This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
2019-11-27 09:07:48 +07:00
|
|
|
package roles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
"PermissionGacha/modules/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetOldLevel(s *discordgo.Session, id string) (int, error) {
|
|
|
|
member, err := s.GuildMember(config.GuildID, id)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("roles: EligibleGachaCount: error fetching guild member (%s): %w", id, err)
|
|
|
|
}
|
2019-12-12 07:30:25 +07:00
|
|
|
foundLevel := 0
|
2019-11-27 09:07:48 +07:00
|
|
|
levelSearchLoop:
|
2019-12-13 10:07:39 +07:00
|
|
|
for i := len(config.LevelRoles); i > 0; i-- {
|
2019-11-27 09:07:48 +07:00
|
|
|
for _, v := range member.Roles {
|
2019-12-13 10:07:39 +07:00
|
|
|
if config.LevelRoles[i-1] == v {
|
2019-11-27 09:07:48 +07:00
|
|
|
foundLevel = i
|
|
|
|
break levelSearchLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundLevel, nil
|
|
|
|
}
|