]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
quiet exception list
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 5 Sep 2008 18:07:38 +0000 (20:07 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 5 Sep 2008 18:07:38 +0000 (20:07 +0200)
Keep a track of exceptions to a global 'quiet' command so that user can
use !quiet and !talk in here to make the bot only talk in one channel
without quiet-ing it by hand in each one of the other channels.

lib/rbot/ircbot.rb

index 55b10d415a96b3c8d9d67783db0b54be831239e4..2830a5ac7b2f78ac96aeac588f72418f9ac470fd 100644 (file)
@@ -591,6 +591,8 @@ class Bot
     # '*' means all channels
     #
     @quiet = Set.new
+    # but we always speak here
+    @not_quiet = Set.new
 
     # the nick we want, if it's different from the irc.nick config value
     # (e.g. as set by a !nick command)
@@ -784,24 +786,30 @@ class Bot
 
   # checks if we should be quiet on a channel
   def quiet_on?(channel)
-    return @quiet.include?('*') || @quiet.include?(channel.downcase)
+    ch = channel.downcase
+    return (@quiet.include?('*') && !@not_quiet.include?(ch)) || @quiet.include?(ch)
   end
 
   def set_quiet(channel = nil)
     if channel
       ch = channel.downcase.dup
+      @not_quiet.delete(ch)
       @quiet << ch
     else
       @quiet.clear
+      @not_quiet.clear
       @quiet << '*'
     end
   end
 
   def reset_quiet(channel = nil)
     if channel
-      @quiet.delete channel.downcase
+      ch = channel.downcase.dup
+      @quiet.delete(ch)
+      @not_quiet << ch
     else
       @quiet.clear
+      @not_quiet.clear
     end
   end