]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
nickreply and nickokay method, with option to let reply/okay behave like this by...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 11 Aug 2006 16:23:47 +0000 (16:23 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 11 Aug 2006 16:23:47 +0000 (16:23 +0000)
ChangeLog
lib/rbot/message.rb

index 9efe9b08090353debbabf58aaa58f55b1292e5bd..6f153a4508da60e692cc1ddf281281ae8af6e97d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,10 @@
        * AutoOp plugin: trigger autoop on nick change too.
        * New Auth Framework: allow? method now informs a user when they don't
        have permission to do what they asked for.
+       * New nickreply and nickokay methods: they act like the old reply
+       method, but include the nick of the user the bot is replying to when
+       talking in public. The usual reply method can be configured to act
+       like this as default.
 
 2006-08-10  Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
 
index fff121944b33f055606565e86d97201ec7abcf80..f1293e787a1d1e4878f7945e34a083228fed3e6c 100644 (file)
@@ -4,6 +4,16 @@ module Irc
     :desc => "what non nick-matching prefixes should the bot respond to as if addressed (e.g !, so that '!foo' is treated like 'rbot: foo')"
   )
 
+  BotConfig.register BotConfigBooleanValue.new('core.reply_with_nick',
+    :default => false, :wizard => true,
+    :desc => "if true, the bot will prepend the nick to what he has to say when replying (e.g. 'markey: you can't do that!')"
+  )
+
+  BotConfig.register BotConfigStringValue.new('core.nick_postfix',
+    :default => ':', :wizard => true,
+    :desc => "when replying with nick put this character after the nick of the user the bot is replying to"
+  )
+
   Color = "\003"
   Bold = "\002"
   Underline = "\037"
@@ -204,11 +214,29 @@ module Irc
     # <tt>@bot.say m.replyto, string</tt>
     # So if the message is private, it will reply to the user. If it was
     # in a channel, it will reply in the channel.
-    def reply(string)
+    def plainreply(string)
       @bot.say @replyto, string
       @replied = true
     end
 
+    # Same as reply, but when replying in public it adds the nick of the user
+    # the bot is replying to
+    def nickreply(string)
+      extra = self.public? ? "#{@source}#{@bot.config['core.nick_postfix']} " : ""
+      @bot.say @replyto, extra + string
+      @replied = true
+    end
+
+    # the default reply style is to nickreply unless the reply already contains
+    # the nick or core.reply_with_nick is set to false
+    #
+    def reply(string)
+      if @bot.config['core.reply_with_nick'] and not string =~ /\b#{@source}\b/
+        return nickreply(string)
+      end
+      plainreply(string)
+    end
+
     # convenience method to reply to a message with an action. It's the
     # same as doing:
     # <tt>@bot.action m.replyto, string</tt>
@@ -221,8 +249,25 @@ module Irc
 
     # convenience method to reply "okay" in the current language to the
     # message
+    def plainokay
+      self.plainreply @bot.lang.get("okay")
+    end
+
+    # Like the above, but append the username
+    def nickokay
+      str = @bot.lang.get("okay").dup
+      if self.public?
+        # remove final punctuation
+        str.gsub!(/[!,.]$/,"")
+        str += ", #{@source}"
+      end
+      self.plainreply str
+    end
+
+    # the default okay style is the same as the default reply style
+    #
     def okay
-      @bot.say @replyto, @bot.lang.get("okay")
+      self.reply @bot.lang.get("okay")
     end
 
   end