예제 #1
0
        public Rank GetMatchingRank(DiscordMember member)
        {
            List <string> roleNamesForMember = new List <string>();

            foreach (var role in member.Roles)
            {
                roleNamesForMember.Add(role.Name);
            }
            //var roleNamesForMember = member.Roles.ToList();
            var matchingRole = MilRanks.Where(x => roleNamesForMember.Contains(x.RankName)).FirstOrDefault();

            if (matchingRole == null)
            {
                matchingRole = CommerceRanks.Where(x => roleNamesForMember.Contains(x.RankName)).FirstOrDefault();
            }

            return(matchingRole);
        }
예제 #2
0
        //Demote a member
        public async Task <bool> Demote(DiscordMember member)
        {
            try
            {
                var currentRank = GetMatchingRank(member);
                var newRank     = MilRanks.Where(x => x.Number == currentRank.Number - 1).FirstOrDefault();
                if (newRank == null)
                {
                    newRank = CommerceRanks.Where(x => x.Number == currentRank.Number - 1).FirstOrDefault();
                }

                await member.RevokeRoleAsync(member.Guild.Roles.Where(x => x.Name == currentRank.RankName).FirstOrDefault());

                await member.GrantRoleAsync(member.Guild.Roles.Where(x => x.Name == newRank.RankName).FirstOrDefault());

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }