From: Giuseppe Bilotta Date: Fri, 11 Aug 2006 16:23:47 +0000 (+0000) Subject: nickreply and nickokay method, with option to let reply/okay behave like this by... X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=41b34863e2064ff7e04c5886277da21abb52e349;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git nickreply and nickokay method, with option to let reply/okay behave like this by default --- diff --git a/ChangeLog b/ChangeLog index 9efe9b08..6f153a45 100644 --- 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 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 # @bot.say m.replyto, string # 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: # @bot.action m.replyto, string @@ -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