From e2dc08da6b19d0e4fdb2f0a71b0c89e6477c5605 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 10 Feb 2009 00:31:57 +0100 Subject: bans: put badwords in message() too Move the whitelist and badwords check in the message() method instead of triggering on listen(). This is more correct and more efficient, and it ensures that the whitelist protects mass-highlighters too. --- data/rbot/plugins/bans.rb | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'data') diff --git a/data/rbot/plugins/bans.rb b/data/rbot/plugins/bans.rb index b77146b8..f80dd70f 100644 --- a/data/rbot/plugins/bans.rb +++ b/data/rbot/plugins/bans.rb @@ -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) -- cgit v1.2.3