]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Fix rbot quieting
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 7 Feb 2007 10:35:28 +0000 (10:35 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 7 Feb 2007 10:35:28 +0000 (10:35 +0000)
lib/rbot/core/basics.rb
lib/rbot/ircbot.rb

index 4c18037e15e236217cbb9dedc238c9fadbbcf257..38c96b23f595a0a393807b33b6b26d990a8a7fd0 100644 (file)
@@ -59,18 +59,24 @@ class BasicsModule < CoreBotModule
 \r
   def bot_quiet(m, param)\r
     if param.has_key?(:where)\r
-      @bot.set_quiet param[:where].sub(/^here$/, m.target)\r
+      @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)\r
     else\r
       @bot.set_quiet\r
     end\r
+    # Make sense when the commmand is given in private or in a non-quieted\r
+    # channel\r
+    m.okay\r
   end\r
 \r
   def bot_talk(m, param)\r
     if param.has_key?(:where)\r
-      @bot.reset_quiet param[:where].sub(/^here$/, m.target)\r
+      @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)\r
     else\r
       @bot.reset_quiet\r
     end\r
+    # Make sense when the commmand is given in private or in a non-quieted\r
+    # channel\r
+    m.okay\r
   end\r
 \r
   def bot_help(m, param)\r
@@ -141,18 +147,12 @@ basics.map "restart *msg",
   :defaults => { :msg => nil },\r
   :auth_path => 'quit'\r
 \r
-basics.map "quiet",\r
+basics.map "quiet [in] [:where]",\r
   :action => 'bot_quiet',\r
   :auth_path => 'talk::set'\r
-basics.map "quiet in :chan",\r
-  :action => 'bot_quiet',\r
-  :auth_path => 'talk::set'\r
-basics.map "talk",\r
+basics.map "talk [in] [:where]",\r
   :action => 'bot_talk',\r
   :auth_path => 'talk::set'\r
-basics.map "quiet in :chan",\r
-  :action => 'bot_quiet',\r
-  :auth_path => 'talk::set'\r
 \r
 basics.map "say :where *what",\r
   :action => 'bot_say',\r
index 0fed549320813fe13fc254a18fd6e40b19819c50..a54fd7cdca6373344afc15ab0834ff79454b3fcd 100644 (file)
@@ -441,9 +441,10 @@ class IrcBot
     myself.nick = @config['irc.nick']
 
     # Channels where we are quiet
-    # It's nil when we are not quiet, an empty list when we are quiet
-    # in all channels, a list of channels otherwise
-    @quiet = nil
+    # Array of channels names where the bot should be quiet
+    # '*' means all channels
+    #
+    @quiet = []
 
     @client[:welcome] = proc {|data|
       irclog "joined server #{@client.server} as #{myself}", "server"
@@ -632,24 +633,24 @@ class IrcBot
 
   # checks if we should be quiet on a channel
   def quiet_on?(channel)
-    return false unless @quiet
-    return true if @quiet.empty?
-    return @quiet.include?(channel.to_s)
+    return @quiet.include?('*') || @quiet.include?(channel.downcase)
   end
 
-  def set_quiet(channel=nil)
+  def set_quiet(channel)
     if channel
-      @quiet << channel.to_s unless @quiet.include?(channel.to_s)
+      ch = channel.downcase.dup
+      @quiet << ch unless @quiet.include?(ch)
     else
-      @quiet = []
+      @quiet.clear
+      @quiet << '*'
     end
   end
 
-  def reset_quiet(channel=nil)
+  def reset_quiet(channel)
     if channel
-      @quiet.delete_if { |x| x == channel.to_s }
+      @quiet.delete channel.downcase
     else
-      @quiet = nil
+      @quiet.clear
     end
   end
 
@@ -884,20 +885,19 @@ class IrcBot
 
   # send a notice message to channel/nick +where+
   def notice(where, message, options={})
-    unless quiet_on?(where)
-      sendmsg "NOTICE", where, message, options
-    end
+    return if where.kind_of?(Channel) and quiet_on?(where)
+    sendmsg "NOTICE", where, message, options
   end
 
   # say something (PRIVMSG) to channel/nick +where+
   def say(where, message, options={})
-    unless quiet_on?(where)
-      sendmsg "PRIVMSG", where, message, options
-    end
+    return if where.kind_of?(Channel) and quiet_on?(where)
+    sendmsg "PRIVMSG", where, message, options
   end
 
   # perform a CTCP action with message +message+ to channel/nick +where+
   def action(where, message, options={})
+    return if where.kind_of?(Channel) and quiet_on?(where)
     mchan = options.fetch(:queue_channel, nil)
     mring = options.fetch(:queue_ring, nil)
     if mchan