Code:
on *:text:*:?:{
  var %t = $strip($1-),%w = $0
  while ( %w != 0 ) {
    if ( $hfind(spam,$gettok(%t,%w,32)) ) {
      close -cm $nick
      break
    }
    dec %w
  }
}


That presumes the spam words are stored as items, not as data.