X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fmessage.rb;h=35100802b8d640db409b90d876fc54a2ed147900;hb=fdf1bc954352f19818f5f9f1c86643a2f8ef40c6;hp=41658c6b29c8a1a83edac35146c40374504c1fe8;hpb=a38462074a633a315cbf0ebc169ed1a9a9f86854;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb index 41658c6b..35100802 100644 --- a/lib/rbot/message.rb +++ b/lib/rbot/message.rb @@ -4,20 +4,27 @@ # :title: IRC message datastructures module Irc - BotConfig.register BotConfigArrayValue.new('core.address_prefix', - :default => [], :wizard => true, - :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" - ) + class Bot + module Config + Config.register ArrayValue.new('core.address_prefix', + :default => [], :wizard => true, + :desc => "what non nick-matching prefixes should the bot respond to as if addressed (e.g !, so that '!foo' is treated like 'rbot: foo')" + ) + + Config.register BooleanValue.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!')" + ) + + Config.register StringValue.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" + ) + end + end + # Define standard IRC attriubtes (not so standard actually, # but the closest thing we have ...) @@ -115,6 +122,9 @@ module Irc # contents of the message attr_accessor :message + # contents of the message (for logging purposes) + attr_accessor :logmessage + # has the message been replied to/handled by a plugin? attr_accessor :replied @@ -145,6 +155,7 @@ module Irc warning "Message does not have identification" end end + @logmessage = @message.dup if target && target == @bot.myself @address = true @@ -164,6 +175,13 @@ module Irc "#{@source.user}@#{@source.host}" rescue @source.to_s end + # Access the botuser corresponding to the source, if any + # + def botuser + source.botuser rescue @bot.auth.everyone + end + + # Was the message from an identified user? def identified? return @identified @@ -269,6 +287,7 @@ module Irc @message = $3 || String.new @action = @ctcp == 'ACTION' debug "Received CTCP command #{@ctcp} with options #{@message} (action? #{@action})" + @logmessage = @message.dup end # free splitting for plugins @@ -315,7 +334,7 @@ module Irc # the nick or core.reply_with_nick is set to false # def reply(string, options={}) - if @bot.config['core.reply_with_nick'] and not string =~ /\b#{@source}\b/ + if @bot.config['core.reply_with_nick'] and not string =~ /\b#{Regexp.escape(@source.to_s)}\b/ return nickreply(string, options) end plainreply(string, options) @@ -363,6 +382,12 @@ module Irc plainokay end + # send a NOTICE to the message source + # + def notify(msg,opts={}) + @bot.notice(sourcenick, msg, opts) + end + end # class to manage IRC PRIVMSGs