using System.Linq; using Discord; using Discord.WebSocket; 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) { return role.Permissions.Has(permission); } /// /// Check if user has the specified role /// /// The user /// The role /// public static bool HasRole(this SocketGuildUser user, IRole role) { return user.Roles.Contains(role); } /// /// Check if user has the specified permission /// /// The user /// The permission /// public static bool HasPermission(this SocketGuildUser user, GuildPermission permission) { return 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) { return user.HasPermission(GuildPermission.Administrator); } /// /// Check if user is administrator of server /// /// The user /// public static bool IsAdmin(this SocketUser user) { return IsAdmin((SocketGuildUser)user); } }