- 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

@@ -66,13 +66,13 @@ namespace NadekoBot.Modules.Permissions
if (pageItems.Count == 0)
{
return new EmbedBuilder()
return _eb.Create()
.WithOkColor()
.WithTitle(title)
.WithDescription(GetText("empty_page"));
}
return new EmbedBuilder()
return _eb.Create()
.WithTitle(title)
.WithDescription(pageItems.JoinWith('\n'))
.WithOkColor();

View File

@@ -287,7 +287,7 @@ namespace NadekoBot.Modules.Permissions
var fws = fwHash.ToArray();
await ctx.SendPaginatedConfirmAsync(page,
(curPage) => new EmbedBuilder()
(curPage) => _eb.Create()
.WithTitle(GetText("filter_word_list"))
.WithDescription(string.Join("\n", fws.Skip(curPage * 10).Take(10)))
.WithOkColor()

View File

@@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Permissions
return;
}
var embed = new EmbedBuilder().WithOkColor();
var embed = _eb.Create().WithOkColor();
if (blockedModule.Any())
embed.AddField(GetText("blocked_modules")

View File

@@ -12,7 +12,6 @@ using NadekoBot.Modules.Permissions.Common;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;
using NadekoBot.Modules.Administration;
namespace NadekoBot.Modules.Permissions.Services
{
@@ -23,20 +22,27 @@ namespace NadekoBot.Modules.Permissions.Services
private readonly DbService _db;
private readonly CommandHandler _cmd;
private readonly IBotStrings _strings;
private readonly IEmbedBuilderService _eb;
//guildid, root permission
public ConcurrentDictionary<ulong, PermissionCache> Cache { get; } =
new ConcurrentDictionary<ulong, PermissionCache>();
public PermissionService(DiscordSocketClient client, DbService db, CommandHandler cmd, IBotStrings strings)
public PermissionService(DiscordSocketClient client,
DbService db,
CommandHandler cmd,
IBotStrings strings,
IEmbedBuilderService eb)
{
_db = db;
_cmd = cmd;
_strings = strings;
_eb = eb;
using (var uow = _db.GetDbContext())
{
foreach (var x in uow.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id).ToList()))
foreach (var x in uow.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id)
.ToList()))
{
Cache.TryAdd(x.GuildId, new PermissionCache()
{
@@ -122,7 +128,8 @@ namespace NadekoBot.Modules.Permissions.Services
{
try
{
await channel.SendErrorAsync(_strings.GetText("perm_prevent", guild.Id, index + 1,
await channel.SendErrorAsync(_eb,
_strings.GetText("perm_prevent", guild.Id, index + 1,
Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild) guild))))
.ConfigureAwait(false);
}
@@ -152,7 +159,7 @@ namespace NadekoBot.Modules.Permissions.Services
{
returnMsg = $"You need Admin permissions in order to use permission commands.";
if (pc.Verbose)
try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { }
try { await channel.SendErrorAsync(_eb, returnMsg).ConfigureAwait(false); } catch { }
return true;
}
@@ -160,7 +167,7 @@ namespace NadekoBot.Modules.Permissions.Services
{
returnMsg = $"You need the {Format.Bold(role.Name)} role in order to use permission commands.";
if (pc.Verbose)
try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { }
try { await channel.SendErrorAsync(_eb, returnMsg).ConfigureAwait(false); } catch { }
return true;
}