aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-05-13 21:07:04 +0200
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-05-13 21:07:04 +0200
commitf56e10514e0fe74599fcdaea553f59cfe0cf5f70 (patch)
tree5ce8d9a8f4101a9f2816af46ac1aa5b3bc049f7b
parent8b174209e193746216e711423cb26cebd0786581 (diff)
feat(command): /config for days before reduction
-rw-r--r--commands/config.go55
-rw-r--r--main.go10
-rw-r--r--updates.json10
3 files changed, 71 insertions, 4 deletions
diff --git a/commands/config.go b/commands/config.go
index 4615c36..d31b929 100644
--- a/commands/config.go
+++ b/commands/config.go
@@ -40,10 +40,9 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
}
err := resp.Embeds([]*discordgo.MessageEmbed{
{
- Type: discordgo.EmbedTypeRich,
- Title: "Config",
- Description: "Configuration",
- Color: utils.Success,
+ Type: discordgo.EmbedTypeRich,
+ Title: "Config",
+ Color: utils.Success,
Fields: []*discordgo.MessageEmbedField{
{
Name: "Salons par défaut",
@@ -60,6 +59,11 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
Value: chans,
Inline: false,
},
+ {
+ Name: "Jours avant la réduction",
+ Value: fmt.Sprintf("%d", cfg.DaysXPRemains),
+ Inline: false,
+ },
},
},
}).Send()
@@ -316,3 +320,46 @@ func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate)
utils.SendAlert("commands/config.go - Channel saved message", err.Error())
}
}
+
+func ConfigPeriodBeforeReduce(s *discordgo.Session, i *discordgo.InteractionCreate) {
+ optMap := utils.GenerateOptionMapForSubcommand(i)
+ resp := utils.ResponseBuilder{C: s, I: i}
+ resp.IsEphemeral()
+ // verify every args
+ days, ok := optMap["days"]
+ if !ok {
+ err := resp.Message("Le nombre de jours n'a pas été renseigné.").Send()
+ if err != nil {
+ utils.SendAlert("commands/config.go - Days not set (fallback)", err.Error())
+ }
+ return
+ }
+ d := days.IntValue()
+ if d < 30 {
+ err := resp.Message("Le nombre de jours est inférieur à 30.").Send()
+ if err != nil {
+ utils.SendAlert("commands/config.go - Days < 30 (fallback)", err.Error())
+ }
+ return
+ }
+ // save
+ cfg := config.GetGuildConfig(i.GuildID)
+ cfg.DaysXPRemains = uint(d)
+ err := cfg.Save()
+ if err != nil {
+ utils.SendAlert(
+ "commands/config.go - Saving config",
+ err.Error(),
+ "guild_id",
+ i.GuildID,
+ "days",
+ d,
+ )
+ err = resp.Message("Il y a eu une erreur lors de la modification de de la base de données.").Send()
+ } else {
+ err = resp.Message("Nombre de jours enregistré.").Send()
+ }
+ if err != nil {
+ utils.SendAlert("commands/config.go - Days saved message", err.Error())
+ }
+}
diff --git a/main.go b/main.go
index 2035cb5..4b4062e 100644
--- a/main.go
+++ b/main.go
@@ -100,6 +100,16 @@ func main() {
SetHandler(commands.ConfigChannel),
).
AddSub(
+ gokord.NewCommand("period-before-reduce", "Temps avant la perte d'xp (affecte aussi le /top)").
+ HasOption().
+ 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").
HasOption().
AddOption(gokord.NewOption(
diff --git a/updates.json b/updates.json
index c378f8b..fd73d8f 100644
--- a/updates.json
+++ b/updates.json
@@ -8,5 +8,15 @@
"config"
]
}
+ },
+ {
+ "version": "3.0.0",
+ "commands": {
+ "added": [],
+ "removed": [],
+ "updated": [
+ "config"
+ ]
+ }
}
]