feat(command): /config for days before reduction
This commit is contained in:
parent
8b174209e1
commit
f56e10514e
3 changed files with 71 additions and 4 deletions
|
@ -42,7 +42,6 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
{
|
{
|
||||||
Type: discordgo.EmbedTypeRich,
|
Type: discordgo.EmbedTypeRich,
|
||||||
Title: "Config",
|
Title: "Config",
|
||||||
Description: "Configuration",
|
|
||||||
Color: utils.Success,
|
Color: utils.Success,
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
|
@ -60,6 +59,11 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
Value: chans,
|
Value: chans,
|
||||||
Inline: false,
|
Inline: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "Jours avant la réduction",
|
||||||
|
Value: fmt.Sprintf("%d", cfg.DaysXPRemains),
|
||||||
|
Inline: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).Send()
|
}).Send()
|
||||||
|
@ -316,3 +320,46 @@ func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate)
|
||||||
utils.SendAlert("commands/config.go - Channel saved message", err.Error())
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -99,6 +99,16 @@ func main() {
|
||||||
).IsRequired()).
|
).IsRequired()).
|
||||||
SetHandler(commands.ConfigChannel),
|
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(
|
AddSub(
|
||||||
gokord.NewCommand("fallback-channel", "Modifie le salon textuel par défaut").
|
gokord.NewCommand("fallback-channel", "Modifie le salon textuel par défaut").
|
||||||
HasOption().
|
HasOption().
|
||||||
|
|
10
updates.json
10
updates.json
|
@ -8,5 +8,15 @@
|
||||||
"config"
|
"config"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "3.0.0",
|
||||||
|
"commands": {
|
||||||
|
"added": [],
|
||||||
|
"removed": [],
|
||||||
|
"updated": [
|
||||||
|
"config"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue