diff --git a/src/Discord.Net.Commands/CommandMatch.cs b/src/Discord.Net.Commands/CommandMatch.cs index 6e78b8509..84c79a596 100644 --- a/src/Discord.Net.Commands/CommandMatch.cs +++ b/src/Discord.Net.Commands/CommandMatch.cs @@ -16,8 +16,8 @@ namespace Discord.Commands public Task CheckPreconditionsAsync(ICommandContext context, IDependencyMap map = null) => Command.CheckPreconditionsAsync(context, map); - public Task ParseAsync(ICommandContext context, SearchResult searchResult, PreconditionResult? preconditionResult = null) - => Command.ParseAsync(context, Alias.Length, searchResult, preconditionResult); + public Task ParseAsync(ICommandContext context, SearchResult searchResult) + => Command.ParseAsync(context, Alias.Length, searchResult); public Task ExecuteAsync(ICommandContext context, IEnumerable argList, IEnumerable paramList, IDependencyMap map) => Command.ExecuteAsync(context, argList, paramList, map); public Task ExecuteAsync(ICommandContext context, ParseResult parseResult, IDependencyMap map) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 0d27bd178..ba8af97f6 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -245,6 +245,7 @@ namespace Discord.Commands if (!searchResult.IsSuccess) return searchResult; + PreconditionResult? secondOption = null; var commands = searchResult.Commands; for (int i = commands.Count - 1; i >= 0; i--) { @@ -253,11 +254,10 @@ namespace Discord.Commands { if (commands.Count == 1) return preconditionResult; - else + else if (secondOption != null) //we already got our last hope, so we can skip 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.Error == CommandError.MultipleMatches) @@ -272,19 +272,23 @@ namespace Discord.Commands break; } } - if (!parseResult.IsSuccess) { if (commands.Count == 1) return parseResult; - else + else if (secondOption != null) //we already got our last hope, so we can skip 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; return SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."); } } diff --git a/src/Discord.Net.Commands/Info/CommandInfo.cs b/src/Discord.Net.Commands/Info/CommandInfo.cs index 031d37581..c65d8b8d6 100644 --- a/src/Discord.Net.Commands/Info/CommandInfo.cs +++ b/src/Discord.Net.Commands/Info/CommandInfo.cs @@ -85,13 +85,13 @@ namespace Discord.Commands return PreconditionResult.FromSuccess(); } - public async Task ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult? preconditionResult = null) + public async Task 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); - 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); return await CommandParser.ParseArgs(this, context, input, 0).ConfigureAwait(false); }