Skip to content

Commit

Permalink
Merge pull request #113 from DisgoOrg/feature/interaction-locale
Browse files Browse the repository at this point in the history
add interaction locales
  • Loading branch information
topi314 authored Jan 11, 2022
2 parents 8bba4eb + 34459a4 commit 05af231
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 1 deletion.
5 changes: 5 additions & 0 deletions _examples/test/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion _examples/test/examplebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
9 changes: 9 additions & 0 deletions _examples/test/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions core/entity_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions core/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
82 changes: 82 additions & 0 deletions discord/locale.go
Original file line number Diff line number Diff line change
@@ -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",
}

0 comments on commit 05af231

Please sign in to comment.