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, channel, sender, line) ⇒ Message

:nodoc:



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

def initialize(bot, channel, sender, line)
	@bot     = bot
	@channel = channel
	@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

#channelString (readonly)

The public channel, or nick, which originated the message. This is the place which replies will be sent to by #reply.

Returns:

  • (String)


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

def channel
  @channel
end

#lineString (readonly)

The text of the message.

Returns:

  • (String)


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

def line
  @line
end

#senderString (readonly)

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

Returns:

  • (String)


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

def sender
  @sender
end

Instance Method Details

#private?Boolean

Whether or not this message was sent directly to the bot, or came to us via a channel.

Returns:

  • (Boolean)


69
70
71
# File 'lib/em/irc_bot/message.rb', line 69

def private?
	channel == sender
end

#reply(s) ⇒ Object

Send a line of text back to the channel which originated the message.

This is only a reply to the source channel; 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



60
61
62
# File 'lib/em/irc_bot/message.rb', line 60

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