Compare commits
No commits in common. "1806c9b494b7c1026f34ed45934d4bd8a27e68a5" and "9e94b48d695133d53eca215b99cdd694dfaafb98" have entirely different histories.
1806c9b494
...
9e94b48d69
|
@ -9,9 +9,7 @@ func removeRole(discordClient *discordgo.Session, guildID string, userID string,
|
||||||
if ! dryrun {
|
if ! dryrun {
|
||||||
err := discordClient.GuildMemberRoleRemove(guild, userID, roleID)
|
err := discordClient.GuildMemberRoleRemove(guild, userID, roleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.Error(err.Error())
|
||||||
"id": userID,
|
|
||||||
}).Error(err.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +18,7 @@ func addRole(discordClient *discordgo.Session, guildID string, userID string, ro
|
||||||
if ! dryrun {
|
if ! dryrun {
|
||||||
err := discordClient.GuildMemberRoleAdd(guild, userID, roleID)
|
err := discordClient.GuildMemberRoleAdd(guild, userID, roleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.Error(err.Error())
|
||||||
"id": userID,
|
|
||||||
}).Error(err.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,4 @@ services:
|
||||||
build: .
|
build: .
|
||||||
container_name: bot_discord
|
container_name: bot_discord
|
||||||
env_file: ./env_file
|
env_file: ./env_file
|
||||||
entrypoint: bot --guild=606162827274616845 --top1=798638767359524875 --top10=801787467064672286 --top50=803729539145924649
|
entrypoint: bot --guild=943459216901955604 --top1=798638767359524875 --top10=801787467064672286 --top50=803729539145924649
|
||||||
|
|
2
main.go
2
main.go
|
@ -16,7 +16,7 @@ type UserRole struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global var (I know, and i don't care)
|
// 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 guild string
|
||||||
var rolesID map[string]string
|
var rolesID map[string]string
|
||||||
var Users map[string]*UserRole
|
var Users map[string]*UserRole
|
||||||
|
|
78
rank.go
78
rank.go
|
@ -29,10 +29,7 @@ func populateUserRole(discordClient *discordgo.Session) error {
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
|
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.Error("ID not found", id)
|
||||||
"id": id,
|
|
||||||
"rank": rank,
|
|
||||||
}).Error(err.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -56,33 +53,27 @@ func updateUserRole(discordClient *discordgo.Session, dryrun bool) error {
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
|
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.Error("ID not found", id)
|
||||||
"id": id,
|
|
||||||
"rank": rank,
|
|
||||||
}).Error(err.Error())
|
|
||||||
}
|
}
|
||||||
user, exist := Users[id]
|
if Users[id].Rank != rank {
|
||||||
if exist {
|
logrus.Info("New rank (", rank, ") for user ", id)
|
||||||
if user.Rank != rank {
|
if Users[id].CurrentRole != "" {
|
||||||
logrus.Info("New rank (", rank, ") for user ", id)
|
logrus.Info("Remove role for ", id)
|
||||||
if user.CurrentRole != "" {
|
removeRole(discordClient, guild, id, Users[id].CurrentRole, dryrun)
|
||||||
logrus.Info("Remove role for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
|
||||||
removeRole(discordClient, guild, id, user.CurrentRole, dryrun)
|
}
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: ""}
|
if rank == 1 {
|
||||||
}
|
logrus.Info("Add role `top1` for ", id)
|
||||||
if rank == 1 {
|
addRole(discordClient, guild, id, rolesID["top1"], dryrun)
|
||||||
logrus.Info("Add role `top1` for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top1"]}
|
||||||
addRole(discordClient, guild, id, rolesID["top1"], dryrun)
|
} else if rank <= 10 {
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top1"]}
|
logrus.Info("Add role `top10` for ", id)
|
||||||
} else if rank <= 10 {
|
addRole(discordClient, guild, id, rolesID["top10"], dryrun)
|
||||||
logrus.Info("Add role `top10` for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top10"]}
|
||||||
addRole(discordClient, guild, id, rolesID["top10"], dryrun)
|
} else if rank <= 50 {
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top10"]}
|
logrus.Info("Add role `top50` for ", id)
|
||||||
} else if rank <= 50 {
|
addRole(discordClient, guild, id, rolesID["top50"], dryrun)
|
||||||
logrus.Info("Add role `top50` for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top50"]}
|
||||||
addRole(discordClient, guild, id, rolesID["top50"], dryrun)
|
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top50"]}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,21 +101,18 @@ func forceUpdate(discordClient *discordgo.Session, dryrun bool) (error) {
|
||||||
} else {
|
} else {
|
||||||
logrus.Error("ID not found", id)
|
logrus.Error("ID not found", id)
|
||||||
}
|
}
|
||||||
_, exist := Users[id]
|
if rank == 1 {
|
||||||
if exist {
|
logrus.Info("Add role `top1` for ", id)
|
||||||
if rank == 1 {
|
addRole(discordClient, guild, id, rolesID["top1"], dryrun)
|
||||||
logrus.Info("Add role `top1` for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top1"]}
|
||||||
addRole(discordClient, guild, id, rolesID["top1"], dryrun)
|
} else if rank <= 10 {
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top1"]}
|
logrus.Info("Add role `top10` for ", id)
|
||||||
} else if rank <= 10 {
|
addRole(discordClient, guild, id, rolesID["top10"], dryrun)
|
||||||
logrus.Info("Add role `top10` for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top10"]}
|
||||||
addRole(discordClient, guild, id, rolesID["top10"], dryrun)
|
} else if rank <= 50 {
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top10"]}
|
logrus.Info("Add role `top50` for ", id)
|
||||||
} else if rank <= 50 {
|
addRole(discordClient, guild, id, rolesID["top50"], dryrun)
|
||||||
logrus.Info("Add role `top50` for ", id)
|
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top50"]}
|
||||||
addRole(discordClient, guild, id, rolesID["top50"], dryrun)
|
|
||||||
Users[id] = &UserRole{Rank: rank, CurrentRole: rolesID["top50"]}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue