refactor(config): handle disabled channels
This commit is contained in:
parent
0b93ea5daa
commit
b9466f8122
3 changed files with 88 additions and 72 deletions
|
@ -102,73 +102,3 @@ func Config(_ *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMa
|
|||
logger.Alert("config/guild.go - Sending config", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap cmd.OptionMap, resp *cmd.ResponseBuilder) {
|
||||
resp.IsEphemeral()
|
||||
// verify every args
|
||||
t, ok := optMap["type"]
|
||||
if !ok {
|
||||
err := resp.SetMessage("Le type d'action n'a pas été renseigné.").Send()
|
||||
if err != nil {
|
||||
logger.Alert("commands/config.go - Action type not set", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
ts := t.StringValue()
|
||||
salon, ok := optMap["channel"]
|
||||
if !ok {
|
||||
err := resp.SetMessage("Le salon n'a pas été renseigné.").Send()
|
||||
if err != nil {
|
||||
logger.Alert("commands/config.go - Channel not set (disabled)", 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.SetMessage("Le salon est déjà dans la liste des salons désactivés").Send()
|
||||
if err != nil {
|
||||
logger.Alert("commands/config.go - Channel already disabled", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
cfg.DisabledChannels += channel.ID + ";"
|
||||
case "del":
|
||||
if !strings.Contains(cfg.DisabledChannels, channel.ID) {
|
||||
err := resp.SetMessage("Le salon n'est pas désactivé").Send()
|
||||
if err != nil {
|
||||
logger.Alert("commands/config.go - Channel not disabled", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
cfg.DisabledChannels = strings.ReplaceAll(cfg.DisabledChannels, channel.ID+";", "")
|
||||
default:
|
||||
err := resp.SetMessage("Le type d'action n'est pas valide.").Send()
|
||||
if err != nil {
|
||||
logger.Alert("commands/config.go - Invalid action type", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
// save
|
||||
err := cfg.Save()
|
||||
if err != nil {
|
||||
logger.Alert(
|
||||
"commands/config.go - Saving config",
|
||||
err.Error(),
|
||||
"guild_id",
|
||||
i.GuildID,
|
||||
"type",
|
||||
ts,
|
||||
"channel_id",
|
||||
channel.ID,
|
||||
)
|
||||
err = resp.SetMessage("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
||||
} else {
|
||||
err = resp.SetMessage("Modification sauvegardé.").Send()
|
||||
}
|
||||
if err != nil {
|
||||
logger.Alert("commands/config.go - Modification saved message", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue