Add grouping of preconditions to allow for flexible precondition logic. (#672)

* Add grouping of preconditions to allow for flexible precondition logic.

* Fix checking Module Preconditions twice (and none of the command's own)

* Fix command preconditions group 0 looping over every other precondition anyway #whoopsies

* Use custom message when a non-zero Precondition Group fails.

* Fix doc comment rendering.

* Refactor loops into local function

* Considering a new result type

* Switch to IReadOnlyCollection<T> and fix compiler errors

* Revert PreconditionResult -> IResult in return types - Change PreconditionResult to a class that PreconditionGroupResult inherits.

* Feedback on property name.

* Change grouping type int -> string

* Explicitly use an ordinal StringComparer

* Full stops on error messages

* Remove some sillyness.

* Remove unneeded using.
This commit is contained in:
Joe4evr
2017-06-23 16:28:22 +02:00
committed by RogueException
parent d44d5e7198
commit 4a9c8168a9
5 changed files with 70 additions and 16 deletions

View File

@@ -6,6 +6,13 @@ namespace Discord.Commands
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public abstract class PreconditionAttribute : Attribute
{
/// <summary>
/// Specify a group that this precondition belongs to. Preconditions of the same group require only one
/// of the preconditions to pass in order to be successful (A || B). Specifying <see cref="Group"/> = <see cref="null"/>
/// or not at all will require *all* preconditions to pass, just like normal (A &amp;&amp; B).
/// </summary>
public string Group { get; set; } = null;
public abstract Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services);
}
}