Class: Rubycord::Events::ApplicationCommandEvent

Inherits:
InteractionCreateEvent show all
Defined in:
lib/rubycord/events/interactions.rb

Overview

Event for ApplicationCommand interactions.

Defined Under Namespace

Classes: Resolved

Instance Attribute Summary collapse

Attributes inherited from InteractionCreateEvent

#channel, #channel_id, #interaction, #server, #server_id, #type, #user

Attributes inherited from Event

#bot

Instance Method Summary collapse

Methods inherited from InteractionCreateEvent

#defer, #defer_update, #delete_message, #delete_response, #edit_message, #edit_response, #get_component, #respond, #send_message, #show_modal, #update_message

Constructor Details

#initialize(data, bot) ⇒ ApplicationCommandEvent



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/rubycord/events/interactions.rb', line 154

def initialize(data, bot)
  super

  command_data = data["data"]

  @command_id = command_data["id"]
  @command_name = command_data["name"].to_sym

  @target_id = command_data["target_id"]&.to_i
  @resolved = Resolved.new({}, {}, {}, {}, {}, {})
  process_resolved(command_data["resolved"]) if command_data["resolved"]

  options = command_data["options"] || []

  if options.empty?
    @options = {}
    return
  end

  case options[0]["type"]
  when 2
    options = options[0]
    @subcommand_group = options["name"].to_sym
    @subcommand = options["options"][0]["name"].to_sym
    options = options["options"][0]["options"]
  when 1
    options = options[0]
    @subcommand = options["name"].to_sym
    options = options["options"]
  end

  @options = transform_options_hash(options || {})
end

Instance Attribute Details

#command_idInteger (readonly)



137
138
139
# File 'lib/rubycord/events/interactions.rb', line 137

def command_id
  @command_id
end

#command_nameString (readonly)



134
135
136
# File 'lib/rubycord/events/interactions.rb', line 134

def command_name
  @command_name
end

#optionsHash<Symbol, Object> (readonly)



149
150
151
# File 'lib/rubycord/events/interactions.rb', line 149

def options
  @options
end

#resolvedResolved (readonly)



146
147
148
# File 'lib/rubycord/events/interactions.rb', line 146

def resolved
  @resolved
end

#subcommandString? (readonly)



143
144
145
# File 'lib/rubycord/events/interactions.rb', line 143

def subcommand
  @subcommand
end

#subcommand_groupString? (readonly)



140
141
142
# File 'lib/rubycord/events/interactions.rb', line 140

def subcommand_group
  @subcommand_group
end

#target_idInteger? (readonly)



152
153
154
# File 'lib/rubycord/events/interactions.rb', line 152

def target_id
  @target_id
end

Instance Method Details

#targetMessage, ...



189
190
191
192
193
# File 'lib/rubycord/events/interactions.rb', line 189

def target
  return nil unless @target_id

  @resolved.find { |data| data.key?(@target_id) }[@target_id]
end