feat(command): reset and reset-user
This commit is contained in:
parent
6b595b8b11
commit
fe789ad072
3 changed files with 56 additions and 0 deletions
35
commands/reset.go
Normal file
35
commands/reset.go
Normal 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())
|
||||||
|
}
|
||||||
|
}
|
17
main.go
17
main.go
|
@ -100,6 +100,21 @@ func main() {
|
||||||
HasOption().
|
HasOption().
|
||||||
SetHandler(commands.Top)
|
SetHandler(commands.Top)
|
||||||
|
|
||||||
|
resetCmd := gokord.NewCommand("reset", "Reset l'xp").
|
||||||
|
HasOption().
|
||||||
|
SetHandler(commands.Reset).
|
||||||
|
SetPermission(gokord.AdminPermission)
|
||||||
|
|
||||||
|
resetUserCmd := gokord.NewCommand("reset-user", "Reset l'xp d'un utilisation").
|
||||||
|
HasOption().
|
||||||
|
AddOption(gokord.NewOption(
|
||||||
|
discordgo.ApplicationCommandOptionUser,
|
||||||
|
"copaing",
|
||||||
|
"Copaing a reset",
|
||||||
|
).IsRequired()).
|
||||||
|
SetHandler(commands.ResetUser).
|
||||||
|
SetPermission(gokord.AdminPermission)
|
||||||
|
|
||||||
bot := gokord.Bot{
|
bot := gokord.Bot{
|
||||||
Token: token,
|
Token: token,
|
||||||
Status: []*gokord.Status{
|
Status: []*gokord.Status{
|
||||||
|
@ -113,6 +128,8 @@ func main() {
|
||||||
rankCmd,
|
rankCmd,
|
||||||
configCmd,
|
configCmd,
|
||||||
topCmd,
|
topCmd,
|
||||||
|
resetCmd,
|
||||||
|
resetUserCmd,
|
||||||
},
|
},
|
||||||
AfterInit: afterInit,
|
AfterInit: afterInit,
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,10 @@ func (c *Copaing) GetUserBase() *gokord.UserBase {
|
||||||
return &gokord.UserBase{DiscordID: c.DiscordID, GuildID: c.GuildID}
|
return &gokord.UserBase{DiscordID: c.DiscordID, GuildID: c.GuildID}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Copaing) Reset() {
|
||||||
|
gokord.DB.Where("guild_id = ? AND discord_id", c.GuildID, c.DiscordID).Delete(c)
|
||||||
|
}
|
||||||
|
|
||||||
func getRedisClient() (*redis.Client, error) {
|
func getRedisClient() (*redis.Client, error) {
|
||||||
if redisClient == nil {
|
if redisClient == nil {
|
||||||
var err error
|
var err error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue