Compare commits

..

No commits in common. "1806c9b494b7c1026f34ed45934d4bd8a27e68a5" and "9e94b48d695133d53eca215b99cdd694dfaafb98" have entirely different histories.

4 changed files with 37 additions and 53 deletions

View File

@ -9,9 +9,7 @@ func removeRole(discordClient *discordgo.Session, guildID string, userID string,
if ! dryrun {
err := discordClient.GuildMemberRoleRemove(guild, userID, roleID)
if err != nil {
logrus.WithFields(logrus.Fields{
"id": userID,
}).Error(err.Error())
logrus.Error(err.Error())
}
}
}
@ -20,9 +18,7 @@ func addRole(discordClient *discordgo.Session, guildID string, userID string, ro
if ! dryrun {
err := discordClient.GuildMemberRoleAdd(guild, userID, roleID)
if err != nil {
logrus.WithFields(logrus.Fields{
"id": userID,
}).Error(err.Error())
logrus.Error(err.Error())
}
}
}

View File

@ -5,4 +5,4 @@ services:
build: .
container_name: bot_discord
env_file: ./env_file
entrypoint: bot --guild=606162827274616845 --top1=798638767359524875 --top10=801787467064672286 --top50=803729539145924649
entrypoint: bot --guild=943459216901955604 --top1=798638767359524875 --top10=801787467064672286 --top50=803729539145924649

View File

@ -16,7 +16,7 @@ type UserRole struct {
}
// Global var (I know, and i don't care)
var api string = os.Getenv("API_URL")
var api string = "https://www.42ctf.local/api/bot/discord?token=" + os.Getenv("AUTH_TOKEN")
var guild string
var rolesID map[string]string
var Users map[string]*UserRole

22
rank.go
View File

@ -29,10 +29,7 @@ func populateUserRole(discordClient *discordgo.Session) error {
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
}
} else {
logrus.WithFields(logrus.Fields{
"id": id,
"rank": rank,
}).Error(err.Error())
logrus.Error("ID not found", id)
}
}
return nil
@ -56,18 +53,13 @@ func updateUserRole(discordClient *discordgo.Session, dryrun bool) error {
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
}
} else {
logrus.WithFields(logrus.Fields{
"id": id,
"rank": rank,
}).Error(err.Error())
logrus.Error("ID not found", id)
}
user, exist := Users[id]
if exist {
if user.Rank != rank {
if Users[id].Rank != rank {
logrus.Info("New rank (", rank, ") for user ", id)
if user.CurrentRole != "" {
if Users[id].CurrentRole != "" {
logrus.Info("Remove role for ", id)
removeRole(discordClient, guild, id, user.CurrentRole, dryrun)
removeRole(discordClient, guild, id, Users[id].CurrentRole, dryrun)
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
}
if rank == 1 {
@ -85,7 +77,6 @@ func updateUserRole(discordClient *discordgo.Session, dryrun bool) error {
}
}
}
}
return nil
}
@ -110,8 +101,6 @@ func forceUpdate(discordClient *discordgo.Session, dryrun bool) (error) {
} else {
logrus.Error("ID not found", id)
}
_, exist := Users[id]
if exist {
if rank == 1 {
logrus.Info("Add role `top1` for ", id)
addRole(discordClient, guild, id, rolesID["top1"], dryrun)
@ -126,6 +115,5 @@ func forceUpdate(discordClient *discordgo.Session, dryrun bool) (error) {
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top50"]}
}
}
}
return nil
}