Module: Discorb::ApplicationCommand

Defined in:
lib/discorb/app_command/common.rb,
lib/discorb/app_command/command.rb,
lib/discorb/app_command/handler.rb

Overview

Handles application commands.

Defined Under Namespace

Modules: Handler Classes: Command

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

Class Method Summary collapse

Class Method Details

.modify_localization_hash(hash) -> Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/discorb/app_command/common.rb', line 44

def 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