using System.Linq;
using Discord;
using Discord.WebSocket;
namespace DiscordBotCore.Others;
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.Any(role => role.HasPermission(permission)) || 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);
}
}