X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fbans.rb;h=17281d4cc0b83162924303ee61c3a9c516ee36d6;hb=edd1cf77be07ae507014574141e920ad23eb164d;hp=8a8f3389f84d18f77da73e18e5f19d119189b5db;hpb=bb135f4425abb5dc53b52a355b8994c0e8646d59;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/bans.rb b/data/rbot/plugins/bans.rb index 8a8f3389..17281d4c 100644 --- a/data/rbot/plugins/bans.rb +++ b/data/rbot/plugins/bans.rb @@ -1,10 +1,19 @@ -# BansPlugin v3 for 0.9.11 +#-- vim:sw=2:et +#++ # -# Managing kick and bans, automatically removing bans after timeouts, quiet bans, and kickban/quietban based on regexp +# :title: Bans Plugin v3 for rbot 0.9.11 and later # -# (c) 2006 Marco Gulino -# (c) 2007 kamu -# (c) 2007 Giuseppe Bilotta +# Author:: Marco Gulino +# Author:: kamu +# Author:: Giuseppe Bilotta +# +# Copyright:: (C) 2006 Marco Gulino +# Copyright:: (C) 2007 kamu, Giuseppe Bilotta +# +# License:: GPL V2. +# +# Managing kick and bans, automatically removing bans after timeouts, quiet +# bans, and kickban/quietban based on regexp # # v1 -> v2 (kamu's version, never released) # * reworked @@ -13,15 +22,15 @@ # # v2 -> v3 (GB) # * remove the 'bans' prefix from most of the commands -# * (un)quiet has been renamed to (un)silence because 'quiet' was used to tell the bot to keep quiet +# * (un)quiet has been renamed to (un)silence because 'quiet' was used to +# tell the bot to keep quiet # * both (un)quiet and (un)silence are accepted as actions # * use the more descriptive 'onjoin' term for autoactions -# * convert v1's (0.9.10) :bans and :bansmasks to BadWordActions and WhitelistEntries +# * convert v1's (0.9.10) :bans and :bansmasks to BadWordActions and +# WhitelistEntries # * enhanced list manipulation facilities # * fixed regexp usage in requirements for plugin map # * add proper auth management -# -# Licensed under GPL V2. OnJoinAction = Struct.new("OnJoinAction", :host, :action, :channel, :reason) BadWordAction = Struct.new("BadWordAction", :regexp, :action, :channel, :timer, :reason) @@ -41,7 +50,7 @@ class BansPlugin < Plugin end def make_badword_rx(txt) - return /\b#{txt}\b/i + return /\b(?:#{txt})\b/i end def initialize @@ -63,7 +72,7 @@ class BansPlugin < Plugin next end bans.delete(ar) - chan = ar[1] + chan = ar[1].downcase regexp = make_badword_rx(ar[2]) badwords << BadWordAction.new(regexp, action, chan, "0s", "") } @@ -219,7 +228,8 @@ class BansPlugin < Plugin autos = @registry[:onjoin] count = autos.length - idx = params[:idx].to_i + idx = nil + idx = params[:idx].to_i if params[:idx] if idx if idx > count @@ -242,11 +252,15 @@ class BansPlugin < Plugin end end @registry[:onjoin] = autos - m.okay if count > autos.length + if count > autos.length + m.okay + else + m.reply "No matching onjoin rule for #{host} found" + end end def add_badword(m, params=nil) - regexp, channel = make_badword_rx(params[:regexp]), params[:channel].dup + regexp, channel = make_badword_rx(params[:regexp]), params[:channel].downcase.dup action, timer, reason = params[:action], params[:timer].dup, params[:reason].to_s badwords = @registry[:badwords] @@ -268,7 +282,8 @@ class BansPlugin < Plugin badwords = @registry[:badwords] count = badwords.length - idx = params[:idx].to_i + idx = nil + idx = params[:idx].to_i if params[:idx] if idx if idx > count @@ -284,12 +299,17 @@ class BansPlugin < Plugin badwords.each { |badword| next unless ['all', badword.channel].include?(channel) + debug "Removing #{badword.inspect}" if badword == regexp badwords.delete(badword) if badword == regexp } end @registry[:badwords] = badwords - m.okay if count > badwords.length + if count > badwords.length + m.okay + else + m.reply "No matching badword #{regexp} found" + end end def add_whitelist(m, params=nil) @@ -319,7 +339,8 @@ class BansPlugin < Plugin wl = @registry[:whitelist] count = wl.length - idx = params[:idx].to_i + idx = nil + idx = params[:idx].to_i if params[:idx] if idx if idx > count @@ -342,7 +363,11 @@ class BansPlugin < Plugin end end @registry[:whitelist] = wl - m.okay if count > whitelist.length + if count > whitelist.length + m.okay + else + m.reply "No host matching #{host}" + end end private