Depends on what you mean by "counter" and "any spell".
If I got you correctly with that "any spell" part, it's actually not that simple. You would have to store every ability in the map in a global array variable (that's the hard part), then you can probably use a dummy caster to cast the spell (to make it look like the hero is casting). You would then use that global array with a random index.
Yeah, that's a pretty clumsy way to do it, but I don't think there's a better one.
What do you mean by "counter"?