feat(gokord): use new component lib
This commit is contained in:
parent
5a8da1eaeb
commit
0cd725108c
3 changed files with 74 additions and 82 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
"github.com/anhgelus/gokord/cmd"
|
"github.com/anhgelus/gokord/cmd"
|
||||||
|
"github.com/anhgelus/gokord/component"
|
||||||
"github.com/anhgelus/gokord/logger"
|
"github.com/anhgelus/gokord/logger"
|
||||||
"github.com/anhgelus/les-copaings-bot/config"
|
"github.com/anhgelus/les-copaings-bot/config"
|
||||||
"github.com/anhgelus/les-copaings-bot/exp"
|
"github.com/anhgelus/les-copaings-bot/exp"
|
||||||
|
@ -34,7 +35,7 @@ var (
|
||||||
configModifyMap = map[string]uint{}
|
configModifyMap = map[string]uint{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Config(s *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) {
|
func Config(_ *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) {
|
||||||
cfg := config.GetGuildConfig(i.GuildID)
|
cfg := config.GetGuildConfig(i.GuildID)
|
||||||
roles := ""
|
roles := ""
|
||||||
l := len(cfg.XpRoles) - 1
|
l := len(cfg.XpRoles) - 1
|
||||||
|
@ -93,40 +94,30 @@ func Config(s *discordgo.Session, i *discordgo.InteractionCreate, _ cmd.OptionMa
|
||||||
Inline: false,
|
Inline: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{
|
}).SetComponents(component.New().Add(new(component.ActionRow).Add(
|
||||||
discordgo.SelectMenu{
|
new(component.StringSelect).SetPlaceholder("Modifier...").
|
||||||
MenuType: discordgo.StringSelectMenu,
|
AddOption(
|
||||||
CustomID: ConfigModify,
|
component.NewSelectOption("Rôles liés à l'XP", ConfigModifyXpRole).
|
||||||
Placeholder: "Modifier...",
|
SetDescription("Gère les rôles liés à l'XP").
|
||||||
Options: []discordgo.SelectMenuOption{
|
SetEmoji(&discordgo.ComponentEmoji{Name: "🏅"}),
|
||||||
{
|
).
|
||||||
Label: "Rôles liés à l'XP",
|
AddOption(
|
||||||
Value: ConfigModifyXpRole,
|
component.NewSelectOption("Salons désactivés", ConfigModifyDisChannel).
|
||||||
Description: "Gère les rôles liés à l'XP",
|
SetDescription("Gère les salons désactivés").
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "🏅"},
|
SetEmoji(&discordgo.ComponentEmoji{Name: "❌"}),
|
||||||
},
|
).
|
||||||
{
|
AddOption(
|
||||||
Label: "Salons désactivés",
|
component.NewSelectOption("Salons de repli", ConfigModifyFallbackChannel). // I don't have a better idea for this...
|
||||||
Value: ConfigModifyDisChannel,
|
SetDescription("Spécifie le salon de repli").
|
||||||
Description: "Gère les salons désactivés",
|
SetEmoji(&discordgo.ComponentEmoji{Name: "💾"}),
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "❌"},
|
).
|
||||||
},
|
AddOption(
|
||||||
{
|
component.NewSelectOption("Temps avec la réduction", ConfigModifyTimeReduce).
|
||||||
Label: "Salons de repli", // I don't have a better idea for this...
|
SetDescription("Gère le temps avant la réduction d'XP").
|
||||||
Value: ConfigModifyFallbackChannel,
|
SetEmoji(&discordgo.ComponentEmoji{Name: "⌛"}),
|
||||||
Description: "Spécifie le salon de repli",
|
).
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "💾"},
|
SetCustomID(ConfigModify),
|
||||||
},
|
))).IsEphemeral().Send()
|
||||||
{
|
|
||||||
Label: "Temps avec la réduction",
|
|
||||||
Value: ConfigModifyTimeReduce,
|
|
||||||
Description: "Gère le temps avant la réduction d'XP",
|
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "⌛"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Disabled: false,
|
|
||||||
},
|
|
||||||
}}).IsEphemeral().Send()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Alert("config/guild.go - Sending config", err.Error())
|
logger.Alert("config/guild.go - Sending config", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -146,33 +137,25 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
case ConfigModifyXpRole:
|
case ConfigModifyXpRole:
|
||||||
err := resp.IsEphemeral().
|
err := resp.IsEphemeral().
|
||||||
SetMessage("Action à réaliser").
|
SetMessage("Action à réaliser").
|
||||||
AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{
|
SetComponents(component.New().Add(new(component.ActionRow).Add(
|
||||||
discordgo.SelectMenu{
|
new(component.StringSelect).SetPlaceholder("Action").
|
||||||
MenuType: discordgo.StringSelectMenu,
|
AddOption(
|
||||||
CustomID: ConfigModify,
|
component.NewSelectOption("Ajouter", XpRoleAdd).
|
||||||
Placeholder: "Action",
|
SetDescription("Ajouter un rôle à XP").
|
||||||
Options: []discordgo.SelectMenuOption{
|
SetEmoji(&discordgo.ComponentEmoji{Name: "⬆️"}),
|
||||||
{
|
).
|
||||||
Label: "Ajouter",
|
AddOption(
|
||||||
Value: XpRoleAdd,
|
component.NewSelectOption("Modifier", XpRoleEdit).
|
||||||
Description: "Ajouter un rôle à XP",
|
SetDescription("Modifier un rôle à XP").
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "⬆️"},
|
SetEmoji(&discordgo.ComponentEmoji{Name: "📝"}),
|
||||||
},
|
).
|
||||||
{
|
AddOption(
|
||||||
Label: "Supprimer",
|
component.NewSelectOption("Supprimer", XpRoleDel).
|
||||||
Value: XpRoleDel,
|
SetDescription("Supprimer un rôle à XP").
|
||||||
Description: "Supprimer un rôle à XP",
|
SetEmoji(&discordgo.ComponentEmoji{Name: "❌"}),
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "❌"},
|
).
|
||||||
},
|
SetCustomID(ConfigModify),
|
||||||
{
|
))).Send()
|
||||||
Label: "Modifier",
|
|
||||||
Value: XpRoleEdit,
|
|
||||||
Description: "Modifier un rôle à XP",
|
|
||||||
Emoji: &discordgo.ComponentEmoji{Name: "📝"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}).Send()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Alert("config/guild.go - Sending config", err.Error())
|
logger.Alert("config/guild.go - Sending config", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -181,19 +164,28 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
if msgData.CustomID == XpRoleEdit {
|
if msgData.CustomID == XpRoleEdit {
|
||||||
cID = XpRoleEditLevel
|
cID = XpRoleEditLevel
|
||||||
}
|
}
|
||||||
|
component.New().ForModal().Add(new(component.ActionRow).Add(
|
||||||
|
new(component.TextInput).
|
||||||
|
SetLabel("Niveau").
|
||||||
|
SetPlaceholder("5").
|
||||||
|
IsRequired().
|
||||||
|
SetMinLength(0).
|
||||||
|
SetMaxLength(5).
|
||||||
|
SetStyle(discordgo.TextInputShort).
|
||||||
|
SetCustomID(cID),
|
||||||
|
))
|
||||||
err := resp.IsModal().
|
err := resp.IsModal().
|
||||||
SetTitle("Role").
|
SetTitle("Role").
|
||||||
AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{
|
SetComponents(component.New().ForModal().Add(new(component.ActionRow).Add(
|
||||||
discordgo.TextInput{
|
new(component.TextInput).
|
||||||
CustomID: cID,
|
SetLabel("Niveau").
|
||||||
Label: "Niveau",
|
SetPlaceholder("5").
|
||||||
Style: discordgo.TextInputShort,
|
IsRequired().
|
||||||
Placeholder: "5",
|
SetMinLength(0).
|
||||||
Required: true,
|
SetMaxLength(5).
|
||||||
MinLength: 0,
|
SetStyle(discordgo.TextInputShort).
|
||||||
MaxLength: 5,
|
SetCustomID(cID),
|
||||||
},
|
))).
|
||||||
}}).
|
|
||||||
Send()
|
Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Alert("config/guild.go - Sending modal to add", err.Error())
|
logger.Alert("config/guild.go - Sending modal to add", err.Error())
|
||||||
|
@ -253,10 +245,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
case XpRoleDel:
|
case XpRoleDel:
|
||||||
err := resp.IsEphemeral().
|
err := resp.IsEphemeral().
|
||||||
SetMessage("Rôle à supprimer").
|
SetMessage("Rôle à supprimer").
|
||||||
AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{discordgo.SelectMenu{
|
SetComponents(component.New().Add(new(component.ActionRow).Add(new(component.RoleSelect).SetCustomID(XpRoleDelRole)))).
|
||||||
MenuType: discordgo.RoleSelectMenu,
|
|
||||||
CustomID: XpRoleDelRole,
|
|
||||||
}}}).
|
|
||||||
Send()
|
Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Alert("config/guild.go - Sending response to del", err.Error())
|
logger.Alert("config/guild.go - Sending response to del", err.Error())
|
||||||
|
@ -332,10 +321,7 @@ func ConfigXPModal(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
|
||||||
err = resp.IsEphemeral().
|
err = resp.IsEphemeral().
|
||||||
SetMessage("Rôle à supprimer").
|
SetMessage("Rôle à supprimer").
|
||||||
AddComponent(discordgo.ActionsRow{Components: []discordgo.MessageComponent{discordgo.SelectMenu{
|
SetComponents(component.New().Add(new(component.ActionRow).Add(new(component.RoleSelect).SetCustomID(cID)))).
|
||||||
MenuType: discordgo.RoleSelectMenu,
|
|
||||||
CustomID: cID,
|
|
||||||
}}}).
|
|
||||||
Send()
|
Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Alert("config/guild.go - Sending response to add/edit", err.Error())
|
logger.Alert("config/guild.go - Sending response to add/edit", err.Error())
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module github.com/anhgelus/les-copaings-bot
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1
|
github.com/anhgelus/gokord v0.11.1-0.20250806004311-9988b375047f
|
||||||
github.com/bwmarrin/discordgo v0.29.0
|
github.com/bwmarrin/discordgo v0.29.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4
|
github.com/pelletier/go-toml/v2 v2.2.4
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -1,5 +1,11 @@
|
||||||
github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1 h1:irHDC/xUm65yLFx5HnVeCbM0qQRpm0i1vQHsyLXeEbo=
|
github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1 h1:irHDC/xUm65yLFx5HnVeCbM0qQRpm0i1vQHsyLXeEbo=
|
||||||
github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k=
|
github.com/anhgelus/gokord v0.11.1-0.20250806000243-ddfebe2ca6f1/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k=
|
||||||
|
github.com/anhgelus/gokord v0.11.1-0.20250806003339-90cf89cde031 h1:56vqHQzCHCcMeBBhAWUyC466BETAhaIl1Qiq93WdrYI=
|
||||||
|
github.com/anhgelus/gokord v0.11.1-0.20250806003339-90cf89cde031/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k=
|
||||||
|
github.com/anhgelus/gokord v0.11.1-0.20250806003704-21a4238c64a0 h1:Jj4ja4bshyEHOd+stqqB4e0iuggtDx/hzZ8K69+rtsE=
|
||||||
|
github.com/anhgelus/gokord v0.11.1-0.20250806003704-21a4238c64a0/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k=
|
||||||
|
github.com/anhgelus/gokord v0.11.1-0.20250806004311-9988b375047f h1:OSTlmWDVRGw3bt4uHOBFyUWNNl5VV3zaB6Xj0TWlY0s=
|
||||||
|
github.com/anhgelus/gokord v0.11.1-0.20250806004311-9988b375047f/go.mod h1:4xpwLzIG34/XG9QZiPsnYScQhckiCpQMAI0CjP0Nc2k=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue