Пример #1
0
        public static GuildPermissions GetPermissions(this RestMember user, RestGuild guild)
        {
            if (user.Id == guild.OwnerId)
            {
                return(GuildPermissions.All);
            }

            return(GetPermissions(user, guild.Roles));
        }
Пример #2
0
        /// <summary>
        /// Gets a users max position within a guild
        /// </summary>
        /// <param name="user"></param>
        /// <param name="guild"></param>
        /// <returns></returns>
        public static int GetPosition(this RestMember user, RestGuild guild)
        {
            if (guild == null)
            {
                return(-1);
            }
            if (guild.OwnerId == user.Id)
            {
                return(int.MaxValue);
            }

            return(GetPosition(user, guild.Roles));
        }
Пример #3
0
        public static GuildPermissions GetPermissions(this RestMember user, IReadOnlyDictionary <Snowflake, RestRole> roles)
        {
            GuildPermissions basePerms = GuildPermissions.None;

            foreach (var role in roles.OrderBy(x => x.Value.Position))
            {
                if (!user.RoleIds.Contains(role.Key))
                {
                    continue;
                }
                basePerms += role.Value.Permissions;
            }
            return(basePerms);
        }
Пример #4
0
        /// <summary>
        /// Gets a users max position within a list of roles.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="roles"></param>
        /// <returns></returns>
        public static int GetPosition(this RestMember user, IReadOnlyDictionary <Snowflake, RestRole> roles)
        {
            int maxPos = 0;

            foreach (var roleId in user.RoleIds)
            {
                if (roles.TryGetValue(roleId, out var role))
                {
                    if (role.Position > maxPos)
                    {
                        maxPos = role.Position;
                    }
                }
            }
            return(maxPos);
        }
Пример #5
0
        /// <summary>
        /// Gets a users max position within their guild, fetching the guild
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static async Task <int> GetPositionAsync(this RestMember user)
        {
            var guild = await user.Guild.FetchAsync();

            return(GetPosition(user, guild));
        }
Пример #6
0
        public static async Task <GuildPermissions> GetPermissions(this RestMember user)
        {
            var guild = await user.Guild.FetchAsync();

            return(GetPermissions(user, guild));
        }