Class: EM::IrcBot::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/em/irc_bot/message.rb

Overview

A message that has come in to the bot from the server.

You will see one of these objects in every one of your #on callbacks -- it is what gets yielded to your callbacks. You should never need to create an instance of this class yourself.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot, source, sender, line) ⇒ Message

:nodoc:



42
43
44
45
46
47
# File 'lib/em/irc_bot/message.rb', line 42

def initialize(bot, source, sender, line)
	@bot    = bot
	@source = source
	@sender = sender
	@line   = line
end

Instance Attribute Details

#botEM::IrcBot (readonly)

The instance of EM::IrcBot from which this message originated. Useful if you want to send a customised message back.

Examples:

Use .bot to send a message

on(/./) do |msg|
  msg.bot.say "master", "I was sent a message: #{msg.line}"
end

Returns:



18
19
20
# File 'lib/em/irc_bot/message.rb', line 18

def bot
  @bot
end

#lineString (readonly)

The text of the message.

Returns:

  • (String)


38
39
40
# File 'lib/em/irc_bot/message.rb', line 38

def line
  @line
end

#senderString (readonly)

The nick which sent the message. For private messages, this will be the same as #source, but for messages in-channel, this will be the nick which sent the message, while #source is the channel.

Returns:

  • (String)


32
33
34
# File 'lib/em/irc_bot/message.rb', line 32

def sender
  @sender
end

#sourceString (readonly)

The nick or channel which originated the message.

Returns:

  • (String)


24
25
26
# File 'lib/em/irc_bot/message.rb', line 24

def source
  @source
end

Instance Method Details

#reply(s) ⇒ Object

Send a line of text back to the source of the message.

This is only a reply to the source; it doesn't modify your message at all to, say, prepend the nick of the sender. That bit's up to you.

Parameters:

  • s (String)

    The message to send.

Returns:

  • void



58
59
60
# File 'lib/em/irc_bot/message.rb', line 58

def reply(s)
	bot.say(source, s)
end