]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/bans.rb
UNO plugin: add top and topwin commands to help
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / bans.rb
index 4e35d99638171cfa6310c07ed32a5c669a0add96..52993106f6fb98d8d534a3b3ec6455b43868453e 100644 (file)
@@ -145,8 +145,8 @@ class BansPlugin < Plugin
       next unless ['all', m.target.downcase].include?(badword.channel)
       next unless badword.regexp.match(m.plainmessage)
 
-      do_cmd(badword.action.to_sym, m.source.nick, m.target, badword.timer, badword.reason)
       m.reply "bad word detected! #{badword.action} for #{badword.timer} because: #{badword.reason}"
+      do_cmd(badword.action.to_sym, m.source.nick, m.target, badword.timer, badword.reason)
       return
     }
   end
@@ -298,8 +298,8 @@ 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
+        debug "Removing #{badword.inspect}" if badword.regexp == regexp
+        badwords.delete(badword) if badword.regexp == regexp
       }
     end
 
@@ -401,15 +401,13 @@ class BansPlugin < Plugin
 
     case action
     when :ban
-      set_mode(channel, "+b", nick)
-      @bot.timer.add_once(timer) { set_mode(channel, "-b", nick) } if timer > 0
+      set_temporary_mode(channel, 'b', nick, timer)
     when :unban
       set_mode(channel, "-b", nick)
     when :kick
       do_kick(channel, nick, reason)
     when :kickban
-      set_mode(channel, "+b", nick)
-      @bot.timer.add_once(timer) { set_mode(channel, "-b", nick) } if timer > 0
+      set_temporary_mode(channel, 'b', nick, timer)
       do_kick(channel, nick, reason)
     when :silence, :quiet
       set_mode(channel, "+q", nick)
@@ -424,6 +422,13 @@ class BansPlugin < Plugin
     @bot.mode(channel, mode, host)
   end
 
+  def set_temporary_mode(channel, mode, nick, timer)
+    host = channel.has_user?(nick) ? "*!*@" + channel.users[nick].host : nick
+    @bot.mode(channel, "+#{mode}", host)
+    return if timer == 0
+    @bot.timer.add_once(timer) { @bot.mode(channel, "-#{mode}", host) }
+  end
+
   def do_kick(channel, nick, reason="")
     @bot.kick(channel, nick, reason)
   end