mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-09 10:08:16 -06:00
Setup proper modal interaction handlers using CustomID string slice
This commit is contained in:
21
main.go
21
main.go
@@ -4,9 +4,9 @@ import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/joho/godotenv"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -19,6 +19,9 @@ var (
|
||||
"register": RegisterCommandHandler,
|
||||
"code": CodeCommandHandler,
|
||||
}
|
||||
modalHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"register": RegisterModalHandler,
|
||||
}
|
||||
db *redis.Client
|
||||
debugFlag = flag.Bool("debug", false, "Enable debug logging")
|
||||
)
|
||||
@@ -71,18 +74,12 @@ func Bot() {
|
||||
}
|
||||
|
||||
case discordgo.InteractionModalSubmit:
|
||||
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Registration data received. Please wait while your vehicle is registered.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
id := interaction.ModalSubmitData().CustomID
|
||||
handlerId := id[:strings.Index(id, ":")]
|
||||
|
||||
if handler, ok := modalHandlers[handlerId]; ok {
|
||||
handler(internalSession, interaction)
|
||||
}
|
||||
data := interaction.ModalSubmitData()
|
||||
spew.Dump(data)
|
||||
|
||||
// if !strings.HasPrefix(data.CustomID, "modals_survey") {
|
||||
// return
|
||||
|
||||
21
submit.go
Normal file
21
submit.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func RegisterModalHandler(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
|
||||
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Registration data received. Please wait while your vehicle is registered.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data := interaction.ModalSubmitData()
|
||||
spew.Dump(data)
|
||||
}
|
||||
Reference in New Issue
Block a user