From 0cd725108c998aedcf647ce39cd80a325b33cfa0 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Wed, 6 Aug 2025 02:47:41 +0200 Subject: [PATCH] feat(gokord): use new component lib --- commands/config.go | 148 ++++++++++++++++++++------------------------- go.mod | 2 +- go.sum | 6 ++ 3 files changed, 74 insertions(+), 82 deletions(-) diff --git a/commands/config.go b/commands/config.go index c6eca0d..3084056 100644 --- a/commands/config.go +++ b/commands/config.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/anhgelus/gokord" "github.com/anhgelus/gokord/cmd" + "github.com/anhgelus/gokord/component" "github.com/anhgelus/gokord/logger" "github.com/anhgelus/les-copaings-bot/config" "github.com/anhgelus/les-copaings-bot/exp" @@ -34,7 +35,7 @@ var ( configModifyMap = map[string]uint{} ) -func Config(s *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) { +func Config(_ *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) { cfg := config.GetGuildConfig(i.GuildID) roles := "" l := len(cfg.XpRoles) - 1 @@ -93,40 +94,30 @@ func Config(s *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMa Inline: false, }, }, - }).AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{ - discordgo.SelectMenu{ - MenuType: discordgo.StringSelectMenu, - CustomID: ConfigModify, - Placeholder: "Modifier...", - Options: []discordgo.SelectMenuOption{ - { - Label: "Rôles liés à l'XP", - Value: ConfigModifyXpRole, - Description: "Gère les rôles liés à l'XP", - Emoji: &discordgo.ComponentEmoji{Name: "🏅"}, - }, - { - Label: "Salons désactivés", - Value: ConfigModifyDisChannel, - Description: "Gère les salons désactivés", - Emoji: &discordgo.ComponentEmoji{Name: "❌"}, - }, - { - Label: "Salons de repli", // I don't have a better idea for this... - Value: ConfigModifyFallbackChannel, - Description: "Spécifie le salon de repli", - Emoji: &discordgo.ComponentEmoji{Name: "💾"}, - }, - { - Label: "Temps avec la réduction", - Value: ConfigModifyTimeReduce, - Description: "Gère le temps avant la réduction d'XP", - Emoji: &discordgo.ComponentEmoji{Name: "⌛"}, - }, - }, - Disabled: false, - }, - }}).IsEphemeral().Send() + }).SetComponents(component.New().Add(new(component.ActionRow).Add( + new(component.StringSelect).SetPlaceholder("Modifier..."). + AddOption( + component.NewSelectOption("Rôles liés à l'XP", ConfigModifyXpRole). + SetDescription("Gère les rôles liés à l'XP"). + SetEmoji(&discordgo.ComponentEmoji{Name: "🏅"}), + ). + AddOption( + component.NewSelectOption("Salons désactivés", ConfigModifyDisChannel). + SetDescription("Gère les salons désactivés"). + SetEmoji(&discordgo.ComponentEmoji{Name: "❌"}), + ). + AddOption( + component.NewSelectOption("Salons de repli", ConfigModifyFallbackChannel). // I don't have a better idea for this... + SetDescription("Spécifie le salon de repli"). + SetEmoji(&discordgo.ComponentEmoji{Name: "💾"}), + ). + AddOption( + component.NewSelectOption("Temps avec la réduction", ConfigModifyTimeReduce). + SetDescription("Gère le temps avant la réduction d'XP"). + SetEmoji(&discordgo.ComponentEmoji{Name: "⌛"}), + ). + SetCustomID(ConfigModify), + ))).IsEphemeral().Send() if err != nil { logger.Alert("config/guild.go - Sending config", err.Error()) } @@ -146,33 +137,25 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) { case ConfigModifyXpRole: err := resp.IsEphemeral(). SetMessage("Action à réaliser"). - AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{ - discordgo.SelectMenu{ - MenuType: discordgo.StringSelectMenu, - CustomID: ConfigModify, - Placeholder: "Action", - Options: []discordgo.SelectMenuOption{ - { - Label: "Ajouter", - Value: XpRoleAdd, - Description: "Ajouter un rôle à XP", - Emoji: &discordgo.ComponentEmoji{Name: "⬆️"}, - }, - { - Label: "Supprimer", - Value: XpRoleDel, - Description: "Supprimer un rôle à XP", - Emoji: &discordgo.ComponentEmoji{Name: "❌"}, - }, - { - Label: "Modifier", - Value: XpRoleEdit, - Description: "Modifier un rôle à XP", - Emoji: &discordgo.ComponentEmoji{Name: "📝"}, - }, - }, - }, - }}).Send() + SetComponents(component.New().Add(new(component.ActionRow).Add( + new(component.StringSelect).SetPlaceholder("Action"). + AddOption( + component.NewSelectOption("Ajouter", XpRoleAdd). + SetDescription("Ajouter un rôle à XP"). + SetEmoji(&discordgo.ComponentEmoji{Name: "⬆️"}), + ). + AddOption( + component.NewSelectOption("Modifier", XpRoleEdit). + SetDescription("Modifier un rôle à XP"). + SetEmoji(&discordgo.ComponentEmoji{Name: "📝"}), + ). + AddOption( + component.NewSelectOption("Supprimer", XpRoleDel). + SetDescription("Supprimer un rôle à XP"). + SetEmoji(&discordgo.ComponentEmoji{Name: "❌"}), + ). + SetCustomID(ConfigModify), + ))).Send() if err != nil { logger.Alert("config/guild.go - Sending config", err.Error()) } @@ -181,19 +164,28 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) { if msgData.CustomID == XpRoleEdit { cID = XpRoleEditLevel } + component.New().ForModal().Add(new(component.ActionRow).Add( + new(component.TextInput). + SetLabel("Niveau"). + SetPlaceholder("5"). + IsRequired(). + SetMinLength(0). + SetMaxLength(5). + SetStyle(discordgo.TextInputShort). + SetCustomID(cID), + )) err := resp.IsModal(). SetTitle("Role"). - AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{ - discordgo.TextInput{ - CustomID: cID, - Label: "Niveau", - Style: discordgo.TextInputShort, - Placeholder: "5", - Required: true, - MinLength: 0, - MaxLength: 5, - }, - }}). + SetComponents(component.New().ForModal().Add(new(component.ActionRow).Add( + new(component.TextInput). + SetLabel("Niveau"). + SetPlaceholder("5"). + IsRequired(). + SetMinLength(0). + SetMaxLength(5). + SetStyle(discordgo.TextInputShort). + SetCustomID(cID), + ))). Send() if err != nil { logger.Alert("config/guild.go - Sending modal to add", err.Error()) @@ -253,10 +245,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) { case XpRoleDel: err := resp.IsEphemeral(). SetMessage("Rôle à supprimer"). - AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{discordgo.SelectMenu{ - MenuType: discordgo.RoleSelectMenu, - CustomID: XpRoleDelRole, - }}}). + SetComponents(component.New().Add(new(component.ActionRow).Add(new(component.RoleSelect).SetCustomID(XpRoleDelRole)))). Send() if err != nil { logger.Alert("config/guild.go - Sending response to del", err.Error()) @@ -332,10 +321,7 @@ func ConfigXPModal(s *discordgo.Session, i *discordgo.InteractionCreate) { err = resp.IsEphemeral(). SetMessage("Rôle à supprimer"). - AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{discordgo.SelectMenu{ - MenuType: discordgo.RoleSelectMenu, - CustomID: cID, - }}}). + SetComponents(component.New().Add(new(component.ActionRow).Add(new(component.RoleSelect).SetCustomID(cID)))). Send() if err != nil { logger.Alert("config/guild.go - Sending response to add/edit", err.Error()) diff --git a/go.mod b/go.mod index d3fae23..8b4222f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/anhgelus/les-copaings-bot go 1.24 require ( - github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1 + github.com/anhgelus/gokord v0.11.1-0.20250806004311-9988b375047f github.com/bwmarrin/discordgo v0.29.0 github.com/joho/godotenv v1.5.1 github.com/pelletier/go-toml/v2 v2.2.4 diff --git a/go.sum b/go.sum index e083c17..21beeff 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,11 @@ github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1 h1:irHDC/xUm65yLFx5HnVeCbM0qQRpm0i1vQHsyLXeEbo= github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= +github.com/anhgelus/gokord v0.11.1-0.20250806003339-90cf89cde031 h1:56vqHQzCHCcMeBBhAWUyC466BETAhaIl1Qiq93WdrYI= +github.com/anhgelus/gokord v0.11.1-0.20250806003339-90cf89cde031/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= +github.com/anhgelus/gokord v0.11.1-0.20250806003704-21a4238c64a0 h1:Jj4ja4bshyEHOd+stqqB4e0iuggtDx/hzZ8K69+rtsE= +github.com/anhgelus/gokord v0.11.1-0.20250806003704-21a4238c64a0/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= +github.com/anhgelus/gokord v0.11.1-0.20250806004311-9988b375047f h1:OSTlmWDVRGw3bt4uHOBFyUWNNl5VV3zaB6Xj0TWlY0s= +github.com/anhgelus/gokord v0.11.1-0.20250806004311-9988b375047f/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=