diff --git a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs b/src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs similarity index 98% rename from src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs rename to src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs index 2b0976428..c66286633 100644 --- a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapCommands.cs +++ b/src/NadekoBot/Modules/Utility/Alias/AliasCommands.cs @@ -9,7 +9,7 @@ namespace NadekoBot.Modules.Utility; public partial class Utility { [Group] - public partial class CommandMapCommands : NadekoModule + public partial class CommandMapCommands : NadekoModule { private readonly DbService _db; private readonly DiscordSocketClient _client; diff --git a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs b/src/NadekoBot/Modules/Utility/Alias/AliasService.cs similarity index 59% rename from src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs rename to src/NadekoBot/Modules/Utility/Alias/AliasService.cs index 92761ae9f..e48c6a0c0 100644 --- a/src/NadekoBot/Modules/Utility/CommandMap/CommandMapService.cs +++ b/src/NadekoBot/Modules/Utility/Alias/AliasService.cs @@ -6,15 +6,14 @@ using NadekoBot.Services.Database.Models; namespace NadekoBot.Modules.Utility.Services; -public class CommandMapService : IInputTransformer, INService +public class AliasService : IInputTransformer, INService { public ConcurrentDictionary> AliasMaps { get; } = new(); private readonly IEmbedBuilderService _eb; private readonly DbService _db; - //commandmap - public CommandMapService(DiscordSocketClient client, DbService db, IEmbedBuilderService eb) + public AliasService(DiscordSocketClient client, DbService db, IEmbedBuilderService eb) { _eb = eb; @@ -66,7 +65,10 @@ public class CommandMapService : IInputTransformer, INService } else if (input.StartsWith(k + ' ', StringComparison.OrdinalIgnoreCase)) { - newInput = v + ' ' + input[k.Length..]; + if (v.Contains("%target%")) + newInput = v.Replace("%target%", input[k.Length..]); + else + newInput = v + ' ' + input[k.Length..]; } if (newInput is not null) @@ -74,17 +76,11 @@ public class CommandMapService : IInputTransformer, INService try { var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}"); - _ = Task.Run(async () => - { - await Task.Delay(1500); - await toDelete.DeleteAsync(new() - { - RetryMode = RetryMode.AlwaysRetry - }); - }); + toDelete.DeleteAfter(1.5f); } catch { + // ignored } return newInput; @@ -92,34 +88,6 @@ public class CommandMapService : IInputTransformer, INService } return null; - - // 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; diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 113bee4ff..dfb6c7c9e 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -144,11 +144,11 @@ public static class Extensions public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb) => eb.WithColor(EmbedColor.Error); - public static IMessage DeleteAfter(this IUserMessage msg, int seconds, ILogCommandService? logService = null) + public static IMessage DeleteAfter(this IUserMessage msg, float seconds, ILogCommandService? logService = null) { Task.Run(async () => { - await Task.Delay(seconds * 1000); + await Task.Delay((int)(seconds * 1000)); if (logService is not null) logService.AddDeleteIgnore(msg.Id);