From 3c3afe7bb1732786328625d3fdf16d23cf62b7f4 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Thu, 5 Sep 2024 23:58:46 -0400 Subject: [PATCH 01/14] Passed in original interaction to addMemberRole() --- commands/slash/member.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 40c88ae..e2161a1 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -872,6 +872,7 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us message := <-verifyChan i = <-interactionCreateChan + orginalInteraction := i err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseUpdateMessage, @@ -922,6 +923,7 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us memberChan <- "alumni" interactionCreateChan <- i } + defer delete(*ComponentHandlers, alumniSlug) (*ComponentHandlers)[denySlug] = func(s *discordgo.Session, i *discordgo.InteractionCreate) { memberChan <- "deny" @@ -1034,7 +1036,7 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us switch memberType { case "member": - err = addMemberRole(s, i, userEmail, attempts, false, span.Context()) + err = addMemberRole(s, orginalInteraction, userEmail, attempts, false, span.Context()) if err != nil { logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err}) return From b80f6a25bb51a8e073081720b650bbabefa76f4a Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 00:16:33 -0400 Subject: [PATCH 02/14] Passed in original interaction to addMemberRole() part 2 --- commands/slash/member.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index e2161a1..7ba4d61 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -870,9 +870,10 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us return } + originalInteraction := i + message := <-verifyChan i = <-interactionCreateChan - orginalInteraction := i err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseUpdateMessage, @@ -1036,7 +1037,7 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us switch memberType { case "member": - err = addMemberRole(s, orginalInteraction, userEmail, attempts, false, span.Context()) + err = addMemberRole(s, originalInteraction, userEmail, attempts, false, span.Context()) if err != nil { logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err}) return From 0d3fe7c4db31af3eb94f8c32aa2d39744fdcba3d Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 00:35:59 -0400 Subject: [PATCH 03/14] removed firstmessage parameter for addMemberRole() --- commands/slash/member.go | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 7ba4d61..a26d238 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -56,7 +56,7 @@ func Member() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *disc // check if user is already a member if data.User.IsVerified(i.Member.User.ID, span.Context()) { - err := addMemberRole(s, i, "", 0, true, span.Context()) + err := addMemberRole(s, i, "", 0, span.Context()) if err != nil { logging.Error(s, err.Error(), i.Member.User, span, logrus.Fields{"error": err}) return @@ -170,7 +170,7 @@ func Member() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *disc } // add member role - err = addMemberRole(s, i, userEmail, attempts, false, span.Context()) + err = addMemberRole(s, i, userEmail, attempts, span.Context()) if err != nil { logging.Error(s, err.Error(), originalInteraction.Member.User, span, logrus.Fields{"error": err}) return @@ -348,7 +348,7 @@ func emailInUse(s *discordgo.Session, i *discordgo.InteractionCreate, userEmail } // addMemberRole adds the member role to the user and marks them as verified -func addMemberRole(s *discordgo.Session, i *discordgo.InteractionCreate, userEmail string, attempts int, firstMessage bool, ctx ddtrace.SpanContext) error { +func addMemberRole(s *discordgo.Session, i *discordgo.InteractionCreate, userEmail string, attempts int, ctx ddtrace.SpanContext) error { span := tracer.StartSpan( "commands.slash.member:addMemberRole", tracer.ResourceName("/member:addMemberRole"), @@ -375,22 +375,24 @@ func addMemberRole(s *discordgo.Session, i *discordgo.InteractionCreate, userEma } logging.Debug(s, fmt.Sprintf("User successfully verified:\n Email:`%v`\nAttempts:`%d`", userEmail, attempts), i.Member.User, span) - if firstMessage { - return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Flags: discordgo.MessageFlagsEphemeral, - Content: "You have been verified as a member of RITSEC. Welcome!", - }, - }) - } else { - return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseUpdateMessage, - Data: &discordgo.InteractionResponseData{ - Content: "You have been verified as a member of RITSEC. Welcome!", - }, - }) - } + + // if firstMessage { + // return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + // Type: discordgo.InteractionResponseChannelMessageWithSource, + // Data: &discordgo.InteractionResponseData{ + // Flags: discordgo.MessageFlagsEphemeral, + // Content: "You have been verified as a member of RITSEC. Welcome!", + // }, + // }) + // } else { + // return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + // Type: discordgo.InteractionResponseUpdateMessage, + // Data: &discordgo.InteractionResponseData{ + // Content: "You have been verified as a member of RITSEC. Welcome!", + // }, + // }) + // } + return nil } // getVerificationCode sends the user a verification code and waits for them to respond with it @@ -1037,7 +1039,7 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us switch memberType { case "member": - err = addMemberRole(s, originalInteraction, userEmail, attempts, false, span.Context()) + err = addMemberRole(s, originalInteraction, userEmail, attempts, span.Context()) if err != nil { logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err}) return From 6fd625abbdf2de5b3caf4bfa043bb5c6fcb1726a Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 00:55:32 -0400 Subject: [PATCH 04/14] Added follow up message --- commands/slash/member.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commands/slash/member.go b/commands/slash/member.go index a26d238..003906e 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -1050,6 +1050,15 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err}) return } + + msg := "You have been verified as a member of RITSEC. Welcome!" + _, err = s.InteractionResponseEdit(originalInteraction.Interaction, &discordgo.WebhookEdit{ + Content: &msg, + }) + if err != nil { + logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err}) + return + } case "external": err = s.GuildMemberRoleAdd(i.GuildID, user.ID, externalRole) if err != nil { From 0051b463cb3026ab789784b3f80558621698c827 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 01:13:39 -0400 Subject: [PATCH 05/14] Added an interactionRespond to properly close the input/verify screen --- commands/slash/member.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commands/slash/member.go b/commands/slash/member.go index 003906e..08001ec 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -449,6 +449,16 @@ func getVerificationCode(s *discordgo.Session, i *discordgo.InteractionCreate, c 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 } From 729b3acdeffe12891012092eb02d71c089446c76 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 11:54:20 -0400 Subject: [PATCH 06/14] changed content --- commands/slash/member.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 08001ec..896ea29 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -375,23 +375,6 @@ func addMemberRole(s *discordgo.Session, i *discordgo.InteractionCreate, userEma } logging.Debug(s, fmt.Sprintf("User successfully verified:\n Email:`%v`\nAttempts:`%d`", userEmail, attempts), i.Member.User, span) - - // if firstMessage { - // return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - // Type: discordgo.InteractionResponseChannelMessageWithSource, - // Data: &discordgo.InteractionResponseData{ - // Flags: discordgo.MessageFlagsEphemeral, - // Content: "You have been verified as a member of RITSEC. Welcome!", - // }, - // }) - // } else { - // return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - // Type: discordgo.InteractionResponseUpdateMessage, - // Data: &discordgo.InteractionResponseData{ - // Content: "You have been verified as a member of RITSEC. Welcome!", - // }, - // }) - // } return nil } @@ -495,7 +478,7 @@ func recievedEmail(s *discordgo.Session, i *discordgo.InteractionCreate, userEma err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseUpdateMessage, Data: &discordgo.InteractionResponseData{ - Content: "A verification code has been sent to \"" + userEmail + "\". This could take up to 10 minutes. **Do not close discord or this window will be closed**.", + Content: "A verification code has been sent to \"" + userEmail + "\". This could take up to 10 minutes and could be in your spam. Please check your spam! **Do not close discord or this window will be closed**.", Components: []discordgo.MessageComponent{ discordgo.ActionsRow{ Components: []discordgo.MessageComponent{ From 6b71e1f4b8fd5f9a4db5d6929233792932ac8197 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 18:27:01 -0400 Subject: [PATCH 07/14] Added a debug message for when initialization is done --- commands/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/main.go b/commands/main.go index 4e22eec..83b1974 100644 --- a/commands/main.go +++ b/commands/main.go @@ -58,6 +58,7 @@ func Init(ctx ddtrace.SpanContext) { // Attach events to bot addSlashCommands(span.Context()) addHandlers(span.Context()) + logging.Debug(bot.Session, "Finished init", nil, span) } // addSlashCommands adds all slash commands to the bot From 43aeb0e7707ec03f2c79eab9ba57c0d463157c58 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 18:27:22 -0400 Subject: [PATCH 08/14] preserved the original interaction through verification code part --- commands/slash/member.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 896ea29..9170bd9 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -170,7 +170,7 @@ func Member() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *disc } // add member role - err = addMemberRole(s, i, userEmail, attempts, span.Context()) + err = addMemberRole(s, originalInteraction, userEmail, attempts, span.Context()) if err != nil { logging.Error(s, err.Error(), originalInteraction.Member.User, span, logrus.Fields{"error": err}) return From d5aa0a57423a3ebd19a6cb150bb75ee2e4f8db17 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 18:48:09 -0400 Subject: [PATCH 09/14] debug message after finish init --- commands/main.go | 1 - main.go | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/main.go b/commands/main.go index 83b1974..4e22eec 100644 --- a/commands/main.go +++ b/commands/main.go @@ -58,7 +58,6 @@ func Init(ctx ddtrace.SpanContext) { // Attach events to bot addSlashCommands(span.Context()) addHandlers(span.Context()) - logging.Debug(bot.Session, "Finished init", nil, span) } // addSlashCommands adds all slash commands to the bot diff --git a/main.go b/main.go index 02720c2..7b68bf6 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,8 @@ func main() { // start scheduled tasks commands.StartScheduledTasks(span.Context()) + logging.Debug(bot.Session, "Finished init", nil, span) + // create stop channel stop := make(chan os.Signal, 1) signal.Notify(stop, os.Interrupt) From f6c6e3c99117480b2d78fa6802433a557309d744 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 18:55:48 -0400 Subject: [PATCH 10/14] email veriification feedback --- commands/slash/member.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commands/slash/member.go b/commands/slash/member.go index 9170bd9..341aa78 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -176,6 +176,15 @@ func Member() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *disc return } + msg := "You have been verified as a member of RITSEC. Welcome!" + _, err = s.InteractionResponseEdit(originalInteraction.Interaction, &discordgo.WebhookEdit{ + Content: &msg, + }) + if err != nil { + logging.Error(s, err.Error(), originalInteraction.User, span, logrus.Fields{"error": err}) + return + } + } else { manualVerification(s, i, userEmail, attempts, span.Context()) return From 4f4940cef1b0b63df7ea1e1612bf2faf57dadb88 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 19:57:03 -0400 Subject: [PATCH 11/14] 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 From 0860b009ece6203100ce58ad4f2037a8fa1c58cd Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Fri, 6 Sep 2024 20:00:12 -0400 Subject: [PATCH 12/14] revert --- commands/slash/member.go | 50 +++++++++++----------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 981d681..341aa78 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -4,7 +4,6 @@ import ( "fmt" "regexp" "strings" - "time" "github.com/bwmarrin/discordgo" "github.com/google/uuid" @@ -404,14 +403,11 @@ 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 } @@ -442,38 +438,20 @@ 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 - // } - - // 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") - } + 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 } // recievedEmail will prompt a user to check if they recieved an email From b4746d6194d8af910b8b48ffa4b72cf4d799c4a8 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Sat, 7 Sep 2024 17:47:36 -0400 Subject: [PATCH 13/14] Revert "revert" This reverts commit 0860b009ece6203100ce58ad4f2037a8fa1c58cd. --- 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 From 98a1fd3ddac1953b6940a29960c981f8f412e4c0 Mon Sep 17 00:00:00 2001 From: Lukas Peters Date: Sat, 7 Sep 2024 17:47:45 -0400 Subject: [PATCH 14/14] Revert "attempt of looping interaction if user closes the input" This reverts commit 4f4940cef1b0b63df7ea1e1612bf2faf57dadb88. --- commands/slash/member.go | 50 +++++++++++----------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/commands/slash/member.go b/commands/slash/member.go index 981d681..341aa78 100644 --- a/commands/slash/member.go +++ b/commands/slash/member.go @@ -4,7 +4,6 @@ import ( "fmt" "regexp" "strings" - "time" "github.com/bwmarrin/discordgo" "github.com/google/uuid" @@ -404,14 +403,11 @@ 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 } @@ -442,38 +438,20 @@ 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 - // } - - // 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") - } + 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 } // recievedEmail will prompt a user to check if they recieved an email