Class: Discorb::CommandInteraction::SlashCommand

Inherits:
Discorb::CommandInteraction show all
Defined in:
lib/discorb/interaction.rb

Overview

Represents a slash command interaction.

Instance Attribute Summary

Attributes inherited from Interaction

#application_id, #id, #member, #token, #type, #user, #version

Instance Method Summary collapse

Methods included from Interaction::SourceResponse

#defer_source, #post

Methods inherited from Interaction

#channel, #guild, #inspect, #target

Methods inherited from DiscordModel

#==, #eql?, #hash

Instance Method Details

#_set_data(data) -> Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/discorb/interaction.rb', line 259

def _set_data(data)
  super
  Sync do
    name = data[:name]
    options = nil
    if (option = data[:options]&.first)
      case option[:type]
      when 1
        name += " #{option[:name]}"
        options = option[:options]
      when 2
        name += " #{option[:name]}"
        if (option_sub = option[:options]&.first)
          if option_sub[:type] == 1
            name += " #{option_sub[:name]}"
            options = option_sub[:options]
          else
            options = option[:options]
          end
        end
      else
        options = data[:options]
      end
    end
    options ||= []
    options.map! do |option|
      case option[:type]
      when 3, 4, 5, 10
        option[:value]
      when 6
        guild.members[option[:value]] || guild.fetch_member(option[:value]).wait
      when 7
        guild.channels[option[:value]] || guild.fetch_channels.wait.find { |channel| channel.id == option[:value] }
      when 8
        guild.roles[option[:value]] || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
      when 9
        guild.members[option[:value]] || guild.roles[option[:value]] || guild.fetch_member(option[:value]).wait || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
      end
    end

    unless (command = @client.commands.find { |c| c.to_s == name })
      @client.log.warn "Unknown command name #{name}, ignoreing"
      next
    end

    command.block.call(self, *options)
  end
end