Skip to content

Commit

Permalink
fixed remaining errors
Browse files Browse the repository at this point in the history
  • Loading branch information
1nv8rzim committed Aug 25, 2023
1 parent 7080326 commit ccb1116
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
4 changes: 2 additions & 2 deletions commands/scheduled/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func updateStatus(s *discordgo.Session, ctx ddtrace.SpanContext) {
weekday := now.Weekday()
hour := now.Hour()

rand.Seed(time.Now().UnixNano())
r := rand.New(rand.NewSource(time.Now().UnixNano()))

if weekday == time.Friday && hour >= 12 && hour < 16 {
err := s.UpdateStatusComplex(discordgo.UpdateStatusData{
Expand All @@ -49,7 +49,7 @@ func updateStatus(s *discordgo.Session, ctx ddtrace.SpanContext) {
} else {
err := s.UpdateStatusComplex(discordgo.UpdateStatusData{
Activities: []*discordgo.Activity{
&activities[rand.Intn(len(activities))],
&activities[r.Intn(len(activities))],
},
})
if err != nil {
Expand Down
27 changes: 22 additions & 5 deletions commands/slash/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ func Member() *structs.SlashCommand {
// check if userEmail is valid
if !validRITEmail(userEmail, span.Context()) {
logging.Debug(s, fmt.Sprintf("User has invalid RIT email: `%v`", userEmail), originalInteraction.Member.User, span)
invalidRITEmail(s, i, userEmail, attempts, span.Context())
err := invalidRITEmail(s, i, userEmail, attempts, span.Context())
if err != nil {
logging.Error(s, "", originalInteraction.Member.User, span, logrus.Fields{"error": err})
}
return
}

// check if email is already in use
if data.User.EmailExists(originalInteraction.Member.User.ID, userEmail, span.Context()) {
logging.Debug(s, fmt.Sprintf("User has already used email: `%v`", userEmail), originalInteraction.Member.User, span)
emailInUse(s, i, userEmail, attempts, span.Context())
err := emailInUse(s, i, userEmail, attempts, span.Context())
if err != nil {
logging.Error(s, err.Error(), originalInteraction.Member.User, span, logrus.Fields{"error": err})
}
return
}

Expand Down Expand Up @@ -156,7 +162,10 @@ func Member() *structs.SlashCommand {
// check code
if strings.TrimSpace(code) != strings.TrimSpace(verificationCode) {
logging.Debug(s, "User provided invalid verification code", originalInteraction.Member.User, span)
invalidCode(s, i, verificationCode, attempts, span.Context())
err := invalidCode(s, i, verificationCode, attempts, span.Context())
if err != nil {
logging.Error(s, err.Error(), originalInteraction.Member.User, span, logrus.Fields{"error": err})
}
return
}

Expand Down Expand Up @@ -962,7 +971,11 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us

switch memberType {
case "member":
addMemberRole(s, i, userEmail, attempts, false, span.Context())
err = addMemberRole(s, i, userEmail, attempts, false, span.Context())
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 Expand Up @@ -1013,5 +1026,9 @@ func manualVerification(s *discordgo.Session, i *discordgo.InteractionCreate, us
}
}

s.ChannelMessageDelete(memberApprovalChannel, m.ID)
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
}
}
5 changes: 4 additions & 1 deletion commands/slash/signin.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ func Signin() *structs.SlashCommand {

time.Sleep(3 * time.Hour)

s.InteractionResponseDelete(i.Interaction)
err = s.InteractionResponseDelete(i.Interaction)
if err != nil {
logging.Error(s, "Error encounted while deleting interaction response", i.Member.User, span, logrus.Fields{"error": err})
}
},
}
}
Expand Down
10 changes: 8 additions & 2 deletions commands/slash/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ func Usage() *structs.SlashCommand {

logging.Debug(s, "Usage command received", i.Member.User, span)

s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Calculating...",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
logging.Error(s, err.Error(), i.Member.User, span, logrus.Fields{"error": err})
}

memory, err := memory.Get()
if err != nil {
Expand All @@ -58,7 +61,7 @@ func Usage() *structs.SlashCommand {

empty := ""

s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &empty,
Embeds: &[]*discordgo.MessageEmbed{
{
Expand Down Expand Up @@ -88,6 +91,9 @@ func Usage() *structs.SlashCommand {
},
},
})
if err != nil {
logging.Error(s, err.Error(), i.Member.User, span, logrus.Fields{"error": err})
}
},
}
}
5 changes: 4 additions & 1 deletion commands/slash/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ func Vote() *structs.SlashCommand {
return
}

data.Vote.DeleteAll(voteSlug, span.Context())
_, err = data.Vote.DeleteAll(voteSlug, span.Context())
if err != nil {
logging.Error(s, err.Error(), nil, span, logrus.Fields{"error": err})
}
},
}
}
Expand Down
7 changes: 2 additions & 5 deletions google/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package google

import (
"context"
"io/ioutil"
"log"
"net/http"
"os"

"gitlab.ritsec.cloud/1nv8rZim/ops-bot-iii/config"
"golang.org/x/oauth2/google"
Expand All @@ -14,9 +14,6 @@ import (
)

var (
// Ctx is the context for the google package
ctx context.Context = context.Background()

// SheetsSrv is the sheets service
sheetsSrv *sheets.Service

Expand All @@ -26,7 +23,7 @@ var (

func init() {
// Read the JSON key file
keyBytes, err := ioutil.ReadFile(config.Google.KeyFile)
keyBytes, err := os.ReadFile(config.Google.KeyFile)
if err != nil {
log.Fatalf("Failed to read the JSON key file: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions helpers/generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func IsNotEmpty[T any](slice []T) bool {

// Choose returns a random item from a slice
func Choose[T any](slice []T) T {
if slice == nil || len(slice) == 0 {
if len(slice) == 0 {
panic("Cannot choose from empty slice")
}

rand.Seed(time.Now().UnixNano())
return slice[rand.Intn(len(slice))]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return slice[r.Intn(len(slice))]
}

// EmliminationPool returns the options with the lowest count in a round
Expand Down

0 comments on commit ccb1116

Please sign in to comment.