Multiword aliases are once again supported

This commit is contained in:
Kwoth
2022-07-05 18:08:11 +02:00
parent 9d3e80eb32
commit fd25f5bf45

View File

@@ -57,30 +57,20 @@ public class CommandMapService : IInputTransformer, INService
if (AliasMaps.TryGetValue(guild.Id, out var maps)) if (AliasMaps.TryGetValue(guild.Id, out var maps))
{ {
string word; string newInput = null;
var index = input.IndexOf(' ', StringComparison.InvariantCulture); foreach (var (k, v) in maps)
if (index == -1)
{ {
word = input; if (string.Equals(input, k, StringComparison.OrdinalIgnoreCase))
{
newInput = v;
} }
else else if (input.StartsWith(k + ' ', StringComparison.OrdinalIgnoreCase))
{ {
word = input[..index]; newInput = v + ' ' + input[k.Length..];
} }
string newInput; if (newInput is not null)
if (maps.TryGetValue(word, out var alias))
{ {
if (index == -1)
newInput = alias;
else
newInput = alias + ' ' + input[index..];
}
else
{
return null;
}
try try
{ {
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}"); var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
@@ -93,9 +83,15 @@ public class CommandMapService : IInputTransformer, INService
}); });
}); });
} }
catch { } catch
{
}
return newInput; return newInput;
}
}
return null;
// var keys = maps.Keys.OrderByDescending(x => x.Length); // var keys = maps.Keys.OrderByDescending(x => x.Length);
// foreach (var k in keys) // foreach (var k in keys)