Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed /member not giving Member role and added more response messages #137

Merged
merged 15 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions commands/slash/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,12 +170,21 @@ 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, originalInteraction, userEmail, attempts, span.Context())
if err != nil {
logging.Error(s, err.Error(), originalInteraction.Member.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(), originalInteraction.User, span, logrus.Fields{"error": err})
return
}

} else {
manualVerification(s, i, userEmail, attempts, span.Context())
return
Expand Down Expand Up @@ -348,7 +357,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"),
Expand All @@ -375,22 +384,7 @@ 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
}

// getVerificationCode sends the user a verification code and waits for them to respond with it
Expand Down Expand Up @@ -447,6 +441,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
}

Expand Down Expand Up @@ -483,7 +487,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{
Expand Down Expand Up @@ -870,6 +874,8 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
return
}

originalInteraction := i

message := <-verifyChan
i = <-interactionCreateChan

Expand Down Expand Up @@ -922,6 +928,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"
Expand Down Expand Up @@ -1034,7 +1041,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, originalInteraction, userEmail, attempts, span.Context())
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
Expand All @@ -1045,6 +1052,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 {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading