You'll need something to queue this, so you don't get flooded off. I won't include my queue script, though.
Code:
on 1:JOIN:#:whois $nick
raw 319:*#*:{
  var %chans = $3- , %i = 0
  while (%i < $numtok(%chans,32)) {
    inc %i
    if ($gettok(%chans,%i,32) == #badchan) && $comchan($2,0)) {
      ;cycle through your chans through $comchan, and ban them
    }
  }
}


Acquire. Analyze. Adapt.