summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-10 00:31:57 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-10 00:31:57 +0100
commite2dc08da6b19d0e4fdb2f0a71b0c89e6477c5605 (patch)
treed82bf44e78ebff759b9c2bbccdd67ee1de5b8a2e /data/rbot/plugins
parentad193513e4c1ca759fe461496eb1032fe34106d8 (diff)
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.
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/bans.rb35
1 files changed, 18 insertions, 17 deletions
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)