class Lita::Source

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.

Attributes

private_message[R]

A flag indicating that a message was sent to the robot privately. @return [Boolean] The boolean flag.

private_message?[R]

A flag indicating that a message was sent to the robot privately. @return [Boolean] The boolean flag.

room[R]

The room the message came from or should be sent to, as a string. @return [String, NilClass] A string uniquely identifying the room.

room_object[R]

The room the message came from or should be sent to, as a {Lita::Room} object. @return [Lita::Room, NilClass] The room. @since 4.4.0

user[R]

The user who sent the message or should receive the outgoing message. @return [Lita::User, NilClass] The user.

Public Class Methods

new(user: nil, room: nil, private_message: false) click to toggle source

@param user [Lita::User] The user who sent the message or should receive

the outgoing message.

@param room [Lita::Room, String] A string or {Lita::Room} uniquely identifying the room

the user sent the message from, or the room where a reply should go. The format of this
string (or the ID of the {Lita::Room} object) will differ depending on the chat service.

@param private_message [Boolean] A flag indicating whether or not the

message was sent privately.
# File lib/lita/source.rb, line 35
def initialize(user: nil, room: nil, private_message: false)
  @user = user

  case room
  when String
    @room = room
    @room_object = Room.new(room)
  when Room
    @room = room.id
    @room_object = room
  end

  @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

Public Instance Methods

private_message!() click to toggle source

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. @return [void]

# File lib/lita/source.rb, line 58
def private_message!
  @private_message = true
end