Created
May 25, 2017 09:30
-
-
Save Joe4evr/275fdadc4848ba9755ae0e8d1e022920 to your computer and use it in GitHub Desktop.
Example of how to make a logical OR of multiple preconditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | |
public class RequireAdminOrOwnerAttribute : PreconditionAttribute | |
{ | |
private readonly RequireOwnerAttribute _owner = new RequireOwnerAttribute(); | |
private readonly RequireUserPermissionAttribute _admins = new RequireUserPermissionAttribute(GuildPermission.Administrator); | |
public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |
{ | |
var isAdmin = await _admins.CheckPermissions(context, command, services); | |
var isOwner = await _owner.CheckPermissions(context, command, services); | |
return (isAdmin.IsSuccess || isOwner.IsSuccess) | |
? PreconditionResult.FromSuccess() | |
: PreconditionResult.FromError("Need to be admin or bot owner"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment