]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
+ (reply) config option to force reply to query
authorSimon Hafner <hafnersimon@gmail.com>
Wed, 21 Jan 2009 15:49:31 +0000 (16:49 +0100)
committerdmitry kim <jason@nichego.net>
Wed, 21 Jan 2009 23:48:19 +0000 (02:48 +0300)
+ (reply) symbol to bypass the config option
* (plugins) fixed url according to the patch

The symbols are:
:to => :public   force the message to be replied in channel (if any)
:to => :private  force the message to be replied in private
:to => :auto     takes core.private_replies (default)

data/rbot/plugins/markov.rb
data/rbot/plugins/salut.rb
data/rbot/plugins/url.rb
lib/rbot/message.rb

index 3a1fea59d3613057be8f13545531e4358c7a5fc5..64e87556e272df17c45058a74014ae3832939957 100644 (file)
@@ -187,7 +187,7 @@ class MarkovPlugin < Plugin
     # of the line we received
     return if message.index(line) == 0
     @bot.timer.add_once(delay) {
-      m.reply line, :nick => false
+      m.reply line, :nick => false, :to => :public
     }
   end
 
index 131821a7ac90fb9594612a0f7afc7449194c8798..c169d138f6a946bff9b3ddea3cff2e0d7ac6a2ee 100644 (file)
@@ -158,7 +158,7 @@ class SalutPlugin < Plugin
       end
     end
     debug "Replying #{choice}"
-    m.reply choice, :nick => false
+    m.reply choice, :nick => false, :to => :public
   end
 
   def reload
index 826af10defec3c53b241ff972da73c2404326d06..e75224cff278b19261fac556c76fb4a184822030 100644 (file)
@@ -160,7 +160,7 @@ class UrlPlugin < Plugin
 
       if display_info > urls_displayed
         if reply
-          m.reply reply, :overlong => :truncate,
+          m.reply reply, :overlong => :truncate, :to => :public,
             :nick => (m.address? ? :auto : false)
           urls_displayed += 1
         end
index 8b650681b96474b9e875ef8796fd0d291ce0b89f..4da511ed8dc944fdec5a1fdec04840c4cf9b6601 100644 (file)
@@ -22,6 +22,10 @@ module Irc
         :default => ':', :wizard => true,
         :desc => "when replying with nick put this character after the nick of the user the bot is replying to"
       )
+      Config.register BooleanValue.new('core.private_replies',
+        :default => false,
+        :desc => 'Should the bot reply to private instead of the channel?'
+      )
     end
   end
 
@@ -404,16 +408,32 @@ module Irc
     #   state if the nick of the user calling the command should be prepended
     #   :auto uses core.reply_with_nick
     #
+    # :to [:private, :public, :auto]
+    #   where should the bot reply?
+    #   :private always reply to the nick
+    #   :public reply to the channel (if available)
+    #   :auto uses core.private_replies
+
     def reply(string, options={})
-      opts = {:nick => :auto}.merge options
+      opts = {:nick => :auto, :to => :auto}.merge options
+
       if opts[:nick] == :auto
         opts[:nick] = @bot.config['core.reply_with_nick']
       end
-      if (opts[:nick] && self.public? &&
+
+      if !self.public?
+        opts[:to] = :private
+      elsif opts[:to] == :auto
+        opts[:to] = @bot.config['core.private_replies'] ? :private : :public
+      end
+
+      if (opts[:nick] &&
+          opts[:to] != :private &&
           string !~ /(?:^|\W)#{Regexp.escape(@source.to_s)}(?:$|\W)/)
         string = "#{@source}#{@bot.config['core.nick_postfix']} #{string}"
       end
-      @bot.say @replyto, string, options
+      to = (opts[:to] == :private) ? source : @channel
+      @bot.say to, string, options
       @replied = true
     end