Example #1
0
        /// <summary>
        /// Returns a <see langword="bool"/> that says whether the member can be banned from the server. <c>Attention!</c> can be banned by the <c>bot</c>.
        /// </summary>
        /// <param name="discordUser"></param>
        /// <returns>A <see langword="bool"/>.</returns>
        public static bool CanBeBanned(this DiscordUser discordUser)
        {
            discordUser.IsNotNull();

            var discordMember = discordUser.ToDiscordMember();

            return(!discordMember.IsOwner && !discordMember.IsAdministrator() && discordMember.GetHighestRole().IsBelow(TarsBase._discordClient.CurrentUser.GetHighestRole()));
        }
Example #2
0
        /// <summary>
        /// Get the lowest role of this user in relation to the hierarchy of the Discord server.
        /// </summary>
        /// <param name="discordUser"></param>
        /// <param name="predicate"></param>
        /// <returns>The lowest <see cref="DiscordRole"/> of the user in relation to the role of the Discord server.</returns>
        public static DiscordRole GetLowestRole(this DiscordUser discordUser, Func <DiscordRole, bool> predicate = null)
        {
            discordUser.IsNotNull();

            var memberRolesOrded = discordUser.ToDiscordMember().Roles.OrderByDescending(r => r.Position);

            return(predicate is null?memberRolesOrded.LastOrDefault() : memberRolesOrded.LastOrDefault(predicate));
        }
Example #3
0
        /// <summary>
        /// Returns a <see langword="bool"/> that says whether the user is a server administrator.
        /// </summary>
        /// <param name="discordUser"></param>
        /// <returns>A <see langword="bool"/>.</returns>
        public static bool IsAdministrator(this DiscordUser discordUser)
        {
            discordUser.IsNotNull();

            return(discordUser.ToDiscordMember().Roles.Any(r => r.Permissions.HasPermission(Permissions.Administrator)));
        }