diff --git a/src/NadekoBot/Common/SmartText/SmartEmbedText.cs b/src/NadekoBot/Common/SmartText/SmartEmbedText.cs index dd9f1f71e..35c84a97f 100644 --- a/src/NadekoBot/Common/SmartText/SmartEmbedText.cs +++ b/src/NadekoBot/Common/SmartText/SmartEmbedText.cs @@ -29,7 +29,7 @@ namespace NadekoBot (Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) || (Fields != null && Fields.Length > 0); - public EmbedBuilder GetEmbed(IEmbedBuilderService eb) + public EmbedBuilder GetEmbed() { var embed = new EmbedBuilder() .WithColor(Color); diff --git a/src/NadekoBot/Modules/Administration/SelfCommands.cs b/src/NadekoBot/Modules/Administration/SelfCommands.cs index c6f5cf49e..5166b7e8e 100644 --- a/src/NadekoBot/Modules/Administration/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfCommands.cs @@ -469,7 +469,7 @@ namespace NadekoBot.Modules.Administration return; text = rep.Replace(text); - await ch.SendAsync(_eb, text, sanitizeAll: false); + await ch.SendAsync(text, sanitizeAll: false); } else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture)) { @@ -480,7 +480,7 @@ namespace NadekoBot.Modules.Administration var ch = await user.GetOrCreateDMChannelAsync(); text = rep.Replace(text); - await ch.SendAsync(_eb, text); + await ch.SendAsync(text); } else { diff --git a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs index 463d02093..3958c1624 100644 --- a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs @@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Administration.Services } } - public async Task EditMessage(ICommandContext context, ITextChannel chanl, ulong messageId, string text) + public async Task EditMessage(ICommandContext context, ITextChannel chanl, ulong messageId, string input) { var msg = await chanl.GetMessageAsync(messageId); @@ -167,23 +167,10 @@ namespace NadekoBot.Modules.Administration.Services .WithDefault(context) .Build(); - if (CREmbed.TryParse(text, out var crembed)) - { - rep.Replace(crembed); - await umsg.ModifyAsync(x => - { - x.Embed = crembed.ToEmbed(_eb).Build(); - x.Content = crembed.PlainText?.SanitizeMentions() ?? ""; - }).ConfigureAwait(false); - } - else - { - await umsg.ModifyAsync(x => - { - x.Content = text.SanitizeMentions(); - x.Embed = null; - }).ConfigureAwait(false); - } + var text = SmartText.CreateFrom(input); + text = rep.Replace(text); + + await umsg.EditAsync(text); } } } diff --git a/src/NadekoBot/Modules/Help/Services/HelpService.cs b/src/NadekoBot/Modules/Help/Services/HelpService.cs index 9c186e7e4..c97a3a0ed 100644 --- a/src/NadekoBot/Modules/Help/Services/HelpService.cs +++ b/src/NadekoBot/Modules/Help/Services/HelpService.cs @@ -23,7 +23,6 @@ namespace NadekoBot.Modules.Help.Services private readonly DiscordPermOverrideService _dpos; private readonly BotConfigService _bss; private readonly IEmbedBuilderService _eb; - private readonly Replacer _rep; public HelpService(CommandHandler ch, IBotStrings strings, @@ -36,12 +35,6 @@ namespace NadekoBot.Modules.Help.Services _dpos = dpos; _bss = bss; _eb = eb; - - - _rep = new ReplacementBuilder() - .WithOverride("%prefix%", () => _bss.Data.Prefix) - .WithOverride("%bot.prefix%", () => _bss.Data.Prefix) - .Build(); } public Task LateExecute(IGuild guild, IUserMessage msg) @@ -51,11 +44,17 @@ namespace NadekoBot.Modules.Help.Services { if (string.IsNullOrWhiteSpace(settings.DmHelpText) || settings.DmHelpText == "-") return Task.CompletedTask; + + var rep = new ReplacementBuilder() + .WithOverride("%prefix%", () => _bss.Data.Prefix) + .WithOverride("%bot.prefix%", () => _bss.Data.Prefix) + .WithUser(msg.Author) + .Build(); - if (CREmbed.TryParse(settings.DmHelpText, out var embed)) - return msg.Channel.EmbedAsync(_rep.Replace(embed), _eb); - - return msg.Channel.SendMessageAsync(_rep.Replace(settings.DmHelpText)); + var text = SmartText.CreateFrom(settings.DmHelpText); + text = rep.Replace(text); + + return msg.Channel.SendAsync(text); } return Task.CompletedTask; } diff --git a/src/NadekoBot/Modules/Utility/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/QuoteCommands.cs index 0192eed94..5bf760727 100644 --- a/src/NadekoBot/Modules/Utility/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/QuoteCommands.cs @@ -85,7 +85,7 @@ namespace NadekoBot.Modules.Utility var text = SmartText.CreateFrom(quote.Text); text = rep.Replace(text); - await ctx.Channel.SendAsync(_eb, $"`#{quote.Id}` 📣 " + text, true); + await ctx.Channel.SendAsync($"`#{quote.Id}` 📣 " + text, true); } [NadekoCommand, Aliases] @@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Utility var text = SmartText.CreateFrom(quote.Text); text = rep.Replace(text); - await ctx.Channel.SendAsync(_eb, infoText + text, true); + await ctx.Channel.SendAsync(infoText + text, true); } [NadekoCommand, Aliases] diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 6102a74ba..5e7bab824 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Utility message = rep.Replace(message); - await channel.SendAsync(_eb, message, !((IGuildUser)Context.User).GuildPermissions.MentionEveryone); + await channel.SendAsync(message, !((IGuildUser)Context.User).GuildPermissions.MentionEveryone); } [NadekoCommand, Aliases] diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 7819d78f4..977c865ee 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -35,6 +35,22 @@ namespace NadekoBot.Extensions public static TOut[] Map(this TIn[] arr, Func f) => Array.ConvertAll(arr, x => f(x)); + public static Task EditAsync(this IUserMessage msg, SmartText text) + => text switch + { + SmartEmbedText set => msg.ModifyAsync(x => + { + x.Embed = set.GetEmbed().Build(); + x.Content = set.PlainText?.SanitizeMentions() ?? ""; + }), + SmartPlainText spt => msg.ModifyAsync(x => + { + x.Content = spt.Text.SanitizeMentions(); + x.Embed = null; + }), + _ => throw new ArgumentOutOfRangeException(nameof(text)) + }; + public static Task SendAsync(this IMessageChannel channel, string plainText, Embed embed, bool sanitizeAll = false) { plainText = sanitizeAll @@ -44,10 +60,10 @@ namespace NadekoBot.Extensions return channel.SendMessageAsync(plainText, embed: embed); } - public static Task SendAsync(this IMessageChannel channel, IEmbedBuilderService eb, SmartText text, bool sanitizeAll = false) + public static Task SendAsync(this IMessageChannel channel, SmartText text, bool sanitizeAll = false) => text switch { - SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed(eb).Build(), sanitizeAll), + SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed().Build(), sanitizeAll), SmartPlainText st => channel.SendAsync(st.Text, null, sanitizeAll), _ => throw new ArgumentOutOfRangeException(nameof(text)) };