class Discorb::Interaction

Represents a user interaction with the bot.

Attributes

event_name[R]

@!visibility private

interaction_name[R]

@!visibility private

interaction_type[R]

@!visibility private

application_id[R]

@return [Discorb::Snowflake] The ID of the application that created the interaction.

id[R]

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

member[R]

@return [Discorb::Member] The member that created the interaction.

token[R]

@return [String] The token for the interaction.

type[R]

@return [Symbol] The type of interaction.

user[R]

@return [Discorb::User] The user that created the interaction.

version[R]

@return [Integer] The type of interaction. @note This is always `1` for now.

Public Class Methods

descendants() click to toggle source

@!visibility private

# File lib/discorb/interaction.rb, line 90
def descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end
make_interaction(client, data) click to toggle source

@!visibility private

# File lib/discorb/interaction.rb, line 77
def make_interaction(client, data)
  interaction = nil
  descendants.each do |klass|
    interaction = klass.make_interaction(client, data) if !klass.interaction_type.nil? && klass.interaction_type == data[:type]
  end
  if interaction.nil?
    client.log.warn("Unknown interaction type #{data[:type]}, initialized Interaction")
    interaction = Interaction.new(client, data)
  end
  interaction
end
new(client, data) click to toggle source

@!visibility private

# File lib/discorb/interaction.rb, line 37
def initialize(client, data)
  @client = client
  @id = Snowflake.new(data[:id])
  @application_id = Snowflake.new(data[:application_id])
  @type = self.class.interaction_name
  @type_id = self.class.interaction_type
  @guild_id = data[:guild_id] && Snowflake.new(data[:guild_id])
  @channel_id = data[:channel_id] && Snowflake.new(data[:channel_id])
  @member = guild.members[data[:member][:id]] || Member.new(@client, @guild_id, data[:member][:user], data[:member]) if data[:member]
  @user = @client.users[data[:user][:id]] || User.new(@client, data[:user]) if data[:user]
  @token = data[:token]
  @version = data[:version]
  @defered = false
  @responded = false
  _set_data(data[:data])
end

Public Instance Methods

channel() click to toggle source
# File lib/discorb/interaction.rb, line 58
def channel
  @client.channels[@channel_id]
end
fired_by()
Alias for: target
guild() click to toggle source
# File lib/discorb/interaction.rb, line 54
def guild
  @client.guilds[@guild_id]
end
inspect() click to toggle source
# File lib/discorb/interaction.rb, line 68
def inspect
  "#<#{self.class} id=#{@id}>"
end
target() click to toggle source
# File lib/discorb/interaction.rb, line 62
def target
  @member || @user
end
Also aliased as: fired_by

Private Instance Methods

_set_data(*) click to toggle source
# File lib/discorb/interaction.rb, line 239
def _set_data(*)
  nil
end