]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/bans.rb
bans: put badwords in message() too
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / bans.rb
index b77146b81d5a59d3f45ceba55c1c7c5d85ed0819..f80dd70f9fed91b1219461954d804acecb4b549b 100644 (file)
@@ -142,29 +142,14 @@ class BansPlugin < Plugin
 
   def message(m)
     return unless m.channel
-    mm = m.plainmessage.irc_downcase(m.server.casemap).split(/[\s\.,:]/)
-    nicks_said = (m.channel.users.map { |u| u.downcase} & mm).size
-    return unless nicks_said > 0 # not really needed, but saves some cycles
-    got_nicks = 0
-    masshl_action = nil
-    @registry[:masshl].each { |masshl|
-      next unless masshl.channel == m.channel.downcase or masshl.channel == "all"
-      needed = [masshl.num.to_i, (masshl.perc * m.channel.user_nicks.size / 100).to_i].max
-      next if needed > nicks_said or needed < got_nicks
-      masshl_action = masshl
-      got_nicks = needed
-    }
-    return unless masshl_action
-    do_cmd masshl_action.action.intern, m.sourcenick, m.channel, masshl_action.timer, masshl_action.reason
-  end
 
-  def listen(m)
-    return unless m.respond_to?(:public?) and m.public?
+    # check the whitelist first
     @registry[:whitelist].each { |white|
       next unless ['all', m.target.downcase].include?(white.channel)
       return if m.source.matches?(white.host)
     }
 
+    # check the badwords next
     @registry[:badwords].each { |badword|
       next unless ['all', m.target.downcase].include?(badword.channel)
       next unless badword.regexp.match(m.plainmessage)
@@ -173,6 +158,22 @@ class BansPlugin < Plugin
       do_cmd(badword.action.to_sym, m.source.nick, m.target, badword.timer, badword.reason)
       return
     }
+
+    # and finally, see if the user triggered masshl
+    mm = m.plainmessage.irc_downcase(m.server.casemap).split(/[\s\.,:]/)
+    nicks_said = (m.channel.users.map { |u| u.downcase} & mm).size
+    return unless nicks_said > 0 # not really needed, but saves some cycles
+    got_nicks = 0
+    masshl_action = nil
+    @registry[:masshl].each { |masshl|
+      next unless masshl.channel == m.channel.downcase or masshl.channel == "all"
+      needed = [masshl.num.to_i, (masshl.perc * m.channel.user_nicks.size / 100).to_i].max
+      next if needed > nicks_said or needed < got_nicks
+      masshl_action = masshl
+      got_nicks = needed
+    }
+    return unless masshl_action
+    do_cmd masshl_action.action.intern, m.sourcenick, m.channel, masshl_action.timer, masshl_action.reason
   end
 
   def join(m)