class Discorb::Gateway::ReactionEvent

Represents a reaction event.

Attributes

channel[R]

@macro client_cache @return [Discorb::Channel] The channel the message was sent in.

channel_id[R]

@return [Discorb::Snowflake] The ID of the channel the message was sent in.

data[R]

@return [Hash] The raw data of the event.

emoji[R]

@return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.

guild[R]

@macro client_cache @return [Discorb::Guild] The guild the message was sent in.

guild_id[R]

@return [Discorb::Snowflake] The ID of the guild the message was sent in.

member[R]

@macro client_cache @return [Discorb::Member] The member who reacted.

member_id[R]

@return [Discorb::Snowflake] The ID of the user who reacted.

message[R]

@macro client_cache @return [Discorb::Message] The message the reaction was sent in.

message_id[R]

@return [Discorb::Snowflake] The ID of the message.

user[R]

@macro client_cache @return [Discorb::User] The user who reacted.

user_id[R]

@return [Discorb::Snowflake] The ID of the user who reacted.

Public Class Methods

new(client, data) click to toggle source

@!visibility private

# File lib/discorb/gateway.rb, line 58
def initialize(client, data)
  @client = client
  @data = data
  if data.key?(:user_id)
    @user_id = Snowflake.new(data[:user_id])
  else
    @member_data = data[:member]
  end
  @channel_id = Snowflake.new(data[:channel_id])
  @message_id = Snowflake.new(data[:message_id])
  @guild_id = Snowflake.new(data[:guild_id])
  @guild = client.guilds[data[:guild_id]]
  @channel = client.channels[data[:channel_id]] unless @guild.nil?

  @user = client.users[data[:user_id]] if data.key?(:user_id)

  unless @guild.nil?
    @member = if data.key?(:member)
        @guild.members[data[:member][:user][:id]] || Member.new(@client, @guild_id, data[:member][:user], data[:member])
      else
        @guild.members[data[:user_id]]
      end
  end

  @message = client.messages[data[:message_id]]
  @emoji = data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
end

Public Instance Methods

fetch_message(force: false) click to toggle source

Fetch the message. If message is cached, it will be returned. @macro async @macro http

@param [Boolean] force Whether to force fetching the message.

@return [Discorb::Message] The message.

# File lib/discorb/gateway.rb, line 94
def fetch_message(force: false)
  Async do
    next @message if !force && @message

    @message = @channel.fetch_message(@message_id).wait
  end
end