Skip to content

Commit

Permalink
attempt of looping interaction if user closes the input
Browse files Browse the repository at this point in the history
  • Loading branch information
c0untingNumbers committed Sep 6, 2024
1 parent f6c6e3c commit 4f4940c
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions commands/slash/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"strings"
"time"

"github.com/bwmarrin/discordgo"
"github.com/google/uuid"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4f4940c

Please sign in to comment.