| @@ -16,8 +16,8 @@ namespace Discord.Commands | |||||
| public Task<PreconditionResult> CheckPreconditionsAsync(ICommandContext context, IDependencyMap map = null) | public Task<PreconditionResult> CheckPreconditionsAsync(ICommandContext context, IDependencyMap map = null) | ||||
| => Command.CheckPreconditionsAsync(context, map); | => Command.CheckPreconditionsAsync(context, map); | ||||
| public Task<ParseResult> ParseAsync(ICommandContext context, SearchResult searchResult, PreconditionResult? preconditionResult = null) | |||||
| => Command.ParseAsync(context, Alias.Length, searchResult, preconditionResult); | |||||
| public Task<ParseResult> ParseAsync(ICommandContext context, SearchResult searchResult) | |||||
| => Command.ParseAsync(context, Alias.Length, searchResult); | |||||
| public Task<ExecuteResult> ExecuteAsync(ICommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IDependencyMap map) | public Task<ExecuteResult> ExecuteAsync(ICommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IDependencyMap map) | ||||
| => Command.ExecuteAsync(context, argList, paramList, map); | => Command.ExecuteAsync(context, argList, paramList, map); | ||||
| public Task<ExecuteResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IDependencyMap map) | public Task<ExecuteResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IDependencyMap map) | ||||
| @@ -257,6 +257,7 @@ namespace Discord.Commands | |||||
| if (!searchResult.IsSuccess) | if (!searchResult.IsSuccess) | ||||
| return searchResult; | return searchResult; | ||||
| PreconditionResult? secondOption = null; | |||||
| var commands = searchResult.Commands; | var commands = searchResult.Commands; | ||||
| for (int i = 0; i < commands.Count; i++) | for (int i = 0; i < commands.Count; i++) | ||||
| { | { | ||||
| @@ -265,11 +266,10 @@ namespace Discord.Commands | |||||
| { | { | ||||
| if (commands.Count == 1) | if (commands.Count == 1) | ||||
| return preconditionResult; | return preconditionResult; | ||||
| else | |||||
| else if (secondOption != null) //we already got our second option, so we can skip | |||||
| continue; | continue; | ||||
| } | } | ||||
| var parseResult = await commands[i].ParseAsync(context, searchResult, preconditionResult).ConfigureAwait(false); | |||||
| var parseResult = await commands[i].ParseAsync(context, searchResult).ConfigureAwait(false); | |||||
| if (!parseResult.IsSuccess) | if (!parseResult.IsSuccess) | ||||
| { | { | ||||
| if (parseResult.Error == CommandError.MultipleMatches) | if (parseResult.Error == CommandError.MultipleMatches) | ||||
| @@ -284,19 +284,23 @@ namespace Discord.Commands | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (!parseResult.IsSuccess) | if (!parseResult.IsSuccess) | ||||
| { | { | ||||
| if (commands.Count == 1) | if (commands.Count == 1) | ||||
| return parseResult; | return parseResult; | ||||
| else | |||||
| else if (secondOption != null) //we already got our second option, so we can skip | |||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| return await commands[i].ExecuteAsync(context, parseResult, dependencyMap).ConfigureAwait(false); | |||||
| if (parseResult.IsSuccess && preconditionResult.IsSuccess) | |||||
| return await commands[i].ExecuteAsync(context, parseResult, dependencyMap).ConfigureAwait(false); // Perfect match and highest priority | |||||
| else if (secondOption == null && parseResult.IsSuccess) | |||||
| secondOption = preconditionResult; // It's a parse match, not perfect, but the highest priority | |||||
| } | } | ||||
| if (secondOption != null) | |||||
| return secondOption.Value; | |||||
| return SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."); | return SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."); | ||||
| } | } | ||||
| } | } | ||||
| @@ -85,13 +85,13 @@ namespace Discord.Commands | |||||
| return PreconditionResult.FromSuccess(); | return PreconditionResult.FromSuccess(); | ||||
| } | } | ||||
| public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult? preconditionResult = null) | |||||
| public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult) | |||||
| { | { | ||||
| if (!searchResult.IsSuccess) | |||||
| if (!searchResult.IsSuccess) // I think this should be removed too. Same reason as below. | |||||
| return ParseResult.FromError(searchResult); | return ParseResult.FromError(searchResult); | ||||
| if (preconditionResult != null && !preconditionResult.Value.IsSuccess) | |||||
| return ParseResult.FromError(preconditionResult.Value); | |||||
| //if (preconditionResult != null && !preconditionResult.Value.IsSuccess) Why? It could be our last hope and some preconditions removed it? | |||||
| // return ParseResult.FromError(preconditionResult.Value); Parse should parse, not check if the preconditions are okay, this is ExecuteAsync's job. | |||||
| string input = searchResult.Text.Substring(startIndex); | string input = searchResult.Text.Substring(startIndex); | ||||
| return await CommandParser.ParseArgs(this, context, input, 0).ConfigureAwait(false); | return await CommandParser.ParseArgs(this, context, input, 0).ConfigureAwait(false); | ||||
| } | } | ||||