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,45 +57,41 @@ 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))
}
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 () =>
{ {
await Task.Delay(1500); newInput = v;
await toDelete.DeleteAsync(new() }
{ else if (input.StartsWith(k + ' ', StringComparison.OrdinalIgnoreCase))
RetryMode = RetryMode.AlwaysRetry {
}); newInput = v + ' ' + input[k.Length..];
}); }
}
catch { }
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); // var keys = maps.Keys.OrderByDescending(x => x.Length);
// foreach (var k in keys) // foreach (var k in keys)