From 91fdf2a7136edd241e5422dff9045d7192840fce Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Tue, 21 Feb 2017 16:41:50 +0100 Subject: [PATCH 1/2] Fix [Priority] behaving inverse to spec. --- src/Discord.Net.Commands/CommandService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 2c7955028..300000b16 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -223,13 +223,13 @@ namespace Discord.Commands } //Execution - public SearchResult Search(ICommandContext context, int argPos) + public SearchResult Search(ICommandContext context, int argPos) => Search(context, context.Message.Content.Substring(argPos)); public SearchResult Search(ICommandContext context, string input) { string searchInput = _caseSensitive ? input : input.ToLowerInvariant(); - var matches = _map.GetCommands(searchInput).OrderByDescending(x => x.Command.Priority).ToImmutableArray(); - + var matches = _map.GetCommands(searchInput).OrderBy(x => x.Command.Priority).ToImmutableArray(); + if (matches.Length > 0) return SearchResult.FromSuccess(input, matches); else From b28fd87e268f480e76b0d65dad7e56d4dd313f40 Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Tue, 21 Feb 2017 16:50:49 +0100 Subject: [PATCH 2/2] Add comment explaining behavior --- src/Discord.Net.Commands/CommandService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 300000b16..dd47e456d 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -228,6 +228,8 @@ namespace Discord.Commands public SearchResult Search(ICommandContext context, string input) { string searchInput = _caseSensitive ? input : input.ToLowerInvariant(); + + // We sort by Ascending priority here because the collection is looped over backwards later. var matches = _map.GetCommands(searchInput).OrderBy(x => x.Command.Priority).ToImmutableArray(); if (matches.Length > 0)