class for handling IRC user messages. Includes some utilities for handling the message, for example in plugins. The message member will have any bot addressing "^bot: " removed (address? will return true in this case)
for PRIVMSGs, true if the message was a CTCP ACTION (CTCP stuff will be stripped from the message)
instantiate a new UserMessage
bot |
associated bot class |
source |
hostmask of the message source |
target |
nick/channel message is destined for |
message |
message part |
# File lib/rbot/message.rb, line 333 def initialize(bot, server, source, target, message) super(bot, server, source, target, message) @target = target @private = false @plugin = nil @ctcp = false @action = false if target == @bot.myself @private = true @address = true @channel = nil @replyto = source else @replyto = @target @channel = @target end # check for option extra addressing prefixes, e.g "|search foo", or # "!version" - first match wins bot.config['core.address_prefix'].each {|mprefix| if @message.gsub!(/^#{Regexp.escape(mprefix)}\s*/, "") @address = true @prefixed = true break end } # even if they used above prefixes, we allow for silly people who # combine all possible types, e.g. "|rbot: hello", or # "/msg rbot rbot: hello", etc if @message.gsub!(/^\s*#{Regexp.escape(bot.nick)}\s*([:;,>]|\s)\s*/, "") @address = true end if(@message =~ /^\0001(\S+)(\s(.+))?\0001/) @ctcp = $1 # FIXME need to support quoting of NULL and CR/LF, see # http://www.irchelp.org/irchelp/rfc/ctcpspec.html @message = $3 || String.new @action = @ctcp == 'ACTION' debug "Received CTCP command #{@ctcp} with options #{@message} (action? #{@action})" @logmessage = @message.dup @plainmessage = BasicUserMessage.strip_formatting(@message) @message = BasicUserMessage.strip_initial_formatting(@message) end # free splitting for plugins @params = @message.dup # Created messges (such as by fake_message) can contain multiple lines if @params.gsub!(/\A\s*(\S+)[\s$]*/, "") @plugin = $1.downcase @params = nil unless @params.length > 0 end end
convenience method to reply to a message with an action. It's the same as doing: @bot.action 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.
# File lib/rbot/message.rb, line 466 def act(string, options={}) @bot.action @replyto, string, options @replied = true end
# File lib/rbot/message.rb, line 399 def action? return @action end
send a CTCP response, i.e. a private NOTICE to the sender with the same CTCP command and the reply as a parameter
# File lib/rbot/message.rb, line 473 def ctcp_reply(string, options={}) @bot.ctcp_notice @source, @ctcp, string, options end
# File lib/rbot/message.rb, line 285 def inspect fields = ' plugin=' << plugin.inspect fields << ' params=' << params.inspect fields << ' channel=' << channel.to_s if channel fields << ' (reply to ' << replyto.to_s << ')' if self.private? fields << ' (private)' else fields << ' (public)' end if self.action? fields << ' (action)' elsif ctcp fields << ' (CTCP ' << ctcp << ')' end super(fields) end
Like the above, but append the username
# File lib/rbot/message.rb, line 484 def nickokay str = @bot.lang.get("okay").dup if self.public? # remove final punctuation str.gsub!(/[!,.]$/,"") str += ", #{@source}" end self.reply str, :nick => false end
Same as reply, but when replying in public it adds the nick of the user the bot is replying to
# File lib/rbot/message.rb, line 414 def nickreply(string, options={}) reply string, {:nick => true}.merge(options) end
Same as nickreply, but always prepend the target's nick.
# File lib/rbot/message.rb, line 419 def nickreply!(string, options={}) reply string, {:nick => true, :forcenick => true}.merge(options) end
send a NOTICE to the message source
# File lib/rbot/message.rb, line 502 def notify(msg,opts={}) @bot.notice(sourcenick, msg, opts) end
the default okay style is the same as the default reply style
# File lib/rbot/message.rb, line 496 def okay @bot.config['core.reply_with_nick'] ? nickokay : plainokay end
convenience method to reply "okay" in the current language to the message
# File lib/rbot/message.rb, line 479 def plainokay self.reply @bot.lang.get("okay"), :nick => false end
convenience method to reply to a message, useful in plugins. It's the same as doing: @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.
# File lib/rbot/message.rb, line 408 def plainreply(string, options={}) reply string, {:nick => false}.merge(options) end
Generated with the Darkfish Rdoc Generator 2.