- Reworked embed builder

- Use IEmbedBuilderService to create embed builders
- Wrapped embed builder and using IEmbedBuilder
This commit is contained in:
Kwoth
2021-07-09 22:23:19 +02:00
parent 5b4daa9dd3
commit 5e4754fa40
103 changed files with 730 additions and 540 deletions

View File

@@ -41,7 +41,7 @@ namespace NadekoBot.Modules.CustomReactions
var cr = await _service.AddAsync(ctx.Guild?.Id, key, message);
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText("new_cust_react"))
.WithDescription($"#{(kwum)cr.Id}")
.AddField(GetText("trigger"), key)
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.CustomReactions
var cr = await _service.EditAsync(ctx.Guild?.Id, (int)id, message).ConfigureAwait(false);
if (cr != null)
{
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText("edited_cust_react"))
.WithDescription($"#{id}")
.AddField(GetText("trigger"), cr.Trigger)
@@ -107,7 +107,7 @@ namespace NadekoBot.Modules.CustomReactions
: " // " + string.Join(" ", cr.GetReactions())))
.JoinWith('\n');
return new EmbedBuilder().WithOkColor()
return _eb.Create().WithOkColor()
.WithTitle(GetText("custom_reactions"))
.WithDescription(desc);
@@ -146,7 +146,7 @@ namespace NadekoBot.Modules.CustomReactions
}
else
{
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithDescription($"#{id}")
.AddField(GetText("trigger"), found.Trigger.TrimTo(1024))
.AddField(GetText("response"), (found.Response + "\n```css\n" + found.Response).TrimTo(1020) + "```")
@@ -167,7 +167,7 @@ namespace NadekoBot.Modules.CustomReactions
if (cr != null)
{
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText("deleted"))
.WithDescription($"#{id}")
.AddField(GetText("trigger"), cr.Trigger.TrimTo(1024))
@@ -289,7 +289,7 @@ namespace NadekoBot.Modules.CustomReactions
[UserPerm(GuildPerm.Administrator)]
public async Task CrClear()
{
if (await PromptUserConfirmAsync(new EmbedBuilder()
if (await PromptUserConfirmAsync(_eb.Create()
.WithTitle("Custom reaction clear")
.WithDescription("This will delete all custom reactions on this server.")).ConfigureAwait(false))
{

View File

@@ -12,6 +12,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NadekoBot.Services;
namespace NadekoBot.Modules.CustomReactions.Extensions
{
@@ -95,7 +96,7 @@ namespace NadekoBot.Modules.CustomReactions.Extensions
containsAnywhere);
public static async Task<IUserMessage> Send(this CustomReaction cr, IUserMessage ctx,
DiscordSocketClient client, bool sanitize)
DiscordSocketClient client, IEmbedBuilderService eb, bool sanitize)
{
var channel = cr.DmResponse
? await ctx.Author.GetOrCreateDMChannelAsync().ConfigureAwait(false)
@@ -127,7 +128,7 @@ namespace NadekoBot.Modules.CustomReactions.Extensions
rep.Replace(crembed);
return await channel.EmbedAsync(crembed, sanitize).ConfigureAwait(false);
return await channel.EmbedAsync(crembed, eb, sanitize).ConfigureAwait(false);
}
return await channel

View File

@@ -59,11 +59,12 @@ namespace NadekoBot.Modules.CustomReactions.Services
private readonly GlobalPermissionService _gperm;
private readonly CmdCdService _cmdCds;
private readonly IPubSub _pubSub;
private readonly IEmbedBuilderService _eb;
private readonly Random _rng;
public CustomReactionsService(PermissionService perms, DbService db, IBotStrings strings, Bot bot,
DiscordSocketClient client, CommandHandler cmd, GlobalPermissionService gperm, CmdCdService cmdCds,
IPubSub pubSub)
IPubSub pubSub, IEmbedBuilderService eb)
{
_db = db;
_client = client;
@@ -74,6 +75,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
_gperm = gperm;
_cmdCds = cmdCds;
_pubSub = pubSub;
_eb = eb;
_rng = new NadekoRandom();
_pubSub.Sub(_crsReloadedKey, OnCrsShouldReload);
@@ -414,7 +416,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), sg)));
try
{
await msg.Channel.SendErrorAsync(returnMsg).ConfigureAwait(false);
await msg.Channel.SendErrorAsync(_eb, returnMsg).ConfigureAwait(false);
}
catch
{
@@ -427,7 +429,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
}
}
var sentMsg = await cr.Send(msg, _client, false).ConfigureAwait(false);
var sentMsg = await cr.Send(msg, _client, _eb, false).ConfigureAwait(false);
var reactions = cr.GetReactions();
foreach (var reaction in reactions)