Class: RubyCord::Command

Inherits:
DiscordModel show all
Defined in:
lib/rubycord/command.rb,
lib/rubycord/command/sub_command.rb,
lib/rubycord/command/group_command.rb,
lib/rubycord/command/slash_command.rb

Overview

Represents the slash command.

Direct Known Subclasses

GroupCommand, SlashCommand

Defined Under Namespace

Classes: GroupCommand, SlashCommand, SubCommand

Constant Summary collapse

VALID_LOCALES =

Returns List of valid locales.

Returns:

  • (Array<String>)

    List of valid locales.

%w[
  da
  de
  en-GB
  en-US
  es-ES
  fr
  hr
  it
  lt
  hu
  nl
  no
  pl
  pt-BR
  ro
  fi
  sv-SE
  vi
  tr
  cs
  el
  bg
  ru
  uk
  hi
  th
  zh-CN
  ja
  zh-TW
  ko
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#blockProc (readonly)

Returns The block of the command.

Returns:

  • (Proc)

    The block of the command.



49
50
51
# File 'lib/rubycord/command.rb', line 49

def block
  @block
end

#default_permissionRubyCord::Permission (readonly)

Returns The default permissions for this command.

Returns:



55
56
57
# File 'lib/rubycord/command.rb', line 55

def default_permission
  @default_permission
end

#dm_permissionBoolean (readonly)

Returns Whether the command is enabled in DMs.

Returns:

  • (Boolean)

    Whether the command is enabled in DMs.



57
58
59
# File 'lib/rubycord/command.rb', line 57

def dm_permission
  @dm_permission
end

#guild_idsArray<RubyCord::Snowflake> (readonly)

Returns The guild ids that the command is enabled in.

Returns:



47
48
49
# File 'lib/rubycord/command.rb', line 47

def guild_ids
  @guild_ids
end

#nameHash{String => String} (readonly)

Returns The name of the command.

Returns:

  • (Hash{String => String})

    The name of the command.



45
46
47
# File 'lib/rubycord/command.rb', line 45

def name
  @name
end

#type:chat_input, ... (readonly)

Returns The type of the command.

Returns:

  • (:chat_input, :user, :message)

    The type of the command.



51
52
53
# File 'lib/rubycord/command.rb', line 51

def type
  @type
end

#type_rawInteger (readonly)

Returns The raw type of the command.

Returns:

  • (Integer)

    The raw type of the command.



53
54
55
# File 'lib/rubycord/command.rb', line 53

def type_raw
  @type_raw
end

Class Method Details

.modify_localization_hash(hash) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rubycord/command.rb', line 125

def self.modify_localization_hash(hash)
hash.to_h do |rkey, value|
  key = rkey.to_s.gsub("_", "-")
  if VALID_LOCALES.none? { |valid| valid.downcase == key.downcase } &&
      key != "default"
    raise ArgumentError, "Invalid locale: #{key}"
  end

  [
    (
      if key == "default"
        "default"
      else
        VALID_LOCALES.find { |valid| valid.downcase == key.downcase }
      end
    ),
    value
  ]
end
end