]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
message: Allow forcefully prepending of the nick when replying
authorAlex Legler <a3li@gentoo.org>
Mon, 21 Dec 2009 09:46:03 +0000 (10:46 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 21 Dec 2009 10:05:30 +0000 (11:05 +0100)
lib/rbot/message.rb

index c13e59c1673eafdd8f68394968e449d4947bf057..ef2e14fe486a70898cbc72b865016326a77e06d8 100644 (file)
@@ -403,19 +403,27 @@ module Irc
       reply string, {:nick => true}.merge(options)
     end
 
+    # Same as nickreply, but always prepend the target's nick.
+    def nickreply!(string, options={})
+      reply string, {:nick => true, :forcenick => true}.merge(options)
+    end
+
     # The general way to reply to a command. The following options are available:
     # :nick [false, true, :auto]
     #   state if the nick of the user calling the command should be prepended
     #   :auto uses core.reply_with_nick
     #
+    # :forcenick [false, true]
+    #   if :nick is true, always prepend the target's nick, even if the nick
+    #   already appears in the reply. Defaults to false.
+    #
     # :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, :to => :auto}.merge options
+      opts = {:nick => :auto, :forcenick => false, :to => :auto}.merge options
 
       if opts[:nick] == :auto
         opts[:nick] = @bot.config['core.reply_with_nick']
@@ -429,7 +437,8 @@ module Irc
 
       if (opts[:nick] &&
           opts[:to] != :private &&
-          string !~ /(?:^|\W)#{Regexp.escape(@source.to_s)}(?:$|\W)/)
+          (string !~ /(?:^|\W)#{Regexp.escape(@source.to_s)}(?:$|\W)/ ||
+            opts[:forcenick]))
         string = "#{@source}#{@bot.config['core.nick_postfix']} #{string}"
       end
       to = (opts[:to] == :private) ? source : @channel