diff --git a/commands/scheduled/goodfood.go b/commands/scheduled/goodfood.go index 17597d0..2e5261a 100644 --- a/commands/scheduled/goodfood.go +++ b/commands/scheduled/goodfood.go @@ -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 diff --git a/commands/scheduled/status.go b/commands/scheduled/status.go index ccc0ec2..19c3554 100644 --- a/commands/scheduled/status.go +++ b/commands/scheduled/status.go @@ -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", @@ -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) + } } } diff --git a/commands/slash/kudos.go b/commands/slash/kudos.go index facd970..b21c7eb 100644 --- a/commands/slash/kudos.go +++ b/commands/slash/kudos.go @@ -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) }, diff --git a/commands/slash/logging.go b/commands/slash/logging.go index b1761e8..bc8ef60 100644 --- a/commands/slash/logging.go +++ b/commands/slash/logging.go @@ -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" @@ -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}) + } } }, } diff --git a/config/main.go b/config/main.go index 27f4328..71cddd9 100644 --- a/config/main.go +++ b/config/main.go @@ -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 } diff --git a/web/main.go b/web/main.go index 06569f1..ddf7ff0 100644 --- a/web/main.go +++ b/web/main.go @@ -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" ) @@ -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 @@ -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