Class: Lita::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/source.rb

Overview

A wrapper object representing the source of an incoming message (either the user who sent it, the room they sent it from, or both). If a room is set, the message is from a group chat room. If no room is set, the message is assumed to be a private message, though Source objects can be explicitly marked as private messages. Source objects are also used as “target” objects when sending an outgoing message or performing another operation on a user or a room.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user: nil, room: nil, private_message: false) ⇒ Source

Returns a new instance of Source

Parameters:

  • user (Lita::User)

    The user who sent the message or should receive the outgoing message.

  • room (String)

    A string uniquely identifying the room the user sent the message from, or the room where a reply should go. The format of this string will differ depending on the chat service.

  • private_message (Boolean)

    A flag indicating whether or not the message was sent privately.

Raises:

  • (ArgumentError)

30
31
32
33
34
35
36
37
38
# File 'lib/lita/source.rb', line 30

def initialize(user: nil, room: nil, private_message: false)
  @user = user
  @room = room
  @private_message = private_message

  raise ArgumentError, I18n.t("lita.source.user_or_room_required") if user.nil? && room.nil?

  @private_message = true if room.nil?
end

Instance Attribute Details

#private_messageBoolean (readonly) Also known as: private_message?

A flag indicating that a message was sent to the robot privately.

Returns:

  • (Boolean)

    The boolean flag.


12
13
14
# File 'lib/lita/source.rb', line 12

def private_message
  @private_message
end

#roomString (readonly)

The room the message came from or should be sent to.

Returns:

  • (String)

    A string uniquely identifying the room.


17
18
19
# File 'lib/lita/source.rb', line 17

def room
  @room
end

#userLita::User (readonly)

The user who sent the message or should receive the outgoing message.

Returns:


21
22
23
# File 'lib/lita/source.rb', line 21

def user
  @user
end

Instance Method Details

#private_message!void

This method returns an undefined value.

Destructively marks the source as a private message, meaning an incoming message was sent to the robot privately, or an outgoing message should be sent to a user privately.


44
45
46
# File 'lib/lita/source.rb', line 44

def private_message!
  @private_message = true
end