diff --git a/_examples/test/commands.go b/_examples/test/commands.go index ae5d0c6b..1beaaa0d 100644 --- a/_examples/test/commands.go +++ b/_examples/test/commands.go @@ -7,6 +7,11 @@ import ( ) var commands = []discord.ApplicationCommandCreate{ + discord.SlashCommandCreate{ + Name: "locale", + Description: "return the guild & your locale", + DefaultPermission: true, + }, discord.SlashCommandCreate{ Name: "eval", Description: "runs some go code", diff --git a/_examples/test/examplebot.go b/_examples/test/examplebot.go index 38553297..8279f055 100644 --- a/_examples/test/examplebot.go +++ b/_examples/test/examplebot.go @@ -23,7 +23,7 @@ const ( var ( token = os.Getenv("disgo_token") - guildID = discord.Snowflake(os.Getenv("disgo_guild_id")) + guildID = discord.Snowflake(os.Getenv("disgo_test_guild_id")) adminRoleID = discord.Snowflake(os.Getenv("disgo_admin_role_id")) testRoleID = discord.Snowflake(os.Getenv("disgo_test_role_id")) diff --git a/_examples/test/listeners.go b/_examples/test/listeners.go index a8b3ec4d..1c90a8e1 100644 --- a/_examples/test/listeners.go +++ b/_examples/test/listeners.go @@ -61,6 +61,15 @@ func componentListener(event *events.ComponentInteractionEvent) { func applicationCommandListener(event *events.ApplicationCommandInteractionEvent) { data := event.SlashCommandInteractionData() switch data.CommandName { + case "locale": + err := event.Create(discord.NewMessageCreateBuilder(). + SetContentf("Guild Locale: %s\nLocale: %s", event.GuildLocale, event.Locale). + Build(), + ) + if err != nil { + event.Bot().Logger.Error("error on sending response: ", err) + } + case "eval": go func() { code := *data.Options.String("code") diff --git a/core/entity_builder.go b/core/entity_builder.go index 279985f1..087844c1 100644 --- a/core/entity_builder.go +++ b/core/entity_builder.go @@ -83,6 +83,8 @@ func (b *entityBuilderImpl) baseInteraction(baseInteraction discord.BaseInteract Version: baseInteraction.Version, GuildID: baseInteraction.GuildID, ChannelID: baseInteraction.ChannelID, + Locale: baseInteraction.Locale, + GuildLocale: baseInteraction.GuildLocale, Member: member, User: user, ResponseChannel: c, diff --git a/core/interaction.go b/core/interaction.go index 8fa3903b..819a4c78 100644 --- a/core/interaction.go +++ b/core/interaction.go @@ -21,6 +21,8 @@ type BaseInteraction struct { Version int GuildID *discord.Snowflake ChannelID discord.Snowflake + Locale discord.Locale + GuildLocale *discord.Locale Member *Member User *User ResponseChannel chan<- discord.InteractionResponse diff --git a/discord/interaction.go b/discord/interaction.go index 27a5c165..255fb9d5 100644 --- a/discord/interaction.go +++ b/discord/interaction.go @@ -30,6 +30,8 @@ type BaseInteraction struct { Version int `json:"version"` GuildID *Snowflake `json:"guild_id,omitempty"` ChannelID Snowflake `json:"channel_id"` + Locale Locale `json:"locale"` + GuildLocale *Locale `json:"guild_locale,omitempty"` Member *Member `json:"member,omitempty"` User *User `json:"user,omitempty"` } diff --git a/discord/locale.go b/discord/locale.go new file mode 100644 index 00000000..1bfac365 --- /dev/null +++ b/discord/locale.go @@ -0,0 +1,82 @@ +package discord + +type Locale string + +func (l Locale) String() string { + if name, ok := Locales[l]; ok { + return name + } + return Unknown.String() +} + +func (l Locale) Code() string { + return string(l) +} + +const ( + EnglishUS Locale = "en-US" + EnglishGB Locale = "en-GB" + Bulgarian Locale = "bg" + ChineseCN Locale = "zh-CN" + ChineseTW Locale = "zh-TW" + Croatian Locale = "hr" + Czech Locale = "cs" + Danish Locale = "da" + Dutch Locale = "nl" + Finnish Locale = "fi" + French Locale = "fr" + German Locale = "de" + Greek Locale = "el" + Hindi Locale = "hi" + Hungarian Locale = "hu" + Italian Locale = "it" + Japanese Locale = "ja" + Korean Locale = "ko" + Lithuanian Locale = "lt" + Norwegian Locale = "no" + Polish Locale = "pl" + PortugueseBR Locale = "pt-BR" + Romanian Locale = "ro" + Russian Locale = "ru" + SpanishES Locale = "es-ES" + Swedish Locale = "sv-SE" + Thai Locale = "th" + Turkish Locale = "tr" + Ukrainian Locale = "uk" + Vietnamese Locale = "vi" + Unknown Locale = "" +) + +var Locales = map[Locale]string{ + EnglishUS: "English (United States)", + EnglishGB: "English (Great Britain)", + Bulgarian: "Bulgarian", + ChineseCN: "Chinese (China)", + ChineseTW: "Chinese (Taiwan)", + Croatian: "Croatian", + Czech: "Czech", + Danish: "Danish", + Dutch: "Dutch", + Finnish: "Finnish", + French: "French", + German: "German", + Greek: "Greek", + Hindi: "Hindi", + Hungarian: "Hungarian", + Italian: "Italian", + Japanese: "Japanese", + Korean: "Korean", + Lithuanian: "Lithuanian", + Norwegian: "Norwegian", + Polish: "Polish", + PortugueseBR: "Portuguese (Brazil)", + Romanian: "Romanian", + Russian: "Russian", + SpanishES: "Spanish (Spain)", + Swedish: "Swedish", + Thai: "Thai", + Turkish: "Turkish", + Ukrainian: "Ukrainian", + Vietnamese: "Vietnamese", + Unknown: "unknown", +}