From 4f4940cef1b0b63df7ea1e1612bf2faf57dadb88 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 19:57:03 -0400 Subject: [PATCH] attempt of looping interaction if user closes the input --- commands/slash/member.go | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 341aa78..981d681 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -4,6 +4,7 @@ import ( "fmt" "regexp" "strings" + "time" "github.com/bwmarrin/discordgo" "github.com/google/uuid" @@ -403,11 +404,14 @@ func getVerificationCode(s *discordgo.Session, i *discordgo.InteractionCreate, c verifyChan := make(chan string) defer close(verifyChan) + done := make(chan bool) + defer close(done) + verifySlug := uuid.New().String() (*ComponentHandlers)[verifySlug] = func(s *discordgo.Session, i *discordgo.InteractionCreate) { data := i.ModalSubmitData() - + done <- true verifyChan <- data.Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value interactionCreateChan <- i } @@ -438,20 +442,38 @@ func getVerificationCode(s *discordgo.Session, i *discordgo.InteractionCreate, c return "", nil, err } - verificationCode := <-verifyChan - i = <-interactionCreateChan - - err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseUpdateMessage, - Data: &discordgo.InteractionResponseData{ - Content: "Verification code received. Please wait while we verify...", - }, - }) - if err != nil { - return "", nil, err + // verificationCode := <-verifyChan + // i = <-interactionCreateChan + + // err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + // Type: discordgo.InteractionResponseUpdateMessage, + // Data: &discordgo.InteractionResponseData{ + // Content: "Verification code received. Please wait while we verify...", + // }, + // }) + // if err != nil { + // return "", nil, err + // } + + // return verificationCode, i, nil + for { + select { + case verificationCode := <-verifyChan: + i = <-interactionCreateChan + err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseUpdateMessage, + Data: &discordgo.InteractionResponseData{ + Content: "Verification code received. Please wait while we verify...", + }, + }) + if err != nil { + return "", nil, err + } + return verificationCode, i, nil + case <-time.After(1 * time.Minute): // Adjust timeout as needed + return "", nil, fmt.Errorf("interaction timed out") + } } - - return verificationCode, i, nil } // recievedEmail will prompt a user to check if they recieved an email