From f97df035c36c546afd665a1ec7da04cad35d869a Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 15 Apr 2024 16:44:46 +0200 Subject: feat(config): disable channel for xp --- commands/config.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'commands/config.go') diff --git a/commands/config.go b/commands/config.go index 539c6f9..e663b40 100644 --- a/commands/config.go +++ b/commands/config.go @@ -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()) + } +} -- cgit v1.2.3