Class: Discordrb::Events::ReactionEvent

Inherits:
Event
  • Object
show all
Includes:
Respondable
Defined in:
lib/discordrb/events/reactions.rb

Overview

Generic superclass for events about adding and removing reactions

Direct Known Subclasses

ReactionAddEvent, ReactionRemoveEvent

Instance Attribute Summary collapse

Attributes inherited from Event

#bot

Instance Method Summary collapse

Methods included from Respondable

#<<, #drain, #drain_into, #send_embed, #send_message, #send_temporary_message

Constructor Details

#initialize(data, bot) ⇒ ReactionEvent

Returns a new instance of ReactionEvent.



14
15
16
17
18
19
20
21
# File 'lib/discordrb/events/reactions.rb', line 14

def initialize(data, bot)
  @bot = bot

  @emoji = Discordrb::Emoji.new(data['emoji'], bot, nil)
  @user_id = data['user_id'].to_i
  @message_id = data['message_id'].to_i
  @channel_id = data['channel_id'].to_i
end

Instance Attribute Details

#emojiEmoji (readonly)

Returns the emoji that was reacted with.

Returns:

  • (Emoji)

    the emoji that was reacted with.



12
13
14
# File 'lib/discordrb/events/reactions.rb', line 12

def emoji
  @emoji
end

Instance Method Details

#channelChannel

Returns the channel that was reacted in.

Returns:

  • (Channel)

    the channel that was reacted in.



39
40
41
# File 'lib/discordrb/events/reactions.rb', line 39

def channel
  @channel ||= @bot.channel(@channel_id)
end

#messageMessage

Returns the message that was reacted to.

Returns:

  • (Message)

    the message that was reacted to.



34
35
36
# File 'lib/discordrb/events/reactions.rb', line 34

def message
  @message ||= channel.load_message(@message_id)
end

#serverServer?

Returns the server that was reacted in. If reacted in a PM channel, it will be nil.

Returns:

  • (Server, nil)

    the server that was reacted in. If reacted in a PM channel, it will be nil.



44
45
46
# File 'lib/discordrb/events/reactions.rb', line 44

def server
  @server ||= channel.server
end

#userUser, Member

Returns the user that reacted to this message, or member if a server exists.

Returns:

  • (User, Member)

    the user that reacted to this message, or member if a server exists.



24
25
26
27
28
29
30
31
# File 'lib/discordrb/events/reactions.rb', line 24

def user
  # Cache the user so we don't do requests all the time
  @user ||= if server
              @server.member(@user_id)
            else
              @bot.user(@user_id)
            end
end