diff --git a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs b/src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs index dea5552ee..92761ae9f 100644 --- a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs +++ b/src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs @@ -57,45 +57,41 @@ public class CommandMapService : IInputTransformer, INService if (AliasMaps.TryGetValue(guild.Id, out var maps)) { - string word; - var index = input.IndexOf(' ', StringComparison.InvariantCulture); - if (index == -1) + string newInput = null; + foreach (var (k, v) in maps) { - word = input; - } - else - { - word = input[..index]; - } - - string newInput; - if (maps.TryGetValue(word, out var alias)) - { - if (index == -1) - newInput = alias; - else - newInput = alias + ' ' + input[index..]; - } - else - { - return null; - } - - try - { - var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}"); - _ = Task.Run(async () => + if (string.Equals(input, k, StringComparison.OrdinalIgnoreCase)) { - await Task.Delay(1500); - await toDelete.DeleteAsync(new() - { - RetryMode = RetryMode.AlwaysRetry - }); - }); - } - catch { } + newInput = v; + } + else if (input.StartsWith(k + ' ', StringComparison.OrdinalIgnoreCase)) + { + newInput = v + ' ' + input[k.Length..]; + } - return newInput; + if (newInput is not null) + { + try + { + var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}"); + _ = Task.Run(async () => + { + await Task.Delay(1500); + await toDelete.DeleteAsync(new() + { + RetryMode = RetryMode.AlwaysRetry + }); + }); + } + catch + { + } + + return newInput; + } + } + + return null; // var keys = maps.Keys.OrderByDescending(x => x.Length); // foreach (var k in keys)