feat(command): reset and reset-user

This commit is contained in:
Anhgelus Morhtuuzh 2024-04-16 15:58:20 +02:00
parent 6b595b8b11
commit fe789ad072
No known key found for this signature in database
GPG key ID: CF4550297832A29F
3 changed files with 56 additions and 0 deletions

35
commands/reset.go Normal file
View file

@ -0,0 +1,35 @@
package commands
import (
"github.com/anhgelus/gokord"
"github.com/anhgelus/gokord/utils"
"github.com/anhgelus/les-copaings-bot/xp"
"github.com/bwmarrin/discordgo"
)
func Reset(s *discordgo.Session, i *discordgo.InteractionCreate) {
var copaings []*xp.Copaing
gokord.DB.Where("guild_id = ?", i.GuildID).Delete(&copaings)
resp := utils.ResponseBuilder{C: s, I: i}
if err := resp.IsEphemeral().Message("L'XP a été reset.").Send(); err != nil {
utils.SendAlert("commands/reset.go - Sending success (all)", err.Error())
}
}
func ResetUser(s *discordgo.Session, i *discordgo.InteractionCreate) {
resp := utils.ResponseBuilder{C: s, I: i}
resp.IsEphemeral()
optMap := utils.GenerateOptionMap(i)
v, ok := optMap["copaing"]
if !ok {
if err := resp.Message("Le copaing n'a pas été renseigné.").Send(); err != nil {
utils.SendAlert("commands/reset.go - Copaing not set", err.Error())
}
return
}
m := v.UserValue(s)
xp.GetCopaing(m.ID, i.GuildID).Reset()
if err := resp.Message("Le a bien été reset.").Send(); err != nil {
utils.SendAlert("commands/reset.go - Sending success (copaing)", err.Error())
}
}