mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Aliases now support %target% placeholder. For example 'alias .bft .bf %target% t'
This commit is contained in:
@@ -9,7 +9,7 @@ namespace NadekoBot.Modules.Utility;
|
|||||||
public partial class Utility
|
public partial class Utility
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class CommandMapCommands : NadekoModule<CommandMapService>
|
public partial class CommandMapCommands : NadekoModule<AliasService>
|
||||||
{
|
{
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
@@ -6,15 +6,14 @@ using NadekoBot.Services.Database.Models;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Utility.Services;
|
namespace NadekoBot.Modules.Utility.Services;
|
||||||
|
|
||||||
public class CommandMapService : IInputTransformer, INService
|
public class AliasService : IInputTransformer, INService
|
||||||
{
|
{
|
||||||
public ConcurrentDictionary<ulong, ConcurrentDictionary<string, string>> AliasMaps { get; } = new();
|
public ConcurrentDictionary<ulong, ConcurrentDictionary<string, string>> AliasMaps { get; } = new();
|
||||||
private readonly IEmbedBuilderService _eb;
|
private readonly IEmbedBuilderService _eb;
|
||||||
|
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
|
|
||||||
//commandmap
|
public AliasService(DiscordSocketClient client, DbService db, IEmbedBuilderService eb)
|
||||||
public CommandMapService(DiscordSocketClient client, DbService db, IEmbedBuilderService eb)
|
|
||||||
{
|
{
|
||||||
_eb = eb;
|
_eb = eb;
|
||||||
|
|
||||||
@@ -66,7 +65,10 @@ public class CommandMapService : IInputTransformer, INService
|
|||||||
}
|
}
|
||||||
else if (input.StartsWith(k + ' ', StringComparison.OrdinalIgnoreCase))
|
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)
|
if (newInput is not null)
|
||||||
@@ -74,17 +76,11 @@ public class CommandMapService : IInputTransformer, INService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
|
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
|
||||||
_ = Task.Run(async () =>
|
toDelete.DeleteAfter(1.5f);
|
||||||
{
|
|
||||||
await Task.Delay(1500);
|
|
||||||
await toDelete.DeleteAsync(new()
|
|
||||||
{
|
|
||||||
RetryMode = RetryMode.AlwaysRetry
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
return newInput;
|
return newInput;
|
||||||
@@ -92,34 +88,6 @@ public class CommandMapService : IInputTransformer, INService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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;
|
return null;
|
@@ -144,11 +144,11 @@ public static class Extensions
|
|||||||
public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb)
|
public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb)
|
||||||
=> eb.WithColor(EmbedColor.Error);
|
=> 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 () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(seconds * 1000);
|
await Task.Delay((int)(seconds * 1000));
|
||||||
if (logService is not null)
|
if (logService is not null)
|
||||||
logService.AddDeleteIgnore(msg.Id);
|
logService.AddDeleteIgnore(msg.Id);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user