From ef75e59d0ad1e482136ffb66592e628c090ca42e Mon Sep 17 00:00:00 2001 From: Bharat Kathi Date: Fri, 30 Aug 2024 14:24:31 -0700 Subject: [PATCH] add incomplete profile reminder weekly --- jobs/discord.go | 28 ++++++++++++++++++++-------- main.go | 3 +-- service/discord_service.go | 1 - service/user_service.go | 12 ++++++++++++ utils/config.go | 4 ++++ 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/jobs/discord.go b/jobs/discord.go index d43e2e0..31a5e81 100644 --- a/jobs/discord.go +++ b/jobs/discord.go @@ -9,10 +9,10 @@ import ( cron "github.com/robfig/cron/v3" ) -func RegisteDiscordCronJob() { +func RegisterDiscordCronJob() { if config.Env != "PROD" { utils.SugarLogger.Infoln("Discord CRON Job not registered because environment is not PROD") - return + // return } c := cron.New() CleanDiscordJob(c) @@ -21,11 +21,11 @@ func RegisteDiscordCronJob() { func CleanDiscordJob(c *cron.Cron) { entryID, err := c.AddFunc(config.DiscordCron, func() { - _, _ = service.Discord.ChannelMessageSend(config.DiscordLogChannel, ":alarm_clock: Starting discord CRON Job") - utils.SugarLogger.Infoln("Starting discord CRON Job...") - service.CleanGithubMembers() - utils.SugarLogger.Infoln("Finished discord CRON Job!") - _, _ = service.Discord.ChannelMessageSend(config.DiscordLogChannel, ":white_check_mark: Finished discord job!") + _, _ = service.Discord.ChannelMessageSend(config.DiscordLogChannel, ":alarm_clock: Starting discord member cleanup CRON Job") + utils.SugarLogger.Infoln("Starting discord member cleanup CRON Job...") + service.CleanDiscordMembers() + utils.SugarLogger.Infoln("Finished discord member cleanup CRON Job!") + _, _ = service.Discord.ChannelMessageSend(config.DiscordLogChannel, ":white_check_mark: Finished discord member cleanup CRON Job!") }) if err != nil { utils.SugarLogger.Errorln("Error registering CRON Job: " + err.Error()) @@ -36,5 +36,17 @@ func CleanDiscordJob(c *cron.Cron) { } func IncompleteProfileJob(c *cron.Cron) { - + entryID, err := c.AddFunc("0 10 */7 * *", func() { + _, _ = service.Discord.ChannelMessageSend(config.DiscordLogChannel, ":alarm_clock: Starting incomplete profile reminder CRON Job") + utils.SugarLogger.Infoln("Starting incomplete profile reminder CRON Job...") + service.IncompleteProfileReminder() + utils.SugarLogger.Infoln("Finished incomplete profile reminder CRON Job!") + _, _ = service.Discord.ChannelMessageSend(config.DiscordLogChannel, ":white_check_mark: Finished incomplete profile reminder CRON Job!") + }) + if err != nil { + utils.SugarLogger.Errorln("Error registering CRON Job: " + err.Error()) + return + } + c.Start() + utils.SugarLogger.Infoln("Registered CRON Job: " + strconv.Itoa(int(entryID)) + " scheduled with cron expression: " + config.DiscordCron) } diff --git a/main.go b/main.go index fc54347..ff90fa0 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,7 @@ func main() { jobs.RegisterDriveCronJob() jobs.RegisteGithubCronJob() jobs.RegisterWikiCronJob() - - service.CleanDiscordMembers() + jobs.RegisterDiscordCronJob() router := controller.SetupRouter() controller.InitializeRoutes(router) diff --git a/service/discord_service.go b/service/discord_service.go index 6db0340..31b8280 100644 --- a/service/discord_service.go +++ b/service/discord_service.go @@ -315,7 +315,6 @@ func FindAllNonVerifiedUsers() { guildMembers++ } for _, id := range sendIds { - println(id) SendDirectMessage(id, "Hey there Gaucho Racer! It look's like you haven't verified your account yet. Please use the `!verify` command to verify your account before September 7th to avoid any disruption to your server access. You can run this command in any channel in the Gaucho Racing discord server!\n\nHere's the command usage: `!verify `\nAnd here's an example: `!verify Bharat Kathi bkathi@ucsb.edu`") } utils.SugarLogger.Infof("Total Members: %d", guildMembers) diff --git a/service/user_service.go b/service/user_service.go index db6b667..7b875ce 100644 --- a/service/user_service.go +++ b/service/user_service.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "sentinel/config" "sentinel/database" "sentinel/model" "sentinel/utils" @@ -94,3 +95,14 @@ func SearchUsers(search string) []model.User { } return users } + +func IncompleteProfileReminder() { + allUsers := GetAllUsers() + for _, user := range allUsers { + if user.FirstName == "" || user.LastName == "" || user.Email == "" || user.GraduationYear == 0 || user.GraduateLevel == "" || user.Major == "" || user.ShirtSize == "" || user.JacketSize == "" { + utils.SugarLogger.Infof("User %s has incomplete profile", user.ID) + SendDirectMessage(user.ID, fmt.Sprintf("Hey there %s! It look's like you haven't completed your Sentinel profile yet. Please go to https://sso.gauchoracing.com/users/%s/edit to complete it when you get a chance. It only takes a few minutes and saves us a lot of trouble later on :pray: Let us know if you need any help.", user.FirstName, user.ID)) + SendMessage(config.DiscordLogChannel, fmt.Sprintf("Sent incomplete profile reminder to %s", user)) + } + } +} diff --git a/utils/config.go b/utils/config.go index 86ecc11..d19b6d8 100644 --- a/utils/config.go +++ b/utils/config.go @@ -64,4 +64,8 @@ func VerifyConfig() { config.WikiCron = "0 * * * *" SugarLogger.Infof("WIKI_CRON is not set, defaulting to %s", config.WikiCron) } + if config.DiscordCron == "" { + config.DiscordCron = "0 * * * *" + SugarLogger.Infof("DISCORD_CRON is not set, defaulting to %s", config.DiscordCron) + } }