-# BansPlugin v3 for 0.9.11\r
+#-- vim:sw=2:et\r
+#++\r
#\r
-# Managing kick and bans, automatically removing bans after timeouts, quiet bans, and kickban/quietban based on regexp\r
+# :title: Bans Plugin v3 for rbot 0.9.11 and later\r
#\r
-# (c) 2006 Marco Gulino <marco@kmobiletools.org>\r
-# (c) 2007 kamu <mr.kamu@gmail.com>\r
-# (c) 2007 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\r
+# Author:: Marco Gulino <marco@kmobiletools.org>\r
+# Author:: kamu <mr.kamu@gmail.com>\r
+# Author:: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\r
+#\r
+# Copyright:: (C) 2006 Marco Gulino\r
+# Copyright:: (C) 2007 kamu, Giuseppe Bilotta\r
+#\r
+# License:: GPL V2.\r
+#\r
+# Managing kick and bans, automatically removing bans after timeouts, quiet\r
+# bans, and kickban/quietban based on regexp\r
#\r
# v1 -> v2 (kamu's version, never released)\r
# * reworked\r
#\r
# v2 -> v3 (GB)\r
# * remove the 'bans' prefix from most of the commands\r
-# * (un)quiet has been renamed to (un)silence because 'quiet' was used to tell the bot to keep quiet\r
+# * (un)quiet has been renamed to (un)silence because 'quiet' was used to\r
+# tell the bot to keep quiet\r
# * both (un)quiet and (un)silence are accepted as actions\r
# * use the more descriptive 'onjoin' term for autoactions\r
-# * convert v1's (0.9.10) :bans and :bansmasks to BadWordActions and WhitelistEntries\r
+# * convert v1's (0.9.10) :bans and :bansmasks to BadWordActions and\r
+# WhitelistEntries\r
# * enhanced list manipulation facilities\r
# * fixed regexp usage in requirements for plugin map\r
# * add proper auth management\r
-#\r
-# Licensed under GPL V2.\r
-\r
-OnJoinAction = Struct.new("OnJoinAction", :host, :action, :channel, :reason)\r
-BadWordAction = Struct.new("BadWordAction", :regexp, :action, :channel, :timer, :reason)\r
-WhitelistEntry = Struct.new("WhitelistEntry", :host, :channel)\r
\r
+define_structure :OnJoinAction, :host, :action, :channel, :reason\r
+define_structure :BadWordAction, :regexp, :action, :channel, :timer, :reason\r
+define_structure :WhitelistEntry, :host, :channel\r
\r
class BansPlugin < Plugin\r
\r
end\r
\r
def make_badword_rx(txt)\r
- return /\b#{txt}\b/i\r
+ return /\b(?:#{txt})\b/i\r
end\r
\r
def initialize\r
autos = @registry[:onjoin]\r
count = autos.length\r
\r
- idx = params[:idx].to_i\r
+ idx = nil\r
+ idx = params[:idx].to_i if params[:idx]\r
\r
if idx\r
if idx > count\r
end\r
end\r
@registry[:onjoin] = autos\r
- m.okay if count > autos.length\r
+ if count > autos.length\r
+ m.okay\r
+ else\r
+ m.reply "No matching onjoin rule for #{host} found"\r
+ end\r
end\r
\r
def add_badword(m, params=nil)\r
badwords = @registry[:badwords]\r
count = badwords.length\r
\r
- idx = params[:idx].to_i\r
+ idx = nil\r
+ idx = params[:idx].to_i if params[:idx]\r
\r
if idx\r
if idx > count\r
\r
badwords.each { |badword|\r
next unless ['all', badword.channel].include?(channel)\r
+ debug "Removing #{badword.inspect}" if badword == regexp\r
badwords.delete(badword) if badword == regexp\r
}\r
end\r
\r
@registry[:badwords] = badwords\r
- m.okay if count > badwords.length\r
+ if count > badwords.length\r
+ m.okay\r
+ else\r
+ m.reply "No matching badword #{regexp} found"\r
+ end\r
end\r
\r
def add_whitelist(m, params=nil)\r
wl = @registry[:whitelist]\r
count = wl.length\r
\r
- idx = params[:idx].to_i\r
+ idx = nil\r
+ idx = params[:idx].to_i if params[:idx]\r
\r
if idx\r
if idx > count\r
end\r
end\r
@registry[:whitelist] = wl\r
- m.okay if count > whitelist.length\r
+ if count > whitelist.length\r
+ m.okay\r
+ else\r
+ m.reply "No host matching #{host}"\r
+ end\r
end\r
\r
private\r