2019-11-27 09:07:48 +07:00
|
|
|
package roles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
"PermissionGacha/modules/config"
|
|
|
|
"PermissionGacha/modules/log"
|
|
|
|
)
|
|
|
|
|
2019-12-13 10:14:32 +07:00
|
|
|
func GiveLevelRoles(s *discordgo.Session, discordID string, oldLevel, newLevel int) error {
|
2019-11-29 14:10:01 +07:00
|
|
|
for i := oldLevel + 1; i <= newLevel; i++ {
|
2019-12-13 10:14:32 +07:00
|
|
|
err := s.GuildMemberRoleAdd(config.GuildID, discordID, config.LevelRoles[i-1])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-27 09:07:48 +07:00
|
|
|
}
|
2019-12-13 10:14:32 +07:00
|
|
|
return nil
|
2019-11-27 09:07:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func RemoveAllLevelRoles(s *discordgo.Session, discordID string) {
|
|
|
|
member, err := s.GuildMember(config.GuildID, discordID)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(s, "RemoveAllLevelRoles", "GuildMember", discordID)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, v := range member.Roles {
|
2019-12-13 10:07:39 +07:00
|
|
|
for _, w := range config.LevelRoles {
|
2019-11-27 09:07:48 +07:00
|
|
|
if v == w {
|
|
|
|
s.GuildMemberRoleRemove(config.GuildID, discordID, v)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|