feat(config): disable channel for xp

This commit is contained in:
Anhgelus Morhtuuzh 2024-04-15 16:44:46 +02:00
parent 5451dd0e81
commit f97df035c3
No known key found for this signature in database
GPG key ID: CF4550297832A29F
4 changed files with 106 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/anhgelus/les-copaings-bot/config"
"github.com/anhgelus/les-copaings-bot/xp"
"github.com/bwmarrin/discordgo"
"strings"
)
func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
@ -21,6 +22,20 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
roles += fmt.Sprintf("> Niveau %d - <@&%s>\n", xp.Level(r.XP), r.RoleID)
}
}
if len(roles) == 0 {
roles = "Aucun rôle configuré :("
}
disChans := strings.Split(cfg.DisabledChannels, ";")
l = len(disChans) - 1
chans := ""
for i, c := range disChans {
if i != l {
chans += fmt.Sprintf("> <#%s>", c)
}
}
if len(chans) == 0 {
chans = "Aucun salon désactivé :)"
}
err := resp.Embeds([]*discordgo.MessageEmbed{
{
Type: discordgo.EmbedTypeRich,
@ -33,6 +48,11 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
Value: roles,
Inline: false,
},
{
Name: "Salons désactivés",
Value: chans,
Inline: false,
},
},
},
}).Send()
@ -133,3 +153,61 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
utils.SendAlert("commands/config.go - Config updated", err.Error())
}
}
func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
optMap := utils.GenerateOptionMapForSubcommand(i)
resp := utils.ResponseBuilder{C: s, I: i}
resp.IsEphemeral()
// verify every args
t, ok := optMap["type"]
if !ok {
err := resp.Message("Le type d'action n'a pas été renseigné.").Send()
if err != nil {
utils.SendAlert("commands/config.go - Action type not set", err.Error())
}
return
}
ts := t.StringValue()
salon, ok := optMap["channel"]
if !ok {
err := resp.Message("Le salon n'a pas été renseigné.").Send()
if err != nil {
utils.SendAlert("commands/config.go - Channel not set", err.Error())
}
return
}
channel := salon.ChannelValue(s)
cfg := config.GetGuildConfig(i.GuildID)
switch ts {
case "add":
if strings.Contains(cfg.DisabledChannels, channel.ID) {
err := resp.Message("Le salon est déjà dans la liste des salons désactivés").Send()
if err != nil {
utils.SendAlert("commands/config.go - Channel already disabled", err.Error())
}
return
}
cfg.DisabledChannels += channel.ID + ";"
case "del":
if !strings.Contains(cfg.DisabledChannels, channel.ID) {
err := resp.Message("Le salon n'est pas désactivé").Send()
if err != nil {
utils.SendAlert("commands/config.go - Channel not disabled", err.Error())
}
return
}
cfg.DisabledChannels = strings.ReplaceAll(cfg.DisabledChannels, channel.ID+";", "")
default:
err := resp.Message("Le type d'action n'est pas valide.").Send()
if err != nil {
utils.SendAlert("commands/config.go - Invalid action type", err.Error())
}
return
}
// save
cfg.Save()
err := resp.Message("Modification sauvegardé.").Send()
if err != nil {
utils.SendAlert("commands/config.go - Modification saved message", err.Error())
}
}