Skip to content

Commit

Permalink
add alumni command
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed Aug 30, 2024
1 parent 5bcc793 commit f366c7a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions commands/alumni.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package commands

import (
"fmt"
"sentinel/config"
"sentinel/service"
"sentinel/utils"
"time"

"github.com/bwmarrin/discordgo"
)

func Alumni(args []string, s *discordgo.Session, m *discordgo.MessageCreate) {
defer s.ChannelMessageDelete(m.ChannelID, m.ID)
if m.GuildID != config.DiscordGuild {
m.GuildID = config.DiscordGuild
}
// Get user info
guildMember, err := s.GuildMember(m.GuildID, m.Author.ID)
if err != nil {
utils.SugarLogger.Errorln(err)
go service.SendDisappearingMessage(m.ChannelID, "Unexpected error occurred, please try again later!", 5*time.Second)
return
}
isOfficer := false
for _, role := range guildMember.Roles {
if role == "812948550819905546" {
isOfficer = true
break
}
}
utils.SugarLogger.Infof("User %s is officer: %t", m.Author.ID, isOfficer)

user := service.GetUserByID(m.Author.ID)
if user.ID == "" {
// User not found
go service.SendDisappearingMessage(m.ChannelID, "You must verify your account first! (`!verify <first name> <last name> <email>`)", 5*time.Second)
return
} else {
err = s.GuildMemberRoleAdd(m.GuildID, user.ID, config.AlumniRoleID)
if err != nil {
go service.SendDisappearingMessage(m.ChannelID, "Unexpected error occurred, please try again later!", 5*time.Second)
utils.SugarLogger.Errorln(err)
return
}
go service.SendDisappearingMessage(m.ChannelID, fmt.Sprintf("Nice to see you again %s!", user.FirstName), 5*time.Second)
}
}
2 changes: 2 additions & 0 deletions commands/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func OnDiscordMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
Whois(args, s, m)
case "users":
Users(args, s, m)
case "alumni":
Alumni(args, s, m)
default:
utils.SugarLogger.Infof("Command not found: %s", command)
}
Expand Down

0 comments on commit f366c7a

Please sign in to comment.