Skip to content

Commit

Permalink
add incomplete profile reminder weekly
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed Aug 30, 2024
1 parent 5f74d99 commit ef75e59
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
28 changes: 20 additions & 8 deletions jobs/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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)
}
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func main() {
jobs.RegisterDriveCronJob()
jobs.RegisteGithubCronJob()
jobs.RegisterWikiCronJob()

service.CleanDiscordMembers()
jobs.RegisterDiscordCronJob()

router := controller.SetupRouter()
controller.InitializeRoutes(router)
Expand Down
1 change: 0 additions & 1 deletion service/discord_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <first name> <last name> <email>`\nAnd here's an example: `!verify Bharat Kathi bkathi@ucsb.edu`")
}
utils.SugarLogger.Infof("Total Members: %d", guildMembers)
Expand Down
12 changes: 12 additions & 0 deletions service/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"fmt"
"sentinel/config"
"sentinel/database"
"sentinel/model"
"sentinel/utils"
Expand Down Expand Up @@ -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))
}
}
}
4 changes: 4 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit ef75e59

Please sign in to comment.