mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
- Fixed calls to SendAsync - they don't require EmbedBuilderService
- DmHelpText now uses smarttext and supports user-related placeholders
This commit is contained in:
@@ -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);
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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]
|
||||
|
@@ -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]
|
||||
|
@@ -35,6 +35,22 @@ namespace NadekoBot.Extensions
|
||||
public static TOut[] Map<TIn, TOut>(this TIn[] arr, Func<TIn, TOut> 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<IUserMessage> 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<IUserMessage> SendAsync(this IMessageChannel channel, IEmbedBuilderService eb, SmartText text, bool sanitizeAll = false)
|
||||
public static Task<IUserMessage> 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))
|
||||
};
|
||||
|
Reference in New Issue
Block a user