mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Fixed elipsis alias bug, closes #295
This commit is contained in:
@@ -27,7 +27,8 @@ public class CommandMapService : IInputTransformer, INService
|
||||
|
||||
AliasMaps = new(configs.ToDictionary(x => x.GuildId,
|
||||
x => new ConcurrentDictionary<string, string>(x.CommandAliases.DistinctBy(ca => ca.Trigger)
|
||||
.ToDictionary(ca => ca.Trigger, ca => ca.Mapping))));
|
||||
.ToDictionary(ca => ca.Trigger, ca => ca.Mapping),
|
||||
StringComparer.OrdinalIgnoreCase)));
|
||||
|
||||
_db = db;
|
||||
}
|
||||
@@ -45,6 +46,7 @@ public class CommandMapService : IInputTransformer, INService
|
||||
return count;
|
||||
}
|
||||
|
||||
// todo bank take all
|
||||
public async Task<string> TransformInput(
|
||||
IGuild guild,
|
||||
IMessageChannel channel,
|
||||
@@ -53,37 +55,76 @@ public class CommandMapService : IInputTransformer, INService
|
||||
{
|
||||
if (guild is null || string.IsNullOrWhiteSpace(input))
|
||||
return null;
|
||||
|
||||
|
||||
if (AliasMaps.TryGetValue(guild.Id, out var maps))
|
||||
{
|
||||
var keys = maps.Keys.OrderByDescending(x => x.Length);
|
||||
|
||||
foreach (var k in keys)
|
||||
string word;
|
||||
var index = input.IndexOf(' ', StringComparison.InvariantCulture);
|
||||
if (index == -1)
|
||||
{
|
||||
string newInput;
|
||||
if (input.StartsWith(k + " ", StringComparison.InvariantCultureIgnoreCase))
|
||||
newInput = maps[k] + input.Substring(k.Length, input.Length - k.Length);
|
||||
else if (input.Equals(k, StringComparison.InvariantCultureIgnoreCase))
|
||||
newInput = maps[k];
|
||||
else
|
||||
continue;
|
||||
|
||||
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;
|
||||
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 () =>
|
||||
{
|
||||
await Task.Delay(1500);
|
||||
await toDelete.DeleteAsync(new()
|
||||
{
|
||||
RetryMode = RetryMode.AlwaysRetry
|
||||
});
|
||||
});
|
||||
}
|
||||
catch { }
|
||||
|
||||
return newInput;
|
||||
|
||||
// var keys = maps.Keys.OrderByDescending(x => x.Length);
|
||||
// foreach (var k in keys)
|
||||
// {
|
||||
// string newInput;
|
||||
// if (input.StartsWith(k + " ", StringComparison.InvariantCultureIgnoreCase))
|
||||
// newInput = maps[k] + input.Substring(k.Length, input.Length - k.Length);
|
||||
// else if (input.Equals(k, StringComparison.InvariantCultureIgnoreCase))
|
||||
// newInput = maps[k];
|
||||
// else
|
||||
// continue;
|
||||
//
|
||||
// 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;
|
||||
|
Reference in New Issue
Block a user