Skip to content

Commit

Permalink
feat: add static typing for localization fields
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsagu committed Dec 24, 2023
1 parent 9c5f1a3 commit 79480e0
Showing 1 changed file with 65 additions and 29 deletions.
94 changes: 65 additions & 29 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,76 @@ const (
ATTACHMENT_OPTION_TYPE
)

// https://discord.com/developers/docs/reference#locales
type Language string

const (
DANISH_LANGUAGE Language = "da"
GERMAN_LANGUAGE Language = "de"
ENGLISH_UK_LANGUAGE Language = "en-GB"
ENGLISH_US_LANGUAGE Language = "en-US"
SPANISH_LANGUAGE Language = "es-ES"
FRENCH_LANGUAGE Language = "fr"
CROATIAN_LANGUAGE Language = "hr"
ITALIAN_LANGUAGE Language = "it"
LITHUANIAN_LANGUAGE Language = "lt"
HUNGARIAN_LANGUAGE Language = "hu"
DUTCH_LANGUAGE Language = "nl"
NORWEGIAN_LANGUAGE Language = "no"
POLISH_LANGUAGE Language = "pl"
PORTUGESE_BR_LANGUAGE Language = "pt-BR"
ROMANIAN_LANGUAGE Language = "ro"
FINNISH_LANGUAGE Language = "fi"
SWEDISH_LANGUAGE Language = "sv-SE"
VIETNAMESE_LANGUAGE Language = "vi"
TURKISH_LANGUAGE Language = "tr"
CHECH_LANGUAGE Language = "cs"
GREEK_LANGUAGE Language = "el"
BULGARIAN_LANGUAGE Language = "bg"
RUSSIAN_LANGUAGE Language = "ru"
UKRAINIAN_LANGUAGE Language = "uk"
HINDI_LANGUAGE Language = "hi"
THAI_LANGUAGE Language = "th"
CHINESE_CHINA_LANGUAGE Language = "zh-CN"
JAPANESE_LANGUAGE Language = "ja"
CHINESE_TAIWAN_LANGUAGE Language = "zh-TW"
KOREAN_LANGUAGE Language = "ko"
)

// https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure
type Command struct {
ID Snowflake `json:"-"` // Omit in json parsing for now because it was breaking Client#commandParse.
Type CommandType `json:"type,omitempty"`
ApplicationID Snowflake `json:"application_id"`
GuildID Snowflake `json:"guild_id,omitempty"`
Name string `json:"name"`
NameLocalizations map[string]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
Description string `json:"description"`
DescriptionLocalizations map[string]string `json:"description_localizations,omitempty"`
Options []CommandOption `json:"options,omitempty"`
DefaultMemberPermissions uint64 `json:"default_member_permissions,string,omitempty"` // Set of permissions represented as a bit set. Set it to 0 to make command unavailable for regular members.
AvailableInDM bool `json:"dm_permission,omitempty"` // Whether command should be visible (usable) from private, dm channels. Works only for global commands!
NSFW bool `json:"nsfw,omitempty"` // https://discord.com/developers/docs/interactions/application-commands#agerestricted-commands
Version Snowflake `json:"version,omitempty"` // Autoincrementing version identifier updated during substantial record changes
ID Snowflake `json:"-"` // Omit in json parsing for now because it was breaking Client#commandParse.
Type CommandType `json:"type,omitempty"`
ApplicationID Snowflake `json:"application_id"`
GuildID Snowflake `json:"guild_id,omitempty"`
Name string `json:"name"`
NameLocalizations map[Language]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
Description string `json:"description"`
DescriptionLocalizations map[Language]string `json:"description_localizations,omitempty"`
Options []CommandOption `json:"options,omitempty"`
DefaultMemberPermissions uint64 `json:"default_member_permissions,string,omitempty"` // Set of permissions represented as a bit set. Set it to 0 to make command unavailable for regular members.
AvailableInDM bool `json:"dm_permission,omitempty"` // Whether command should be visible (usable) from private, dm channels. Works only for global commands!
NSFW bool `json:"nsfw,omitempty"` // https://discord.com/developers/docs/interactions/application-commands#agerestricted-commands
Version Snowflake `json:"version,omitempty"` // Autoincrementing version identifier updated during substantial record changes

AutoCompleteHandler func(itx *CommandInteraction) []Choice `json:"-"` // Custom handler for auto complete interactions. It's a Tempest specific field.
SlashCommandHandler func(itx *CommandInteraction) `json:"-"` // Custom handler for slash command interactions. It's a Tempest specific field. Warning! Library will panic if command can be triggered but doesn't have this handler.
AutoCompleteHandler func(itx CommandInteraction) []Choice `json:"-"` // Custom handler for auto complete interactions. It's a Tempest specific field.
SlashCommandHandler func(itx *CommandInteraction) `json:"-"` // Custom handler for slash command interactions. It's a Tempest specific field. It receives pointer to CommandInteraction as it's being used with pre & post client hooks.
}

// https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
type CommandOption struct {
Type OptionType `json:"type"`
Name string `json:"name"`
NameLocalizations map[string]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
Description string `json:"description"`
DescriptionLocalizations map[string]string `json:"description_localizations,omitempty"`
Required bool `json:"required,omitempty"`
MinValue float64 `json:"min_value,omitempty"`
MaxValue float64 `json:"max_value,omitempty"`
MinLength uint `json:"min_length,omitempty"`
MaxLength uint `json:"max_length,omitempty"`
Options []CommandOption `json:"options,omitempty"`
ChannelTypes []ChannelType `json:"channel_types,omitempty"`
Choices []Choice `json:"choices,omitempty"`
AutoComplete bool `json:"autocomplete,omitempty"` // Required to be = true if you want to catch it later in auto complete handler.
Type OptionType `json:"type"`
Name string `json:"name"`
NameLocalizations map[Language]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
Description string `json:"description"`
DescriptionLocalizations map[Language]string `json:"description_localizations,omitempty"`
Required bool `json:"required,omitempty"`
MinValue float64 `json:"min_value,omitempty"`
MaxValue float64 `json:"max_value,omitempty"`
MinLength uint `json:"min_length,omitempty"`
MaxLength uint `json:"max_length,omitempty"`
Options []CommandOption `json:"options,omitempty"`
ChannelTypes []ChannelType `json:"channel_types,omitempty"`
Choices []Choice `json:"choices,omitempty"`
AutoComplete bool `json:"autocomplete,omitempty"` // Required to be = true if you want to catch it later in auto complete handler.
}

0 comments on commit 79480e0

Please sign in to comment.