using Discord; using Discord.WebSocket; using System.Linq; namespace PluginManager.Others.Permissions { /// /// A class whith all discord permissions /// public static class DiscordPermissions { /// /// Checks if the role has the specified permission /// /// The role /// The permission /// public static bool hasPermission(this IRole role, GuildPermission permission) => role.Permissions.Has(permission); /// /// Check if user has the specified role /// /// The user /// The role /// public static bool hasRole(this SocketGuildUser user, IRole role) => user.Roles.Contains(role); /// /// Check if user has the specified permission /// /// The user /// The permission /// public static bool hasPermission(this SocketGuildUser user, GuildPermission permission) => user.Roles.Where(role => role.hasPermission(permission)).Any() || user.Guild.Owner == user; /// /// Check if user is administrator of server /// /// The user /// public static bool isAdmin(this SocketGuildUser user) => user.hasPermission(GuildPermission.Administrator); /// /// Check if user is administrator of server /// /// The user /// public static bool isAdmin(this SocketUser user) => isAdmin((SocketGuildUser)user); } }