refactor(command): use message component to edit config
This commit is contained in:
parent
977c818328
commit
b4408674c9
3 changed files with 59 additions and 65 deletions
|
@ -10,7 +10,15 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
||||
const (
|
||||
SelectConfigModify = "config_modify"
|
||||
SelectOptConfigXpRole = "xp_role"
|
||||
SelectOptConfigDisChannel = "disabled_channel"
|
||||
SelectOptConfigFallbackChannel = "fallback_channel"
|
||||
SelectOptConfigTimeReduce = "time_reduce"
|
||||
)
|
||||
|
||||
func Config(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
||||
cfg := config.GetGuildConfig(i.GuildID)
|
||||
roles := ""
|
||||
l := len(cfg.XpRoles) - 1
|
||||
|
@ -69,13 +77,46 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap uti
|
|||
Inline: false,
|
||||
},
|
||||
},
|
||||
}).Send()
|
||||
}).AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{
|
||||
discordgo.SelectMenu{
|
||||
MenuType: discordgo.StringSelectMenu,
|
||||
CustomID: SelectConfigModify,
|
||||
Placeholder: "Modifier...",
|
||||
Options: []discordgo.SelectMenuOption{
|
||||
{
|
||||
Label: "Rôles liés à l'XP",
|
||||
Value: SelectOptConfigXpRole,
|
||||
Description: "Gère les rôles liés à l'XP",
|
||||
Emoji: &discordgo.ComponentEmoji{Name: "🏅"},
|
||||
},
|
||||
{
|
||||
Label: "Salons désactivés",
|
||||
Value: SelectOptConfigDisChannel,
|
||||
Description: "Gère les salons désactivés",
|
||||
Emoji: &discordgo.ComponentEmoji{Name: "❌"},
|
||||
},
|
||||
{
|
||||
Label: "Salons de repli", // I don't have a better idea for this...
|
||||
Value: SelectOptConfigFallbackChannel,
|
||||
Description: "Spécifie le salon de repli",
|
||||
Emoji: &discordgo.ComponentEmoji{Name: "💾"},
|
||||
},
|
||||
{
|
||||
Label: "Temps avec la réduction",
|
||||
Value: SelectOptConfigTimeReduce,
|
||||
Description: "Gère le temps avant la réduction d'XP",
|
||||
Emoji: &discordgo.ComponentEmoji{Name: "⌛"},
|
||||
},
|
||||
},
|
||||
Disabled: false,
|
||||
},
|
||||
}}).IsEphemeral().Send()
|
||||
if err != nil {
|
||||
utils.SendAlert("config/guild.go - Sending config", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
||||
func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
resp.IsEphemeral()
|
||||
// verify every args
|
||||
t, ok := optMap["type"]
|
||||
|
|
67
main.go
67
main.go
|
@ -60,68 +60,8 @@ func main() {
|
|||
SetHandler(commands.Rank)
|
||||
|
||||
configCmd := gokord.NewCommand("config", "Modifie la config").
|
||||
ContainsSub().
|
||||
AddSub(
|
||||
gokord.NewCommand("show", "Affiche la config").SetHandler(commands.ConfigShow),
|
||||
).
|
||||
AddSub(
|
||||
gokord.NewCommand("xp", "Modifie l'xp").
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionString,
|
||||
"type",
|
||||
"Type d'action à effectuer",
|
||||
).
|
||||
AddChoice(gokord.NewChoice("Ajouter", "add")).
|
||||
AddChoice(gokord.NewChoice("Supprimer", "del")).
|
||||
AddChoice(gokord.NewChoice("Modifier", "edit")).IsRequired(),
|
||||
).
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionInteger,
|
||||
"level",
|
||||
"Niveau du rôle",
|
||||
).IsRequired()).
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionRole,
|
||||
"role",
|
||||
"Rôle",
|
||||
).IsRequired()).
|
||||
SetHandler(commands.ConfigXP),
|
||||
).
|
||||
AddSub(
|
||||
gokord.NewCommand("disabled-channels", "Modifie les salons désactivés").
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionString,
|
||||
"type",
|
||||
"Type d'action à effectuer",
|
||||
).
|
||||
AddChoice(gokord.NewChoice("Désactiver le salon", "add")).
|
||||
AddChoice(gokord.NewChoice("Activer le salon", "del")).IsRequired(),
|
||||
).
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionChannel,
|
||||
"channel",
|
||||
"Salon à modifier",
|
||||
).IsRequired()).
|
||||
SetHandler(commands.ConfigChannel),
|
||||
).
|
||||
AddSub(
|
||||
gokord.NewCommand("period-before-reduce", "Temps avant la perte d'xp (affecte aussi le /top)").
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionInteger,
|
||||
"days",
|
||||
"Nombre de jours avant la perte d'xp (doit être égal ou plus grand que 30)",
|
||||
).IsRequired()).
|
||||
SetHandler(commands.ConfigPeriodBeforeReduce),
|
||||
).
|
||||
AddSub(
|
||||
gokord.NewCommand("fallback-channel", "Modifie le salon textuel par défaut").
|
||||
AddOption(gokord.NewOption(
|
||||
discordgo.ApplicationCommandOptionChannel,
|
||||
"channel",
|
||||
"Salon textuel par défaut",
|
||||
).IsRequired()).
|
||||
SetHandler(commands.ConfigFallbackChannel),
|
||||
).SetPermission(&adm)
|
||||
SetPermission(&adm).
|
||||
SetHandler(commands.Config)
|
||||
|
||||
topCmd := gokord.NewCommand("top", "Copaings les plus actifs").
|
||||
SetHandler(commands.Top)
|
||||
|
@ -198,4 +138,7 @@ func afterInit(dg *discordgo.Session) {
|
|||
stopPeriodicReducer = utils.NewTimer(24*time.Hour, func(stop chan<- interface{}) {
|
||||
user.PeriodicReducer(dg)
|
||||
})
|
||||
|
||||
//interaction: /config
|
||||
dg.AddHandler(commands.ConfigXP)
|
||||
}
|
||||
|
|
10
updates.json
10
updates.json
|
@ -28,5 +28,15 @@
|
|||
"ping"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"version": "3.2.0",
|
||||
"commands": {
|
||||
"added": [],
|
||||
"removed": [],
|
||||
"updated": [
|
||||
"config"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue