Skip to content

Commit

Permalink
Merge pull request #130 from ritsec/127-more-detailed-audit-and-membe…
Browse files Browse the repository at this point in the history
…r-approval-details-logging

127 more detailed audit and member approval details logging
  • Loading branch information
c0untingNumbers authored Aug 21, 2024
2 parents 5b27bbd + 73b10f5 commit a9d6a29
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions commands/slash/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
"github.com/ritsec/ops-bot-iii/logging"
"github.com/ritsec/ops-bot-iii/mail"
"github.com/sirupsen/logrus"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

var (
// Channel ID of the member approval channel
// Channel ID of the member approval channel and history channel
memberApprovalChannel string = config.GetString("commands.member.channel_id")

// Role ID of the member role
Expand Down Expand Up @@ -926,9 +928,18 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
}
defer delete(*ComponentHandlers, denySlug)

author := &discordgo.MessageEmbedAuthor{}

if user != nil {
author.Name = user.Username
author.IconURL = user.AvatarURL("")
}

// Verification Request
m, err := s.ChannelMessageSendComplex(memberApprovalChannel, &discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Title: "Verification request",
Author: author,
Title: "Verification request",
Fields: []*discordgo.MessageEmbedField{
func() *discordgo.MessageEmbedField {
if userEmail == "" {
Expand All @@ -945,7 +956,7 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
}(),
{
Name: "Discord",
Value: user.Mention(),
Value: fmt.Sprintf("ID: %v, Name: %v", user.Mention(), user.Username),
},
{
Name: "Message",
Expand Down Expand Up @@ -1028,12 +1039,6 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
return
}

_, err = s.ChannelMessageSend(memberApprovalChannel, fmt.Sprintf("%v verified %v with Member role!", helpers.AtUser(i.Member.User.ID), user.Mention()))
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}

err = helpers.SendDirectMessage(s, user.ID, "You have been verified as a member of RITSEC. Welcome!", span.Context())
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
Expand All @@ -1046,12 +1051,6 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
return
}

_, err = s.ChannelMessageSend(memberApprovalChannel, fmt.Sprintf("%v verified %v with External role!", helpers.AtUser(i.Member.User.ID), user.Mention()))
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}

err = helpers.SendDirectMessage(s, user.ID, "You have been verified as an external member of RITSEC. Welcome!", span.Context())
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
Expand All @@ -1064,12 +1063,6 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
return
}

_, err = s.ChannelMessageSend(memberApprovalChannel, fmt.Sprintf("%v verified %v with Prospective role!", helpers.AtUser(i.Member.User.ID), user.Mention()))
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}

err = helpers.SendDirectMessage(s, user.ID, "You have been verified as a prospective member of RITSEC. Welcome!", span.Context())
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
Expand All @@ -1082,12 +1075,6 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
return
}

_, err = s.ChannelMessageSend(memberApprovalChannel, fmt.Sprintf("%v verified %v with Staff role!", helpers.AtUser(i.Member.User.ID), user.Mention()))
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}

err = helpers.SendDirectMessage(s, user.ID, "You have been verified as a staff member of RIT. Welcome!", span.Context())
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
Expand All @@ -1100,36 +1087,25 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
return
}

_, err = s.ChannelMessageSend(memberApprovalChannel, fmt.Sprintf("%v verified %v with Alumni role!", helpers.AtUser(i.Member.User.ID), user.Mention()))
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}

err = helpers.SendDirectMessage(s, user.ID, "You have been verified as an alumni of RITSEC. Welcome!", span.Context())
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}
case "deny":
_, err = s.ChannelMessageSend(memberApprovalChannel, fmt.Sprintf("%v denied %v!", helpers.AtUser(i.Member.User.ID), user.Mention()))
if err != nil {
logging.Error(s, err.Error(), user, span, logrus.Fields{"error": err})
return
}
}

// Delete the initial message and resend the initial message without the buttons

err = s.ChannelMessageDelete(memberApprovalChannel, m.ID)
if err != nil {
logging.Error(s, "Error encounted while deleting channel message", user, span, logrus.Fields{"error": err})
return
}

// Log the Verification Request
_, err = s.ChannelMessageSendComplex(memberApprovalChannel, &discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Title: "ARCHIVED RECORD OF THE Verification request",
Author: author,
Title: "Verification Request Log",
Fields: []*discordgo.MessageEmbedField{
func() *discordgo.MessageEmbedField {
if userEmail == "" {
Expand All @@ -1146,12 +1122,29 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
}(),
{
Name: "Discord",
Value: user.Mention(),
Value: fmt.Sprintf("ID: %v,\nUsername: %v\nClickable: %v", user.ID, user.Username, user.Mention()),
},
{
Name: "Message",
Value: message,
},
{
Name: "Role given",
Value: cases.Title(language.Und).String(memberType),
},
func() *discordgo.MessageEmbedField {
if memberType != "deny" {
return &discordgo.MessageEmbedField{
Name: "Approved by",
Value: helpers.AtUser(i.Member.User.ID),
}
} else {
return &discordgo.MessageEmbedField{
Name: "Denied by",
Value: helpers.AtUser(i.Member.User.ID),
}
}
}(),
},
},
})
Expand Down

0 comments on commit a9d6a29

Please sign in to comment.