I had a look to the script... It could be better.
I think I can redo it, just need to be sure:
The users which are in $checkchans must not be in $badchans, and check is performed on join and each 5 minutes.
And you want to exclude ops (and halfops ?) of the check/ban ?