-
Notifications
You must be signed in to change notification settings - Fork 3
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
Attendance Command #142
Open
oms125
wants to merge
11
commits into
main
Choose a base branch
from
96-new-slash-command-to-check-how-many-sign-ins-you-have
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Attendance Command #142
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b3c7da3
Signins command framework
oms125 b61e511
moved command to new file
oms125 adcde2f
changed name to attendance to alleviate confusion
oms125 2d7136e
attendance message function created
oms125 1e638e8
arr
oms125 0c64475
attendanceMessage
oms125 625ab38
attendance
oms125 3bfd2d3
comma
oms125 1bb0654
still fixing
oms125 2f30af6
attendance
oms125 d5711a7
enabled
oms125 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package slash | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/ritsec/ops-bot-iii/commands/slash/permission" | ||
"github.com/ritsec/ops-bot-iii/data" | ||
"github.com/ritsec/ops-bot-iii/ent/signin" | ||
"github.com/ritsec/ops-bot-iii/logging" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" | ||
) | ||
|
||
//Attendance slash command | ||
func Attendance() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *discordgo.InteractionCreate)) { | ||
return &discordgo.ApplicationCommand { | ||
Name: "attendance", | ||
Description: "Get signin history", | ||
DefaultMemberPermissions: &permission.Member, | ||
}, | ||
func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
span := tracer.StartSpan( | ||
"commands.slash.attendance:Attendance", | ||
tracer.ResourceName("/attendance"), | ||
) | ||
defer span.Finish() | ||
|
||
logging.Debug(s, "Attendance command received", i.Member.User, span) | ||
|
||
err := s.InteractionRespond( | ||
i.Interaction, | ||
&discordgo.InteractionResponse { | ||
Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
Data: &discordgo.InteractionResponseData { | ||
Content: attendanceMessage(i.Member.User.ID, span.Context()), | ||
Flags: discordgo.MessageFlagsEphemeral, | ||
}, | ||
}, | ||
) | ||
if err != nil { | ||
logging.Error(s, err.Error(), i.Member.User, span) | ||
} else { | ||
logging.Debug(s, "Signin History Given", i.Member.User, span) | ||
} | ||
} | ||
} | ||
|
||
//returns the message sent to the user by the Attendance command | ||
func attendanceMessage(userID string, ctx ddtrace.SpanContext) (message string) { | ||
span := tracer.StartSpan( | ||
"commands.slash.attendance:attendanceMessage", | ||
tracer.ResourceName("/attendance:attendanceMessage"), | ||
tracer.ChildOf(ctx), | ||
) | ||
defer span.Finish() | ||
|
||
message = "**Your Signins:**" | ||
signinTypes := [...]string{ | ||
"General Meeting", | ||
"Contagion", | ||
"IR", | ||
"Ops", | ||
"Ops IG", | ||
"Red Team", | ||
"Red Team Recruiting", | ||
"RVAPT", | ||
"Reversing", | ||
"Physical", | ||
"Wireless", | ||
"WiCyS", | ||
"Vulnerability Research", | ||
"Mentorship", | ||
"Other", | ||
} | ||
|
||
totalSignins, err := data.Signin.GetSignins(userID, span.Context()) | ||
if err != nil { | ||
logging.Error(nil, err.Error(), nil, span) | ||
totalSignins = 0 | ||
} | ||
message += fmt.Sprintf("\n\tTotal Signins: `%d`", totalSignins) | ||
|
||
for _, signinType := range signinTypes { | ||
var entSigninType signin.Type | ||
switch signinType { | ||
case "General Meeting": | ||
entSigninType = signin.TypeGeneralMeeting | ||
case "Contagion": | ||
entSigninType = signin.TypeContagion | ||
case "IR": | ||
entSigninType = signin.TypeIR | ||
case "Ops": | ||
entSigninType = signin.TypeOps | ||
case "Ops IG": | ||
entSigninType = signin.TypeOpsIG | ||
case "Red Team": | ||
entSigninType = signin.TypeRedTeam | ||
case "Red Team Recruiting": | ||
entSigninType = signin.TypeRedTeamRecruiting | ||
case "RVAPT": | ||
entSigninType = signin.TypeRVAPT | ||
case "Reversing": | ||
entSigninType = signin.TypeReversing | ||
case "Physical": | ||
entSigninType = signin.TypePhysical | ||
case "Wireless": | ||
entSigninType = signin.TypeWireless | ||
case "WiCyS": | ||
entSigninType = signin.TypeWiCyS | ||
case "Vulnerability Research": | ||
entSigninType = signin.TypeVulnerabilityResearch | ||
case "Mentorship": | ||
entSigninType = signin.TypeMentorship | ||
case "Other": | ||
entSigninType = signin.TypeOther | ||
} | ||
signins, err := data.Signin.GetSigninsByType(userID, entSigninType, span.Context()) | ||
if err != nil { | ||
logging.Error(nil, err.Error(), nil, span) | ||
signins = 0 | ||
} | ||
if signins != 0 { | ||
message += fmt.Sprintf("\n\t%s: `%d`", signinType, signins) | ||
} | ||
} | ||
|
||
return message | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c0untingNumbers I'll pass it for this PR but just as a heads up, I noticed in a few other places we're hard coding the signin types as a string and putting it through a giant switch statement. I'll make an issue about it but could you look into refactoring this?
Ideally, we'd declare both in one place with a simple helper function which can then be called everywhere else (or something along these lines). Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea. Will put that up for an issue.