refactor(config): handle fallback channel

This commit is contained in:
Anhgelus Morhtuuzh 2025-08-06 15:13:19 +02:00
parent 0968c18b15
commit 6d19ef42c4
Signed by: anhgelus
GPG key ID: 617773CACE89052C
4 changed files with 60 additions and 56 deletions

View file

@ -12,10 +12,8 @@ import (
)
const (
ConfigModify = "config_modify"
ConfigModifyDisChannel = "disabled_channel"
ConfigModifyFallbackChannel = "fallback_channel"
ConfigModifyTimeReduce = "time_reduce"
ConfigModify = "config_modify"
ConfigModifyTimeReduce = "time_reduce"
)
func Config(_ *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) {
@ -85,13 +83,13 @@ func Config(_ *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMa
SetEmoji(&discordgo.ComponentEmoji{Name: "🏅"}),
).
AddOption(
component.NewSelectOption("Salons désactivés", ConfigModifyDisChannel).
component.NewSelectOption("Salons désactivés", config.ModifyDisChannel).
SetDescription("Gère les salons désactivés").
SetEmoji(&discordgo.ComponentEmoji{Name: "❌"}),
).
AddOption(
// I don't have a better idea for this...
component.NewSelectOption("Salons de repli", ConfigModifyFallbackChannel).
component.NewSelectOption("Salons de repli", config.ModifyFallbackChannel).
SetDescription("Spécifie le salon de repli").
SetEmoji(&discordgo.ComponentEmoji{Name: "💾"}),
).
@ -176,47 +174,6 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap
}
}
func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap cmd.OptionMap, resp *cmd.ResponseBuilder) {
resp.IsEphemeral()
// verify every args
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 (fallback)", err.Error())
}
return
}
channel := salon.ChannelValue(s)
if channel.Type != discordgo.ChannelTypeGuildText {
err := resp.SetMessage("Le salon n'est pas un salon textuel.").Send()
if err != nil {
logger.Alert("commands/config.go - Invalid channel type", err.Error())
}
return
}
cfg := config.GetGuildConfig(i.GuildID)
cfg.FallbackChannel = channel.ID
// save
err := cfg.Save()
if err != nil {
logger.Alert(
"commands/config.go - Saving config",
err.Error(),
"guild_id",
i.GuildID,
"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("Salon enregistré.").Send()
}
if err != nil {
logger.Alert("commands/config.go - Channel saved message", err.Error())
}
}
func ConfigPeriodBeforeReduce(s *discordgo.Session, i *discordgo.InteractionCreate, optMap cmd.OptionMap, resp *cmd.ResponseBuilder) {
resp.IsEphemeral()
// verify every args