package discord import ( "fmt" "time" "github.com/diamondburned/arikawa/v3/utils/json" "github.com/diamondburned/arikawa/v3/utils/json/option" ) // CommandType is the type of the command, which describes the intended // invokation source of the command. type CommandType uint const ( ChatInputCommand CommandType = iota + 1 UserCommand MessageCommand ) // Command is the base "command" model that belongs to an application. This is // what you are creating when you POST a new command. // // https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure type Command struct { // ID is the unique id of the command. ID CommandID `json:"id"` // Type is the intended source of the command. Type CommandType `json:"type,omitempty"` // AppID is the unique id of the parent application. AppID AppID `json:"application_id"` // GuildID is the guild id of the command, if not global. GuildID GuildID `json:"guild_id,omitempty"` // Name is the 1-32 lowercase character name matching ^[\w-]{1,32}$. Name string `json:"name"` NameLocalizations StringLocales `json:"name_localizations,omitempty"` // Description is the 1-100 character description. Description string `json:"description"` DescriptionLocalizations StringLocales `json:"description_localizations,omitempty"` // LocalizedName is only populated when this is received from Discord's API. LocalizedName string `json:"name_localized,omitempty"` // LocalizedDescription is only populated when this is received from // Discord's API. LocalizedDescription string `json:"description_localized,omitempty"` // Options are the parameters for the command. Its types are value types, // which can either be a SubcommandOption or a SubcommandGroupOption. // // Note that required options must be listed before optional options, and // a command, or each individual subcommand, can have a maximum of 25 // options. // // It is only present on ChatInputCommands. Options CommandOptions `json:"options,omitempty"` // DefaultMemberPermissions is set of permissions. DefaultMemberPermissions *Permissions `json:"default_member_permissions,string,omitempty"` // NoDMPermission indicates whether the command is NOT available in DMs with // the app, only for globally-scoped commands. By default, commands are visible. NoDMPermission bool `json:"-"` // NoDefaultPermissions defines whether the command is NOT enabled by // default when the app is added to a guild. NoDefaultPermission bool `json:"-"` // Version is an autoincrementing version identifier updated during // substantial record changes Version Snowflake `json:"version,omitempty"` } // Language is a string type for language codes, such as "en-US" or "fr". Refer // to the constants for valid language codes. // // The list of all valid language codes are at // https://discord.com/developers/docs/reference#locales type Language string // StringLocales is the map mapping a language code to a localized string. type StringLocales map[Language]string const ( Danish Language = "da" German Language = "de" EnglishUK Language = "en-GB" EnglishUS Language = "en-US" Spanish Language = "es-ES" French Language = "fr" Croatian Language = "hr" Italian Language = "it" Lithuanian Language = "lt" Hungarian Language = "hu" Dutch Language = "nl" Norwegian Language = "no" Polish Language = "pl" PortugueseBR Language = "pt-BR" Romanian Language = "ro" Finnish Language = "fi" Swedish Language = "sv-SE" Vietnamese Language = "vi" Turkish Language = "tr" Czech Language = "cs" Greek Language = "el" Bulgarian Language = "bg" Russian Language = "ru" Ukrainian Language = "uk" Hindi Language = "hi" Thai Language = "th" ChineseChina Language = "zh-CN" Japanese Language = "ja" ChineseTaiwan Language = "zh-TW" Korean Language = "ko" ) // CreatedAt returns a time object representing when the command was created. func (c *Command) CreatedAt() time.Time { return c.ID.Time() } func (c *Command) MarshalJSON() ([]byte, error) { type RawCommand Command cmd := struct { *RawCommand DMPermission bool `json:"dm_permission"` DefaultPermission bool `json:"default_permission"` }{RawCommand: (*RawCommand)(c)} // Discord defaults default_permission to true, so we need to invert the // meaning of the field (>NoNo