Complete Preconditions implementation

This commit is contained in:
Finite Reality
2016-08-03 17:21:38 +01:00
parent a5393dc937
commit 0e920da21f
10 changed files with 108 additions and 50 deletions

View File

@@ -208,16 +208,19 @@ namespace Discord.Commands
if (!searchResult.IsSuccess)
return searchResult;
// TODO: this logic is for users who don't manually search/execute: should we keep it?
IReadOnlyList<Command> commands = searchResult.Commands
.Where(x => x.MeetsPreconditions(message)).ToImmutableArray();
if (commands.Count == 0 && searchResult.Commands.Count > 0)
return ParseResult.FromError(CommandError.UnmetPrecondition, "Unmet precondition");
var commands = searchResult.Commands;
for (int i = commands.Count - 1; i >= 0; i--)
{
var preconditionResult = await commands[i].CheckPreconditions(message);
if (!preconditionResult.IsSuccess)
{
if (commands.Count == 1)
return preconditionResult;
else
continue;
}
var parseResult = await commands[i].Parse(message, searchResult);
if (!parseResult.IsSuccess)
{