// WingsEmu // // Developed by NosWings Team using System.Threading.Tasks; using Qmmands; using WingsEmu.Commands.Entities; using WingsEmu.DTOs.Account; namespace WingsEmu.Commands.Checks { public sealed class RequireAuthorityAttribute : CheckAttribute { public RequireAuthorityAttribute(AuthorityType authority) => Authority = authority; /// /// This represents the Authority level required to execute a command. /// public AuthorityType Authority { get; } /// /// /// This is a check (pre-condition) before trying to execute a command that needs to pass this check. /// /// Context of the command. It needs to be castable to a WingsEmuIngameCommandContext in our case. /// public override ValueTask CheckAsync(CommandContext context) { if (context is not WingsEmuIngameCommandContext ctx) { return new ValueTask(new CheckResult("Invalid context. This is *very* bad. Please report this.")); } if (ctx.Player?.Account is not null && ctx.Player.Account.Authority < Authority) { return new ValueTask(new CheckResult("You (at least) need to be a " + Authority + " in order to execute that command.")); } return new ValueTask(CheckResult.Successful); } } }