feat: Add level roles
parent
879b482b7a
commit
d273102aa2
@ -0,0 +1,47 @@
|
||||
package level
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
||||
"gitea.teamortix.com/chanbakjsd/Milen/db"
|
||||
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
||||
)
|
||||
|
||||
var Roles []string
|
||||
|
||||
var ShouldCheck = make(map[string]map[string]bool)
|
||||
|
||||
func QueueRoles(dg *discordgo.Session) {
|
||||
for {
|
||||
time.Sleep(5 * time.Second)
|
||||
for guildID, v := range ShouldCheck {
|
||||
for userID, _ := range v {
|
||||
rank, _ := GetLevelFromXP(db.GetXP(userID))
|
||||
AssignRoles(dg, guildID, userID, rank)
|
||||
delete(v, userID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AssignRoles(dg *discordgo.Session, guildID string, userID string, rank Rank) {
|
||||
member, err := util.GetMember(dg, guildID, userID)
|
||||
if err != nil {
|
||||
util.ReportError(dg, err)
|
||||
return
|
||||
}
|
||||
OuterLoop:
|
||||
for i := 0; i <= int(rank); i++ {
|
||||
if i >= len(Roles) {
|
||||
return
|
||||
}
|
||||
for _, v := range member.Roles {
|
||||
if v == Roles[i] {
|
||||
continue OuterLoop
|
||||
}
|
||||
}
|
||||
dg.GuildMemberRoleAdd(guildID, userID, Roles[i])
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue