From 1a864cb7b90cc237e5af8f7fb8298d2efd46ee37 Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Mon, 21 Dec 2009 10:46:03 +0100 Subject: message: Allow forcefully prepending of the nick when replying --- lib/rbot/message.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/rbot/message.rb') diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb index c13e59c1..ef2e14fe 100644 --- a/lib/rbot/message.rb +++ b/lib/rbot/message.rb @@ -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 -- cgit v1.2.3