Class: Discorb::Command::Command::GroupCommand

Inherits:
Discorb::Command::Command show all
Defined in:
lib/discorb/command.rb

Overview

Represents the command with subcommands.

Direct Known Subclasses

SubcommandGroup

Instance Attribute Summary collapse

Attributes inherited from Discorb::Command::Command

#block, #guild_ids, #id_map, #name, #type, #type_raw

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #hash

Instance Attribute Details

#commands -> Array<Discorb::Command::Command::SlashCommand, Discorb::Command::Command::SubcommandGroup> (readonly)

Returns The subcommands of the command.

Returns:



239
240
241
# File 'lib/discorb/command.rb', line 239

def commands
  @commands
end

#description -> String (readonly)

Returns The description of the command.

Returns:

  • (String)

    The description of the command.



241
242
243
# File 'lib/discorb/command.rb', line 241

def description
  @description
end

Instance Method Details

#group(command_name, description) -> Discorb::Command::Command::SubcommandGroup

Add new subcommand group.

Parameters:

  • command_name (String)

    Group name.

  • description (String)

    Group description.

Returns:

See Also:



309
310
311
312
313
# File 'lib/discorb/command.rb', line 309

def group(command_name, description)
  command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name)
  @commands << command
  command
end

#slash(command_name, description, options = {}, &block) -> Discorb::Command::Command::SlashCommand

Add new subcommand.

Parameters:

  • command_name (String)

    Command name.

  • description (String)

    Command description.

  • options (Hash{String => Hash{:description => String, :optional => Boolean, :type => Object}}) (defaults to: {})

    Command options. The key is the option name, the value is a hash with the following keys:

    | Key | Type | Description | | — | — | — | | :description | String | Description of the option. | | :optional | Boolean | Whether the option is optional or not. | | :type | Object | Type of the option. | | :choice | Hash{String => String, Integer, Float} | Type of the option. |

  • guild_ids (Array<#to_s>)

    Guild IDs to restrict the command to.

  • block (Proc)

    Command block.

Returns:



257
258
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
# File 'lib/discorb/command.rb', line 257

def slash(command_name, description, options = {}, &block)
  command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name)
  options_payload = options.map do |name, value|
    ret = {
      type: case (value[:type].is_a?(Array) ? value[:type].first : value[:type])
      when String, :string
        3
      when Integer
        4
      when TrueClass, FalseClass, :boolean
        5
      when Discorb::User, Discorb::Member, :user, :member
        6
      when Discorb::Channel, :channel
        7
      when Discorb::Role, :role
        8
      when :mentionable
        9
      when Float
        10
      end,
      name: name,
      description: value[:description],
      required: !value[:optional],
    }
    if value[:type].is_a?(Array)
      ret[:choices] = value[:type]
    end

    ret
  end
  {
    name: @name,
    default_permission: true,
    description: @description,
    options: options_payload,
  }
  @commands << command
  command
end

#to_s -> String

Returns the command name.

Returns:

  • (String)

    The command name.



320
321
322
# File 'lib/discorb/command.rb', line 320

def to_s
  @name
end