Skip to content

Commit

Permalink
fixing encountered errors from CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
1nv8rzim committed Aug 25, 2023
1 parent 4710fe3 commit 7080326
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
34 changes: 20 additions & 14 deletions commands/scheduled/goodfood.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,29 @@ func GoodFood() *structs.ScheduledEvent {

c := cron.NewWithLocation(est)

must := func(err error) {
if err != nil {
logging.Error(s, err.Error(), nil, span)
}
}

// 11:00 AM
c.AddFunc("0 0 11 * * MON", func() {}) // Monday
c.AddFunc("0 0 11 * * TUE", func() { sendGoodFoodPing(s, "Crossroads", span.Context()) }) // Tuesday
c.AddFunc("0 0 11 * * WED", func() { sendGoodFoodPing(s, "Brick City", span.Context()) }) // Wednesday
c.AddFunc("0 0 11 * * THU", func() {}) // Thursday
c.AddFunc("0 0 11 * * FRI", func() {}) // Friday
c.AddFunc("0 0 11 * * SAT", func() {}) // Saturday
c.AddFunc("0 0 11 * * SUN", func() {}) // Sunday
must(c.AddFunc("0 0 11 * * MON", func() {})) // Monday
must(c.AddFunc("0 0 11 * * TUE", func() { sendGoodFoodPing(s, "Crossroads", span.Context()) })) // Tuesday
must(c.AddFunc("0 0 11 * * WED", func() { sendGoodFoodPing(s, "Brick City", span.Context()) })) // Wednesday
must(c.AddFunc("0 0 11 * * THU", func() {})) // Thursday
must(c.AddFunc("0 0 11 * * FRI", func() {})) // Friday
must(c.AddFunc("0 0 11 * * SAT", func() {})) // Saturday
must(c.AddFunc("0 0 11 * * SUN", func() {})) // Sunday

// 4:00 PM
c.AddFunc("0 0 16 * * MON", func() { sendGoodFoodPing(s, "RITZ", span.Context()) }) // Monday
c.AddFunc("0 0 16 * * TUE", func() {}) // Tuesday
c.AddFunc("0 0 16 * * WED", func() { sendGoodFoodPing(s, "RITZ", span.Context()) }) // Wednesday
c.AddFunc("0 0 16 * * THU", func() { sendGoodFoodPing(s, "Crossroads", span.Context()) }) // Thursday
c.AddFunc("0 0 16 * * FRI", func() {}) // Friday
c.AddFunc("0 0 16 * * SAT", func() {}) // Saturday
c.AddFunc("0 0 16 * * SUN", func() {}) // Sunday
must(c.AddFunc("0 0 16 * * MON", func() { sendGoodFoodPing(s, "RITZ", span.Context()) })) // Monday
must(c.AddFunc("0 0 16 * * TUE", func() {})) // Tuesday
must(c.AddFunc("0 0 16 * * WED", func() { sendGoodFoodPing(s, "RITZ", span.Context()) })) // Wednesday
must(c.AddFunc("0 0 16 * * THU", func() { sendGoodFoodPing(s, "Crossroads", span.Context()) })) // Thursday
must(c.AddFunc("0 0 16 * * FRI", func() {})) // Friday
must(c.AddFunc("0 0 16 * * SAT", func() {})) // Saturday
must(c.AddFunc("0 0 16 * * SUN", func() {})) // Sunday

c.Start()
<-quit
Expand Down
10 changes: 8 additions & 2 deletions commands/scheduled/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func updateStatus(s *discordgo.Session, ctx ddtrace.SpanContext) {
rand.Seed(time.Now().UnixNano())

if weekday == time.Friday && hour >= 12 && hour < 16 {
s.UpdateStatusComplex(discordgo.UpdateStatusData{
err := s.UpdateStatusComplex(discordgo.UpdateStatusData{
Activities: []*discordgo.Activity{
{
Name: "RITSEC General Meeting",
Expand All @@ -43,12 +43,18 @@ func updateStatus(s *discordgo.Session, ctx ddtrace.SpanContext) {
},
},
})
if err != nil {
logging.Error(s, err.Error(), nil, span)
}
} else {
s.UpdateStatusComplex(discordgo.UpdateStatusData{
err := s.UpdateStatusComplex(discordgo.UpdateStatusData{
Activities: []*discordgo.Activity{
&activities[rand.Intn(len(activities))],
},
})
if err != nil {
logging.Error(s, err.Error(), nil, span)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion commands/slash/kudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func Kudos() *structs.SlashCommand {

wg.Wait()

s.ChannelMessageDelete(KudosApprovalChannelID, approvalMessage.ID)
err = s.ChannelMessageDelete(KudosApprovalChannelID, approvalMessage.ID)
if err != nil {
logging.Error(s, "Error deleting channel message", i.Member.User, span, logrus.Fields{"error": err})
}
delete(*ComponentHandlers, approve_slug)
delete(*ComponentHandlers, deny_slug)
},
Expand Down
11 changes: 9 additions & 2 deletions commands/slash/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slash

import (
"github.com/bwmarrin/discordgo"
"github.com/sirupsen/logrus"
"gitlab.ritsec.cloud/1nv8rZim/ops-bot-iii/commands/slash/permission"
"gitlab.ritsec.cloud/1nv8rZim/ops-bot-iii/config"
"gitlab.ritsec.cloud/1nv8rZim/ops-bot-iii/logging"
Expand Down Expand Up @@ -61,25 +62,31 @@ func Log() *structs.SlashCommand {
logging.Debug(s, "Log command received", i.Member.User, span)

if len(i.ApplicationCommandData().Options) == 0 {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Current logging level: " + logging.LevelNameMap[logging.LogLevel()],
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
logging.Error(s, "Error sending current log level", i.Member.User, span, logrus.Fields{"error": err})
}
} else {
config.SetLoggingLevel(i.ApplicationCommandData().Options[0].StringValue())

logging.Critical(s, "Logging level changed to "+i.ApplicationCommandData().Options[0].StringValue(), i.Member.User, span)

s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Logging level changed to " + i.ApplicationCommandData().Options[0].StringValue(),
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
logging.Error(s, "Error sending confirmation of change of log level", i.Member.User, span, logrus.Fields{"error": err})
}
}
},
}
Expand Down
5 changes: 4 additions & 1 deletion config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func mailgun() structs.MailGunConfig {
// SetLoggingLevel sets the logging level
func SetLoggingLevel(level string) {
viper.Set("logging.level", level)
viper.WriteConfig()
err := viper.WriteConfig()
if err != nil {
panic(err)
}

Logging.Level = level
}
Expand Down
12 changes: 10 additions & 2 deletions web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package web

import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"gitlab.ritsec.cloud/1nv8rZim/ops-bot-iii/config"
"gitlab.ritsec.cloud/1nv8rZim/ops-bot-iii/logging"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
Expand All @@ -16,7 +18,10 @@ func init() {
gin.SetMode(gin.ReleaseMode)
Router = gin.Default()

Router.SetTrustedProxies(nil)
err := Router.SetTrustedProxies(nil)
if err != nil {
panic(err)
}
}

// Start starts the web server
Expand All @@ -29,7 +34,10 @@ func Start(ctx ddtrace.SpanContext) {
defer span.Finish()

loadRoutes(span.Context())
Router.Run(config.Web.Hostname + ":" + config.Web.Port)
err := Router.Run(config.Web.Hostname + ":" + config.Web.Port)
if err != nil {
logging.CriticalDD("Error running web server", span, logrus.Fields{"error": err})
}
}

// loadRoutes loads the routes
Expand Down

0 comments on commit 7080326

Please sign in to comment.