aboutsummaryrefslogtreecommitdiff
path: root/commands/config.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-15 16:44:46 +0200
committerAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-15 16:44:46 +0200
commitf97df035c36c546afd665a1ec7da04cad35d869a (patch)
tree066f47b5b31323e7a88010c0f5a274c6bea6e524 /commands/config.go
parent5451dd0e817294c5d53b4e6f6621982bff964d40 (diff)
feat(config): disable channel for xp
Diffstat (limited to 'commands/config.go')
-rw-r--r--commands/config.go78
1 files changed, 78 insertions, 0 deletions
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())
+ }
+}