/// <summary> /// Returns a <see langword="bool"/> that says whether this <see cref="DiscordRole"/> is below another <see cref="DiscordRole"/>. /// </summary> /// <param name="roleBelow"></param> /// <param name="role">The other <see cref="DiscordRole"/> to compare.</param> /// <returns>A <see langword="bool"/>.</returns> public static bool IsBelow(this DiscordRole roleBelow, DiscordRole role) { roleBelow.IsNotNull(); role.IsNotNull(); return(roleBelow.Position < role.Position); }
/// <summary> /// Returns a <see langword="bool"/> that says whether this <see cref="DiscordRole"/> is above another <see cref="DiscordRole"/>. /// </summary> /// <param name="roleAbove"></param> /// <param name="role">The other <see cref="DiscordRole"/> to compare.</param> /// <returns>A <see langword="bool"/>.</returns> public static bool IsAbove(this DiscordRole roleAbove, DiscordRole role) { roleAbove.IsNotNull(); role.IsNotNull(); return(roleAbove.Position > role.Position); }
/// <summary> /// Adds the same permission on different channels. /// </summary> /// <param name="discordClient"></param> /// <param name="role">Role to be added to permission.</param> /// <param name="allow">Permissions to be released.</param> /// <param name="deny">Permissions to be denied.</param> /// <param name="reason">Reason for audit logs.</param> /// <param name="channels">Discord channels for adding permissions.</param> /// <exception cref="NullReferenceException"></exception> /// <exception cref="ElementIsNullException"></exception> /// <returns></returns> public static async Task AddOverwriteOnMultipleChannelsAsync(this DiscordClient discordClient, DiscordRole role, Permissions allow = Permissions.None, Permissions deny = Permissions.None, string reason = null, params DiscordChannel[] channels) { discordClient.IsNotNull(); role.IsNotNull(); channels.IsNotNull(); var tasks = new List <Task>(); foreach (var channel in channels) { tasks.Add(channel.AddOverwriteAsync(role, allow, deny, reason)); } await Task.WhenAll(tasks); }
/// <summary> /// Returns a percentage of the members who hold this <see cref="DiscordRole"/>. /// </summary> /// <param name="role"></param> /// <returns>A <see cref="decimal"/> with the percentage.</returns> /// <exception cref="ArgumentNullException"></exception> public static decimal GetPercentageOfMembers(this DiscordRole role) { role.IsNotNull(); return(Math.Round((decimal)GetMembers(role).Count * 100 / CheckIfRoleExistsAndReturnTheGuild(role).MemberCount, 5)); }
/// <summary> /// Get a list that contains all the <see cref="DiscordMember"/> that have that role. /// </summary> /// <param name="role"></param> /// <returns>A <see cref="IReadOnlyList{DiscordRole}"/> with the members.</returns> public static IReadOnlyList <DiscordMember> GetMembers(this DiscordRole role) { role.IsNotNull(); return(CheckIfRoleExistsAndReturnTheGuild(role).Members.Values.Where(m => m.Roles.Contains(role)).ToList()); }