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,
|
AliasMaps = new(configs.ToDictionary(x => x.GuildId,
|
||||||
x => new ConcurrentDictionary<string, string>(x.CommandAliases.DistinctBy(ca => ca.Trigger)
|
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;
|
_db = db;
|
||||||
}
|
}
|
||||||
@@ -45,6 +46,7 @@ public class CommandMapService : IInputTransformer, INService
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo bank take all
|
||||||
public async Task<string> TransformInput(
|
public async Task<string> TransformInput(
|
||||||
IGuild guild,
|
IGuild guild,
|
||||||
IMessageChannel channel,
|
IMessageChannel channel,
|
||||||
@@ -53,37 +55,76 @@ public class CommandMapService : IInputTransformer, INService
|
|||||||
{
|
{
|
||||||
if (guild is null || string.IsNullOrWhiteSpace(input))
|
if (guild is null || string.IsNullOrWhiteSpace(input))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (AliasMaps.TryGetValue(guild.Id, out var maps))
|
if (AliasMaps.TryGetValue(guild.Id, out var maps))
|
||||||
{
|
{
|
||||||
var keys = maps.Keys.OrderByDescending(x => x.Length);
|
string word;
|
||||||
|
var index = input.IndexOf(' ', StringComparison.InvariantCulture);
|
||||||
foreach (var k in keys)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
string newInput;
|
word = input;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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;
|
return null;
|
||||||
|
Reference in New Issue
Block a user