diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 09ef467b..4d7c90de 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -18,11 +18,13 @@ namespace PluralKit.Bot { private readonly IDatabase _db; private readonly ModelRepository _repo; + private readonly EmbedService _embeds; - public Groups(IDatabase db, ModelRepository repo) + public Groups(IDatabase db, ModelRepository repo, EmbedService embeds) { _db = db; _repo = repo; + _embeds = embeds; } public async Task CreateGroup(Context ctx) @@ -282,38 +284,8 @@ namespace PluralKit.Bot public async Task ShowGroupCard(Context ctx, PKGroup target) { await using var conn = await _db.Obtain(); - var system = await GetGroupSystem(ctx, target, conn); - var pctx = ctx.LookupContextFor(system); - var memberCount = ctx.MatchPrivateFlag(pctx) ? await _repo.GetGroupMemberCount(conn, target.Id, PrivacyLevel.Public) : await _repo.GetGroupMemberCount(conn, target.Id); - - var nameField = target.Name; - if (system.Name != null) - nameField = $"{nameField} ({system.Name})"; - - var eb = new DiscordEmbedBuilder() - .WithAuthor(nameField, iconUrl: DiscordUtils.WorkaroundForUrlBug(target.IconFor(pctx))) - .WithFooter($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}"); - - if (target.DisplayName != null) - eb.AddField("Display Name", target.DisplayName); - - if (target.ListPrivacy.CanAccess(pctx)) - { - if (memberCount == 0 && pctx == LookupContext.ByOwner) - // Only suggest the add command if this is actually the owner lol - eb.AddField("Members (0)", $"Add one with `pk;group {target.Reference()} add `!", true); - else - eb.AddField($"Members ({memberCount})", $"(see `pk;group {target.Reference()} list`)", true); - } - - if (target.DescriptionFor(pctx) is {} desc) - eb.AddField("Description", desc); - - if (target.IconFor(pctx) is {} icon) - eb.WithThumbnail(icon); - - await ctx.Reply(embed: eb.Build()); + await ctx.Reply(embed: await _embeds.CreateGroupEmbed(ctx, system, target)); } public async Task AddRemoveMembers(Context ctx, PKGroup target, AddRemoveOperation op) diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index b34008d1..f9ca05bb 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -157,6 +157,42 @@ namespace PluralKit.Bot { return eb.Build(); } + public async Task CreateGroupEmbed(Context ctx, PKSystem system, PKGroup target) + { + await using var conn = await _db.Obtain(); + + var pctx = ctx.LookupContextFor(system); + var memberCount = ctx.MatchPrivateFlag(pctx) ? await _repo.GetGroupMemberCount(conn, target.Id, PrivacyLevel.Public) : await _repo.GetGroupMemberCount(conn, target.Id); + + var nameField = target.Name; + if (system.Name != null) + nameField = $"{nameField} ({system.Name})"; + + var eb = new DiscordEmbedBuilder() + .WithAuthor(nameField, iconUrl: DiscordUtils.WorkaroundForUrlBug(target.IconFor(pctx))) + .WithFooter($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}"); + + if (target.DisplayName != null) + eb.AddField("Display Name", target.DisplayName); + + if (target.ListPrivacy.CanAccess(pctx)) + { + if (memberCount == 0 && pctx == LookupContext.ByOwner) + // Only suggest the add command if this is actually the owner lol + eb.AddField("Members (0)", $"Add one with `pk;group {target.Reference()} add `!", true); + else + eb.AddField($"Members ({memberCount})", $"(see `pk;group {target.Reference()} list`)", true); + } + + if (target.DescriptionFor(pctx) is {} desc) + eb.AddField("Description", desc); + + if (target.IconFor(pctx) is {} icon) + eb.WithThumbnail(icon); + + return eb.Build(); + } + public async Task CreateFronterEmbed(PKSwitch sw, DateTimeZone zone, LookupContext ctx) { var members = await _db.Execute(c => _repo.GetSwitchMembers(c, sw.Id).ToListAsync().AsTask());