From 9a58e3db845de57ea5c102e59eeb4bb4cc2dc3cd Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 21 Aug 2025 14:12:07 +0200 Subject: [PATCH 1/3] fix(command): not handling config interaction --- go.mod | 2 +- go.sum | 2 ++ main.go | 23 +++++++++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 2a9e497..abd4668 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.20250807111049-5de23912c524 + github.com/anhgelus/gokord v0.11.1-0.20250821115246-50e5f7d17717 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 df19706..288f1ba 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/anhgelus/gokord v0.11.1-0.20250806143823-567c33f63688 h1:0ngeLQxHr80X github.com/anhgelus/gokord v0.11.1-0.20250806143823-567c33f63688/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= github.com/anhgelus/gokord v0.11.1-0.20250807111049-5de23912c524 h1:mK7UtqJPNYhStRVeZ2N4c89tjlhlRZX0LcLs7TAB34I= github.com/anhgelus/gokord v0.11.1-0.20250807111049-5de23912c524/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= +github.com/anhgelus/gokord v0.11.1-0.20250821115246-50e5f7d17717 h1:KfcBHUpwbffRO6aIITq7iN7cP7KcKmUnIE+eWiwsYYw= +github.com/anhgelus/gokord v0.11.1-0.20250821115246-50e5f7d17717/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= diff --git a/main.go b/main.go index 0c45e6a..684ff6e 100644 --- a/main.go +++ b/main.go @@ -138,8 +138,26 @@ func main() { } // interaction: /config + bot.HandleMessageComponent(func(s *discordgo.Session, i *discordgo.InteractionCreate, data discordgo.MessageComponentInteractionData, resp *cmd.ResponseBuilder) { + if len(data.Values) != 1 { + logger.Alert("main.go - Handle config modify", "invalid data values", "values", data.Values) + return + } + switch data.Values[0] { + case config.ModifyXpRole: + config.HandleModifyXpRole(s, i, data, resp) + case config.ModifyFallbackChannel: + config.HandleModifyFallbackChannel(s, i, data, resp) + case config.ModifyDisChannel: + config.HandleModifyDisChannel(s, i, data, resp) + case config.ModifyTimeReduce: + config.HandleModifyPeriodicReduce(s, i, data, resp) + default: + logger.Alert("main.go - Detecting value", "unkown value", "value", data.Values[0]) + return + } + }, commands.ConfigModify) // xp role related - bot.HandleMessageComponent(config.HandleModifyXpRole, config.ModifyXpRole) bot.HandleMessageComponent(config.HandleXpRoleAddEdit, config.XpRoleAdd) bot.HandleMessageComponent(config.HandleXpRoleAddEdit, config.XpRoleEdit) bot.HandleMessageComponent(config.HandleXpRoleAddRole, config.XpRoleAddRole) @@ -149,15 +167,12 @@ func main() { bot.HandleModal(config.HandleXpRoleLevel, config.XpRoleAddLevel) bot.HandleModal(config.HandleXpRoleLevel, config.XpRoleEditLevel) // channel related - bot.HandleMessageComponent(config.HandleModifyFallbackChannel, config.ModifyFallbackChannel) bot.HandleMessageComponent(config.HandleFallbackChannelSet, config.FallbackChannelSet) - bot.HandleMessageComponent(config.HandleModifyDisChannel, config.ModifyDisChannel) bot.HandleMessageComponent(config.HandleDisChannel, config.DisChannelAdd) bot.HandleMessageComponent(config.HandleDisChannel, config.DisChannelDel) bot.HandleMessageComponent(config.HandleDisChannelAddSet, config.DisChannelAddSet) bot.HandleMessageComponent(config.HandleDisChannelDelSet, config.DisChannelDelSet) // reduce related - bot.HandleMessageComponent(config.HandleModifyPeriodicReduce, config.ModifyTimeReduce) bot.HandleModal(config.HandleTimeReduceSet, config.TimeReduceSet) // xp handlers From ecf41adc3c2b8746867a16c8d3c5a09ca89bc534 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 21 Aug 2025 14:38:59 +0200 Subject: [PATCH 2/3] fix(command): missing custom id for modal --- config/xp_reduce.go | 23 +++++++++++++---------- config/xp_role.go | 18 ++++++++++-------- exp/functions.go | 2 +- go.mod | 2 +- go.sum | 2 ++ 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/config/xp_reduce.go b/config/xp_reduce.go index 8e97c26..ce5f23c 100644 --- a/config/xp_reduce.go +++ b/config/xp_reduce.go @@ -1,11 +1,12 @@ package config import ( + "strconv" + "github.com/anhgelus/gokord/cmd" "github.com/anhgelus/gokord/component" "github.com/anhgelus/gokord/logger" "github.com/bwmarrin/discordgo" - "strconv" ) const ( @@ -14,11 +15,13 @@ const ( ) func HandleModifyPeriodicReduce(_ *discordgo.Session, _ *discordgo.InteractionCreate, _ discordgo.MessageComponentInteractionData, resp *cmd.ResponseBuilder) { - err := resp.IsModal().SetComponents(component.New().ForModal().Add(component.NewActionRow().Add( - component.NewTextInput(TimeReduceSet, "Jours avant la réduction", discordgo.TextInputShort). - SetMinLength(1). - SetMaxLength(3), - ))).Send() + err := resp.IsModal(). + SetCustomID(TimeReduceSet). + SetComponents(component.New().ForModal().Add(component.NewActionRow().ForModal().Add( + component.NewTextInput(TimeReduceSet, "Jours avant la réduction", discordgo.TextInputShort). + SetMinLength(1). + SetMaxLength(3), + ))).Send() if err != nil { logger.Alert("config/xp_reduce.go - Sending modal for periodic reduce", err.Error()) } @@ -31,14 +34,14 @@ func HandleTimeReduceSet(_ *discordgo.Session, i *discordgo.InteractionCreate, d if err != nil { logger.Debug(err.Error()) if err = resp.SetMessage("Nombres de jours invalides. Merci de mettre un entier.").Send(); err != nil { - logger.Alert("config/channel.go - Sending bad input", err.Error()) + logger.Alert("config/xp_reduce.go - Sending bad input", err.Error()) } return } if days < 30 { err = resp.SetMessage("Le nombre de jours est inférieur à 30.").Send() if err != nil { - logger.Alert("commands/config.go - Days < 30 (fallback)", err.Error()) + logger.Alert("config/xp_reduce.go - Days < 30 (fallback)", err.Error()) } return } @@ -47,11 +50,11 @@ func HandleTimeReduceSet(_ *discordgo.Session, i *discordgo.InteractionCreate, d if err = cfg.Save(); err != nil { logger.Alert("config/channel.go - Saving days xp remains", err.Error()) if err = resp.SetMessage("Erreur lors de la sauvegarde du salon").Send(); err != nil { - logger.Alert("config/channel.go - Sending error while saving days xp remains", err.Error()) + logger.Alert("config/xp_reduce.go - Sending error while saving days xp remains", err.Error()) } return } if err = resp.SetMessage("Modification sauvegardée.").Send(); err != nil { - logger.Alert("config/channel.go - Sending days saved", err.Error()) + logger.Alert("config/xp_reduce.go - Sending days saved", err.Error()) } } diff --git a/config/xp_role.go b/config/xp_role.go index 27981c0..dac980c 100644 --- a/config/xp_role.go +++ b/config/xp_role.go @@ -2,13 +2,14 @@ package config import ( "fmt" + "strconv" + "time" + "github.com/anhgelus/gokord" "github.com/anhgelus/gokord/cmd" "github.com/anhgelus/gokord/component" "github.com/anhgelus/gokord/logger" "github.com/bwmarrin/discordgo" - "strconv" - "time" ) type XpRole struct { @@ -52,7 +53,7 @@ func HandleModifyXpRole(_ *discordgo.Session, _ *discordgo.InteractionCreate, _ ), )).Send() if err != nil { - logger.Alert("config/guild.go - Sending config", err.Error()) + logger.Alert("config/xp_reduce.go - Sending config", err.Error()) } } @@ -63,7 +64,8 @@ func HandleXpRoleAddEdit(_ *discordgo.Session, _ *discordgo.InteractionCreate, d } err := resp.IsModal(). SetTitle("Role"). - SetComponents(component.New().ForModal().Add(component.NewActionRow().Add( + SetCustomID(cID). + SetComponents(component.New().ForModal().Add(component.NewActionRow().ForModal().Add( component.NewTextInput(cID, "Niveau", discordgo.TextInputShort). SetPlaceholder("5"). IsRequired(). @@ -72,7 +74,7 @@ func HandleXpRoleAddEdit(_ *discordgo.Session, _ *discordgo.InteractionCreate, d ))). Send() if err != nil { - logger.Alert("config/guild.go - Sending modal to add/edit", err.Error()) + logger.Alert("config/xp_reduce.go - Sending modal to add/edit", err.Error()) } } @@ -142,7 +144,7 @@ func HandleXpRoleDel(_ *discordgo.Session, _ *discordgo.InteractionCreate, _ dis SetComponents(component.New().Add(component.NewActionRow().Add(component.NewRoleSelect(XpRoleDelRole)))). Send() if err != nil { - logger.Alert("config/guild.go - Sending response to del", err.Error()) + logger.Alert("config/xp_reduce.go - Sending response to del", err.Error()) } } @@ -204,10 +206,10 @@ func HandleXpRoleLevel(_ *discordgo.Session, i *discordgo.InteractionCreate, dat SetComponents(component.New().Add(component.NewActionRow().Add(component.NewRoleSelect(cID)))). Send() if err != nil { - logger.Alert("config/guild.go - Sending response to add/edit", err.Error()) + logger.Alert("config/xp_reduce.go - Sending response to add/edit", err.Error()) } } func getKeyConfigRole(i *discordgo.InteractionCreate) string { - return fmt.Sprintf("r:%s:%s", i.GuildID, i.User.ID) + return fmt.Sprintf("r:%s:%s", i.GuildID, i.Member.User.ID) } diff --git a/exp/functions.go b/exp/functions.go index 2608094..a8b0350 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -53,7 +53,7 @@ func LevelXP(level uint) uint { func TimeStampNDaysBefore(n uint) string { var unix time.Time if gokord.Debug { - unix = time.Unix(time.Now().Unix()-int64(n), 0) // reduce time for debug + unix = time.Unix(time.Now().Unix()-int64(n)*6, 0) // reduce time for debug } else { unix = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0) } diff --git a/go.mod b/go.mod index abd4668..df8f3bb 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.20250821115246-50e5f7d17717 + github.com/anhgelus/gokord v0.11.1-0.20250821122244-0aee6c37eef6 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 288f1ba..c011b86 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/anhgelus/gokord v0.11.1-0.20250807111049-5de23912c524 h1:mK7UtqJPNYhS github.com/anhgelus/gokord v0.11.1-0.20250807111049-5de23912c524/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= github.com/anhgelus/gokord v0.11.1-0.20250821115246-50e5f7d17717 h1:KfcBHUpwbffRO6aIITq7iN7cP7KcKmUnIE+eWiwsYYw= github.com/anhgelus/gokord v0.11.1-0.20250821115246-50e5f7d17717/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k= +github.com/anhgelus/gokord v0.11.1-0.20250821122244-0aee6c37eef6 h1:4eO/9UqTPfrKyss2CeLafeKeR06bgoFihudKOdLpWpI= +github.com/anhgelus/gokord v0.11.1-0.20250821122244-0aee6c37eef6/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= From 15448aa0014e1473582227e2ea301df7ccfb9560 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 21 Aug 2025 14:53:18 +0200 Subject: [PATCH 3/3] fix(config): saving level and not xp for role --- config/xp_role.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/xp_role.go b/config/xp_role.go index dac980c..f815cc2 100644 --- a/config/xp_role.go +++ b/config/xp_role.go @@ -9,6 +9,7 @@ import ( "github.com/anhgelus/gokord/cmd" "github.com/anhgelus/gokord/component" "github.com/anhgelus/gokord/logger" + "github.com/anhgelus/les-copaings-bot/exp" "github.com/bwmarrin/discordgo" ) @@ -189,7 +190,7 @@ func HandleXpRoleLevel(_ *discordgo.Session, i *discordgo.InteractionCreate, dat } return } - configModifyMap[k] = uint(in) + configModifyMap[k] = exp.LevelXP(uint(in)) go func(i *discordgo.InteractionCreate, k string) { time.Sleep(5 * time.Minute) delete(configModifyMap, k)