diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-08-11 16:23:47 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-08-11 16:23:47 +0000 |
commit | 41b34863e2064ff7e04c5886277da21abb52e349 (patch) | |
tree | 53677303959c77cb0824caf29847e2e58e0075c5 /lib/rbot | |
parent | ad4bb5bf4fce69f1848f8b717abbab849fc37805 (diff) |
nickreply and nickokay method, with option to let reply/okay behave like this by default
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/message.rb | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb index fff12194..f1293e78 100644 --- a/lib/rbot/message.rb +++ b/lib/rbot/message.rb @@ -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 |