mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-10 00:08:09 -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"
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -19,6 +19,9 @@ var (
|
|||||||
"register": RegisterCommandHandler,
|
"register": RegisterCommandHandler,
|
||||||
"code": CodeCommandHandler,
|
"code": CodeCommandHandler,
|
||||||
}
|
}
|
||||||
|
modalHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||||
|
"register": RegisterModalHandler,
|
||||||
|
}
|
||||||
db *redis.Client
|
db *redis.Client
|
||||||
debugFlag = flag.Bool("debug", false, "Enable debug logging")
|
debugFlag = flag.Bool("debug", false, "Enable debug logging")
|
||||||
)
|
)
|
||||||
@@ -71,18 +74,12 @@ func Bot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case discordgo.InteractionModalSubmit:
|
case discordgo.InteractionModalSubmit:
|
||||||
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
id := interaction.ModalSubmitData().CustomID
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
handlerId := id[:strings.Index(id, ":")]
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Content: "Registration data received. Please wait while your vehicle is registered.",
|
if handler, ok := modalHandlers[handlerId]; ok {
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
handler(internalSession, interaction)
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
data := interaction.ModalSubmitData()
|
|
||||||
spew.Dump(data)
|
|
||||||
|
|
||||||
// if !strings.HasPrefix(data.CustomID, "modals_survey") {
|
// if !strings.HasPrefix(data.CustomID, "modals_survey") {
|
||||||
// return
|
// 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