Class Irc::UserMessage
In: lib/rbot/message.rb
Parent: BasicUserMessage
BasicUserMessage JoinMessage NamesMessage WhoisMessage ModeChangeMessage KickMessage MotdMessage QuitMessage BanlistMessage UserMessage NoSuchTargetMessage TopicMessage NickMessage WelcomeMessage UnknownMessage InviteMessage PartMessage NetmaskList UserList ArrayOf ChannelList Netmask User\n[lib/rbot/botuser.rb\nlib/rbot/irc.rb] Channel Singleton RfcCasemap StrictRfcCasemap AsciiCasemap Casemap PrivMessage NoticeMessage TokyoCabinet::BDB CIBDB Btree CIBtree Socket MessageQueue QueueRing Client DBHash\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] DBTree\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Server NetmaskDb Bot\n[lib/rbot/botuser.rb\nlib/rbot/config.rb\nlib/rbot/ircbot.rb\nlib/rbot/language.rb\nlib/rbot/message.rb\nlib/rbot/messagemapper.rb\nlib/rbot/plugins.rb\nlib/rbot/rbotconfig.rb\nlib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] lib/rbot/ircsocket.rb lib/rbot/rfc2812.rb lib/rbot/registry/tc.rb lib/rbot/irc.rb lib/rbot/maskdb.rb lib/rbot/message.rb lib/rbot/messagemapper.rb lib/rbot/botuser.rb lib/rbot/registry/tc.rb (null) BotConfig PKGConfig ServerOrCasemap Irc dot/m_35_0.png

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)

Methods

act   action?   ctcp_reply   inspect   new   nickokay   nickreply   nickreply!   notify   okay   plainokay   plainreply   private?   public?   reply  

Attributes

action  [R]  for PRIVMSGs, true if the message was a CTCP ACTION (CTCP stuff will be stripped from the message)
channel  [R]  channel the message was in, nil for privately addressed messages
ctcp  [R]  for PRIVMSGs, false unless the message was a CTCP command, in which case it evaluates to the CTCP command itself (TIME, PING, VERSION, etc). The CTCP command parameters are then stored in the message.
params  [R]  for plugin messages, the rest of the message, with the plugin name removed
plugin  [R]  for plugin messages, the name of the plugin invoked by the message
replyto  [R]  convenience member. Who to reply to (i.e. would be sourcenick for a privately addressed message, or target (the channel) for a publicly addressed message

Public Class methods

instantiate a new UserMessage

bot:associated bot class
source:hostmask of the message source
target:nick/channel message is destined for
message:message part

[Source]

     # File lib/rbot/message.rb, line 333
333:     def initialize(bot, server, source, target, message)
334:       super(bot, server, source, target, message)
335:       @target = target
336:       @private = false
337:       @plugin = nil
338:       @ctcp = false
339:       @action = false
340: 
341:       if target == @bot.myself
342:         @private = true
343:         @address = true
344:         @channel = nil
345:         @replyto = source
346:       else
347:         @replyto = @target
348:         @channel = @target
349:       end
350: 
351:       # check for option extra addressing prefixes, e.g "|search foo", or
352:       # "!version" - first match wins
353:       bot.config['core.address_prefix'].each {|mprefix|
354:         if @message.gsub!(/^#{Regexp.escape(mprefix)}\s*/, "")
355:           @address = true
356:           @prefixed = true
357:           break
358:         end
359:       }
360: 
361:       # even if they used above prefixes, we allow for silly people who
362:       # combine all possible types, e.g. "|rbot: hello", or
363:       # "/msg rbot rbot: hello", etc
364:       if @message.gsub!(/^\s*#{Regexp.escape(bot.nick)}\s*([:;,>]|\s)\s*/i, "")
365:         @address = true
366:       end
367: 
368:       if(@message =~ /^\001(\S+)(\s(.+))?\001/)
369:         @ctcp = $1
370:         # FIXME need to support quoting of NULL and CR/LF, see
371:         # http://www.irchelp.org/irchelp/rfc/ctcpspec.html
372:         @message = $3 || String.new
373:         @action = @ctcp == 'ACTION'
374:         debug "Received CTCP command #{@ctcp} with options #{@message} (action? #{@action})"
375:         @logmessage = @message.dup
376:         @plainmessage = BasicUserMessage.strip_formatting(@message)
377:         @message = BasicUserMessage.strip_initial_formatting(@message)
378:       end
379: 
380:       # free splitting for plugins
381:       @params = @message.dup
382:       # Created messges (such as by fake_message) can contain multiple lines
383:       if @params.gsub!(/\A\s*(\S+)[\s$]*/m, "")
384:         @plugin = $1.downcase
385:         @params = nil unless @params.length > 0
386:       end
387:     end

Public Instance methods

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.

[Source]

     # File lib/rbot/message.rb, line 466
466:     def act(string, options={})
467:       @bot.action @replyto, string, options
468:       @replied = true
469:     end

[Source]

     # File lib/rbot/message.rb, line 399
399:     def action?
400:       return @action
401:     end

send a CTCP response, i.e. a private NOTICE to the sender with the same CTCP command and the reply as a parameter

[Source]

     # File lib/rbot/message.rb, line 473
473:     def ctcp_reply(string, options={})
474:       @bot.ctcp_notice @source, @ctcp, string, options
475:     end

[Source]

     # File lib/rbot/message.rb, line 285
285:     def inspect
286:       fields = ' plugin=' << plugin.inspect
287:       fields << ' params=' << params.inspect
288:       fields << ' channel=' << channel.to_s if channel
289:       fields << ' (reply to ' << replyto.to_s << ')'
290:       if self.private?
291:         fields << ' (private)'
292:       else
293:         fields << ' (public)'
294:       end
295:       if self.action?
296:         fields << ' (action)'
297:       elsif ctcp
298:         fields << ' (CTCP ' << ctcp << ')'
299:       end
300:       super(fields)
301:     end

Like the above, but append the username

[Source]

     # File lib/rbot/message.rb, line 484
484:     def nickokay
485:       str = @bot.lang.get("okay").dup
486:       if self.public?
487:         # remove final punctuation
488:         str.gsub!(/[!,.]$/,"")
489:         str += ", #{@source}"
490:       end
491:       self.reply str, :nick => false
492:     end

Same as reply, but when replying in public it adds the nick of the user the bot is replying to

[Source]

     # File lib/rbot/message.rb, line 414
414:     def nickreply(string, options={})
415:       reply string, {:nick => true}.merge(options)
416:     end

Same as nickreply, but always prepend the target‘s nick.

[Source]

     # File lib/rbot/message.rb, line 419
419:     def nickreply!(string, options={})
420:       reply string, {:nick => true, :forcenick => true}.merge(options)
421:     end

send a NOTICE to the message source

[Source]

     # File lib/rbot/message.rb, line 502
502:     def notify(msg,opts={})
503:       @bot.notice(sourcenick, msg, opts)
504:     end

the default okay style is the same as the default reply style

[Source]

     # File lib/rbot/message.rb, line 496
496:     def okay
497:       @bot.config['core.reply_with_nick'] ? nickokay : plainokay
498:     end

convenience method to reply "okay" in the current language to the message

[Source]

     # File lib/rbot/message.rb, line 479
479:     def plainokay
480:       self.reply @bot.lang.get("okay"), :nick => false
481:     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.

[Source]

     # File lib/rbot/message.rb, line 408
408:     def plainreply(string, options={})
409:       reply string, {:nick => false}.merge(options)
410:     end

returns true for private messages, e.g. "/msg bot hello"

[Source]

     # File lib/rbot/message.rb, line 390
390:     def private?
391:       return @private
392:     end

returns true if the message was in a channel

[Source]

     # File lib/rbot/message.rb, line 395
395:     def public?
396:       return !@private
397:     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

[Source]

     # File lib/rbot/message.rb, line 437
437:     def reply(string, options={})
438:       opts = {:nick => :auto, :forcenick => false, :to => :auto}.merge options
439: 
440:       if opts[:nick] == :auto
441:         opts[:nick] = @bot.config['core.reply_with_nick']
442:       end
443: 
444:       if !self.public?
445:         opts[:to] = :private
446:       elsif opts[:to] == :auto
447:         opts[:to] = @bot.config['core.private_replies'] ? :private : :public
448:       end
449: 
450:       if (opts[:nick] &&
451:           opts[:to] != :private &&
452:           (string !~ /(?:^|\W)#{Regexp.escape(@source.to_s)}(?:$|\W)/ ||
453:             opts[:forcenick]))
454:         string = "#{@source}#{@bot.config['core.nick_postfix']} #{string}"
455:       end
456:       to = (opts[:to] == :private) ? source : @channel
457:       @bot.say to, string, options
458:       @replied = true
459:     end

[Validate]