public bool HasPerm(string perm) { pService ??= Program.Services.GetRequiredService <PermissionsService>(); var node = pService.FindNode(perm); if (node == null) { Program.LogMsg($"Attempted checking invalid perm: {Path}, '{perm}'"); return(false); } return(PermChecker.HasPerm(this, node)); }
public async override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { var node = Program.Services.GetRequiredService <PermissionsService>().FindNode(Node); if (!(context is BotCommandContext bC)) { return(PreconditionResult.FromError("Command context invalid, contact bot developer.")); } if (PermChecker.HasPerm(bC, node)) { return(PreconditionResult.FromSuccess()); } return(PreconditionResult.FromError($"You required extra permissions to access this endpoint (`{node.Node}`: {node.Description})")); }
public override PreconditionResult Check(APIContext context) { if (context.User == null) { return(PreconditionResult.FromError("You must be logged in")); } List <NodeInfo> missing = new List <NodeInfo>(); foreach (var perm in Nodes) { var node = (NodeInfo)perm; var val = PermChecker.HasPerm(context, node); if (!val) { missing.Add(node); } } if (missing.Count > 0) { return(PreconditionResult.FromError("Missing permissions: '" + string.Join("', '", missing.Select(x => x.Description)) + "'")); } return(PreconditionResult.FromSuccess()); }