feat(config): fallback channel

This commit is contained in:
Anhgelus Morhtuuzh 2024-04-15 16:56:01 +02:00
parent a8c0a395ac
commit 2b285f4523
No known key found for this signature in database
GPG key ID: CF4550297832A29F
3 changed files with 48 additions and 1 deletions

View file

@ -43,6 +43,11 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
Description: "Configuration",
Color: utils.Success,
Fields: []*discordgo.MessageEmbedField{
{
Name: "Salons par défaut",
Value: fmt.Sprintf("<#%s>", cfg.FallbackChannel),
Inline: false,
},
{
Name: "Rôles liés aux niveaux",
Value: roles,
@ -172,7 +177,7 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
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())
utils.SendAlert("commands/config.go - Channel not set (disabled)", err.Error())
}
return
}
@ -211,3 +216,34 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
utils.SendAlert("commands/config.go - Modification saved message", err.Error())
}
}
func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
optMap := utils.GenerateOptionMapForSubcommand(i)
resp := utils.ResponseBuilder{C: s, I: i}
resp.IsEphemeral()
// verify every args
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 (fallback)", err.Error())
}
return
}
channel := salon.ChannelValue(s)
if channel.Type != discordgo.ChannelTypeGuildText {
err := resp.Message("Le salon n'est pas un salon textuel.").Send()
if err != nil {
utils.SendAlert("commands/config.go - Invalid channel type", err.Error())
}
return
}
cfg := config.GetGuildConfig(i.GuildID)
cfg.FallbackChannel = channel.ID
// save
cfg.Save()
err := resp.Message("Salon enregistré.").Send()
if err != nil {
utils.SendAlert("commands/config.go - Channel saved message", err.Error())
}
}

View file

@ -11,6 +11,7 @@ type GuildConfig struct {
GuildID string `gorm:"not null"`
XpRoles []XpRole
DisabledChannels string
FallbackChannel string
}
type XpRole struct {

10
main.go
View file

@ -82,6 +82,16 @@ func main() {
"Salon à modifier",
).IsRequired()).
SetHandler(commands.ConfigChannel),
).
AddSub(
gokord.NewCommand("fallback-channel", "Modifie le salon textuel par défaut").
HasOption().
AddOption(gokord.NewOption(
discordgo.ApplicationCommandOptionChannel,
"channel",
"Salon textuel par défaut",
).IsRequired()).
SetHandler(commands.ConfigFallbackChannel),
)
bot := gokord.Bot{