feat(config): fallback channel
This commit is contained in:
parent
a8c0a395ac
commit
2b285f4523
3 changed files with 48 additions and 1 deletions
|
@ -43,6 +43,11 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
Description: "Configuration",
|
Description: "Configuration",
|
||||||
Color: utils.Success,
|
Color: utils.Success,
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
|
{
|
||||||
|
Name: "Salons par défaut",
|
||||||
|
Value: fmt.Sprintf("<#%s>", cfg.FallbackChannel),
|
||||||
|
Inline: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "Rôles liés aux niveaux",
|
Name: "Rôles liés aux niveaux",
|
||||||
Value: roles,
|
Value: roles,
|
||||||
|
@ -172,7 +177,7 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.Message("Le salon n'a pas été renseigné.").Send()
|
err := resp.Message("Le salon n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
@ -211,3 +216,34 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
utils.SendAlert("commands/config.go - Modification saved message", err.Error())
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ type GuildConfig struct {
|
||||||
GuildID string `gorm:"not null"`
|
GuildID string `gorm:"not null"`
|
||||||
XpRoles []XpRole
|
XpRoles []XpRole
|
||||||
DisabledChannels string
|
DisabledChannels string
|
||||||
|
FallbackChannel string
|
||||||
}
|
}
|
||||||
|
|
||||||
type XpRole struct {
|
type XpRole struct {
|
||||||
|
|
10
main.go
10
main.go
|
@ -82,6 +82,16 @@ func main() {
|
||||||
"Salon à modifier",
|
"Salon à modifier",
|
||||||
).IsRequired()).
|
).IsRequired()).
|
||||||
SetHandler(commands.ConfigChannel),
|
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{
|
bot := gokord.Bot{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue