summaryrefslogtreecommitdiff
path: root/lib/rbot/message.rb
diff options
context:
space:
mode:
authorSimon Hafner <hafnersimon@gmail.com>2009-01-21 15:53:01 +0100
committerdmitry kim <jason@nichego.net>2009-01-22 02:10:06 +0300
commit35cc0ef69af6344db8a36c733207241594bbd402 (patch)
tree1dd5d0e4e25d976b66110331031689f5d2caec98 /lib/rbot/message.rb
parent144cbc49e1893162ee415868c22faa1e815f5107 (diff)
+ (reply) add new option to control nick prefixing
Message#reply() now accepts a :reply option :nick => false don't prefix nick :nick => true prefix nick :nick => :auto take core.reply_with_nick (default)
Diffstat (limited to 'lib/rbot/message.rb')
-rw-r--r--lib/rbot/message.rb34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb
index b34105c4..8b650681 100644
--- a/lib/rbot/message.rb
+++ b/lib/rbot/message.rb
@@ -390,26 +390,31 @@ module Irc
# 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 plainreply(string, options={})
- @bot.say @replyto, string, options
- @replied = true
+ reply string, {:nick => false}.merge(options)
end
# Same as reply, but when replying in public it adds the nick of the user
# the bot is replying to
def nickreply(string, options={})
- extra = self.public? ? "#{@source}#{@bot.config['core.nick_postfix']} " : ""
- @bot.say @replyto, extra + string, options
- @replied = true
+ reply string, {:nick => true}.merge(options)
end
- # the default reply style is to nickreply unless the reply already contains
- # the nick or core.reply_with_nick is set to false
+ # 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
#
def reply(string, options={})
- if @bot.config['core.reply_with_nick'] and not string =~ /(?:^|\W)#{Regexp.escape(@source.to_s)}(?:$|\W)/
- return nickreply(string, options)
+ opts = {:nick => :auto}.merge options
+ if opts[:nick] == :auto
+ opts[:nick] = @bot.config['core.reply_with_nick']
+ end
+ if (opts[:nick] && self.public? &&
+ string !~ /(?:^|\W)#{Regexp.escape(@source.to_s)}(?:$|\W)/)
+ string = "#{@source}#{@bot.config['core.nick_postfix']} #{string}"
end
- plainreply(string, options)
+ @bot.say @replyto, string, options
+ @replied = true
end
# convenience method to reply to a message with an action. It's the
@@ -431,7 +436,7 @@ module Irc
# convenience method to reply "okay" in the current language to the
# message
def plainokay
- self.plainreply @bot.lang.get("okay")
+ self.reply @bot.lang.get("okay"), :nick => false
end
# Like the above, but append the username
@@ -442,16 +447,13 @@ module Irc
str.gsub!(/[!,.]$/,"")
str += ", #{@source}"
end
- self.plainreply str
+ self.reply str, :nick => false
end
# the default okay style is the same as the default reply style
#
def okay
- if @bot.config['core.reply_with_nick']
- return nickokay
- end
- plainokay
+ @bot.config['core.reply_with_nick'] ? nickokay : plainokay
end
# send a NOTICE to the message source