aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-07-30 21:57:05 +0200
committerWilliam Hergès <william@herges.fr>2025-07-30 21:57:05 +0200
commitb4408674c901d03da72f9471cf1a19762f03b03a (patch)
tree13280bf0f81751093e8db14fc3060bcaa80e1a7a
parent977c818328c1c14880029510c6b3742a12858dcb (diff)
refactor(command): use message component to edit config
-rw-r--r--commands/config.go47
-rw-r--r--main.go67
-rw-r--r--updates.json10
3 files changed, 59 insertions, 65 deletions
diff --git a/commands/config.go b/commands/config.go
index 48d7ab8..472a4ea 100644
--- a/commands/config.go
+++ b/commands/config.go
@@ -10,7 +10,15 @@ import (
"strings"
)
-func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
+const (
+ SelectConfigModify = "config_modify"
+ SelectOptConfigXpRole = "xp_role"
+ SelectOptConfigDisChannel = "disabled_channel"
+ SelectOptConfigFallbackChannel = "fallback_channel"
+ SelectOptConfigTimeReduce = "time_reduce"
+)
+
+func Config(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
cfg := config.GetGuildConfig(i.GuildID)
roles := ""
l := len(cfg.XpRoles) - 1
@@ -69,13 +77,46 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap uti
Inline: false,
},
},
- }).Send()
+ }).AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{
+ discordgo.SelectMenu{
+ MenuType: discordgo.StringSelectMenu,
+ CustomID: SelectConfigModify,
+ Placeholder: "Modifier...",
+ Options: []discordgo.SelectMenuOption{
+ {
+ Label: "Rôles liés à l'XP",
+ Value: SelectOptConfigXpRole,
+ Description: "Gère les rôles liés à l'XP",
+ Emoji: &discordgo.ComponentEmoji{Name: "🏅"},
+ },
+ {
+ Label: "Salons désactivés",
+ Value: SelectOptConfigDisChannel,
+ 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: SelectOptConfigFallbackChannel,
+ Description: "Spécifie le salon de repli",
+ Emoji: &discordgo.ComponentEmoji{Name: "💾"},
+ },
+ {
+ Label: "Temps avec la réduction",
+ Value: SelectOptConfigTimeReduce,
+ Description: "Gère le temps avant la réduction d'XP",
+ Emoji: &discordgo.ComponentEmoji{Name: "⌛"},
+ },
+ },
+ Disabled: false,
+ },
+ }}).IsEphemeral().Send()
if err != nil {
utils.SendAlert("config/guild.go - Sending config", err.Error())
}
}
-func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
+func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
resp.IsEphemeral()
// verify every args
t, ok := optMap["type"]
diff --git a/main.go b/main.go
index 4610bc4..b2def4f 100644
--- a/main.go
+++ b/main.go
@@ -60,68 +60,8 @@ func main() {
SetHandler(commands.Rank)
configCmd := gokord.NewCommand("config", "Modifie la config").
- ContainsSub().
- AddSub(
- gokord.NewCommand("show", "Affiche la config").SetHandler(commands.ConfigShow),
- ).
- AddSub(
- gokord.NewCommand("xp", "Modifie l'xp").
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionString,
- "type",
- "Type d'action à effectuer",
- ).
- AddChoice(gokord.NewChoice("Ajouter", "add")).
- AddChoice(gokord.NewChoice("Supprimer", "del")).
- AddChoice(gokord.NewChoice("Modifier", "edit")).IsRequired(),
- ).
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionInteger,
- "level",
- "Niveau du rôle",
- ).IsRequired()).
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionRole,
- "role",
- "Rôle",
- ).IsRequired()).
- SetHandler(commands.ConfigXP),
- ).
- AddSub(
- gokord.NewCommand("disabled-channels", "Modifie les salons désactivés").
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionString,
- "type",
- "Type d'action à effectuer",
- ).
- AddChoice(gokord.NewChoice("Désactiver le salon", "add")).
- AddChoice(gokord.NewChoice("Activer le salon", "del")).IsRequired(),
- ).
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionChannel,
- "channel",
- "Salon à modifier",
- ).IsRequired()).
- SetHandler(commands.ConfigChannel),
- ).
- AddSub(
- gokord.NewCommand("period-before-reduce", "Temps avant la perte d'xp (affecte aussi le /top)").
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionInteger,
- "days",
- "Nombre de jours avant la perte d'xp (doit être égal ou plus grand que 30)",
- ).IsRequired()).
- SetHandler(commands.ConfigPeriodBeforeReduce),
- ).
- AddSub(
- gokord.NewCommand("fallback-channel", "Modifie le salon textuel par défaut").
- AddOption(gokord.NewOption(
- discordgo.ApplicationCommandOptionChannel,
- "channel",
- "Salon textuel par défaut",
- ).IsRequired()).
- SetHandler(commands.ConfigFallbackChannel),
- ).SetPermission(&adm)
+ SetPermission(&adm).
+ SetHandler(commands.Config)
topCmd := gokord.NewCommand("top", "Copaings les plus actifs").
SetHandler(commands.Top)
@@ -198,4 +138,7 @@ func afterInit(dg *discordgo.Session) {
stopPeriodicReducer = utils.NewTimer(24*time.Hour, func(stop chan<- interface{}) {
user.PeriodicReducer(dg)
})
+
+ //interaction: /config
+ dg.AddHandler(commands.ConfigXP)
}
diff --git a/updates.json b/updates.json
index d0d863c..debf5a5 100644
--- a/updates.json
+++ b/updates.json
@@ -28,5 +28,15 @@
"ping"
]
}
+ },
+ {
+ "version": "3.2.0",
+ "commands": {
+ "added": [],
+ "removed": [],
+ "updated": [
+ "config"
+ ]
+ }
}
]