mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Multiword aliases are once again supported
This commit is contained in:
@@ -57,30 +57,20 @@ 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;
|
||||
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 (maps.TryGetValue(word, out var alias))
|
||||
if (newInput is not null)
|
||||
{
|
||||
if (index == -1)
|
||||
newInput = alias;
|
||||
else
|
||||
newInput = alias + ' ' + input[index..];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
|
||||
@@ -93,9 +83,15 @@ public class CommandMapService : IInputTransformer, INService
|
||||
});
|
||||
});
|
||||
}
|
||||
catch { }
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return newInput;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
// var keys = maps.Keys.OrderByDescending(x => x.Length);
|
||||
// foreach (var k in keys)
|
||||
|
Reference in New Issue
Block a user