From 6223f32130d7ec8d47d828b01fa6484950ad6d9d Mon Sep 17 00:00:00 2001 From: Iris System Date: Mon, 25 Aug 2025 14:39:16 +1200 Subject: [PATCH] feat(bot): use button for cv2 cards dashboard link --- PluralKit.Bot/Services/EmbedService.cs | 67 +++++++++++++++++++++----- PluralKit.Core/CoreConfig.cs | 1 + 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 142fe7ea..d82d45cb 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -21,13 +21,15 @@ public class EmbedService private readonly IDatabase _db; private readonly ModelRepository _repo; private readonly DiscordApiClient _rest; + private readonly CoreConfig _coreConfig; - public EmbedService(IDatabase db, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest) + public EmbedService(IDatabase db, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest, CoreConfig coreConfig) { _db = db; _repo = repo; _cache = cache; _rest = rest; + _coreConfig = coreConfig; } private Task<(ulong Id, User? User)[]> GetUsers(IEnumerable ids) @@ -141,7 +143,7 @@ public class EmbedService new MessageComponent() { Type = ComponentType.Text, - Content = $"## [{systemName ?? $"`{system.DisplayHid(cctx.Config)}`"}](https://dash.pluralkit.me/profile/s/{system.Hid}){premiumText}", + Content = $"## {systemName ?? $"`{system.DisplayHid(cctx.Config)}`"}{premiumText}", }, ]; @@ -182,8 +184,21 @@ public class EmbedService }, new MessageComponent() { - Type = ComponentType.Text, - Content = $"-# System ID: `{system.DisplayHid(cctx.Config)}`\n-# Created: {system.Created.FormatZoned(cctx.Zone)}", + Type = ComponentType.Section, + Components = [ + new MessageComponent() + { + Type = ComponentType.Text, + Content = $"-# System ID: `{system.DisplayHid(cctx.Config)}`\n-# Created: {system.Created.FormatZoned(cctx.Zone)}", + }, + ], + Accessory = new MessageComponent() + { + Type = ComponentType.Button, + Style = ButtonStyle.Link, + Label = "View on dashboard", + Url = $"{_coreConfig.DashboardBaseUrl}/profile/s/{system.Hid}", + }, }, ]; } @@ -210,7 +225,7 @@ public class EmbedService .Footer(new Embed.EmbedFooter( $"System ID: {system.DisplayHid(cctx.Config)} | Created on {system.Created.FormatZoned(cctx.Zone)}")) .Color(system.Color?.ToDiscordColor()) - .Url($"https://dash.pluralkit.me/profile/s/{system.Hid}"); + .Url($"{_coreConfig.DashboardBaseUrl}/profile/s/{system.Hid}"); var avatar = system.AvatarFor(ctx); if (avatar != null) @@ -410,7 +425,7 @@ public class EmbedService new MessageComponent() { Type = ComponentType.Text, - Content = $"## [{name}](https://dash.pluralkit.me/profile/m/{member.Hid}){(systemName != null ? $" ({systemName})" : "")}", + Content = $"## {name}{(systemName != null ? $" ({systemName})" : "")}", }, ]; @@ -444,8 +459,21 @@ public class EmbedService }, new MessageComponent() { - Type = ComponentType.Text, - Content = $"-# System ID: `{system.DisplayHid(ccfg)}` \u2219 Member ID: `{member.DisplayHid(ccfg)}`{(member.MetadataPrivacy.CanAccess(ctx) ? $"\n-# Created: {member.Created.FormatZoned(zone)}" : "")}", + Type = ComponentType.Section, + Components = [ + new MessageComponent() + { + Type = ComponentType.Text, + Content = $"-# System ID: `{system.DisplayHid(ccfg)}` \u2219 Member ID: `{member.DisplayHid(ccfg)}`{(member.MetadataPrivacy.CanAccess(ctx) ? $"\n-# Created: {member.Created.FormatZoned(zone)}" : "")}", + }, + ], + Accessory = new MessageComponent() + { + Type = ComponentType.Button, + Style = ButtonStyle.Link, + Label = "View on dashboard", + Url = $"{_coreConfig.DashboardBaseUrl}/profile/m/{member.Hid}", + }, }, ]; } @@ -474,7 +502,7 @@ public class EmbedService .ToListAsync(); var eb = new EmbedBuilder() - .Author(new Embed.EmbedAuthor(name, IconUrl: webhook_avatar.TryGetCleanCdnUrl(), Url: $"https://dash.pluralkit.me/profile/m/{member.Hid}")) + .Author(new Embed.EmbedAuthor(name, IconUrl: webhook_avatar.TryGetCleanCdnUrl(), Url: $"{_coreConfig.DashboardBaseUrl}/profile/m/{member.Hid}")) // .WithColor(member.ColorPrivacy.CanAccess(ctx) ? color : null) .Color(member.Color?.ToDiscordColor()) .Footer(new Embed.EmbedFooter( @@ -584,7 +612,7 @@ public class EmbedService new MessageComponent() { Type = ComponentType.Text, - Content = $"## [{name}](https://dash.pluralkit.me/profile/g/{target.Hid}){(systemName != null ? $" ({systemName})" : "")}", + Content = $"## {name}{(systemName != null ? $" ({systemName})" : "")}", }, ]; @@ -618,8 +646,21 @@ public class EmbedService }, new MessageComponent() { - Type = ComponentType.Text, - Content = $"-# System ID: `{system.DisplayHid(ctx.Config)}` \u2219 Group ID: `{target.DisplayHid(ctx.Config)}`{(target.MetadataPrivacy.CanAccess(pctx) ? $"\n-# Created: {target.Created.FormatZoned(ctx.Zone)}" : "")}", + Type = ComponentType.Section, + Components = [ + new MessageComponent() + { + Type = ComponentType.Text, + Content = $"-# System ID: `{system.DisplayHid(ctx.Config)}` \u2219 Group ID: `{target.DisplayHid(ctx.Config)}`{(target.MetadataPrivacy.CanAccess(pctx) ? $"\n-# Created: {target.Created.FormatZoned(ctx.Zone)}" : "")}", + }, + ], + Accessory = new MessageComponent() + { + Type = ComponentType.Button, + Style = ButtonStyle.Link, + Label = "View on dashboard", + Url = $"{_coreConfig.DashboardBaseUrl}/profile/g/{target.Hid}", + }, }, ]; } @@ -649,7 +690,7 @@ public class EmbedService nameField = $"{nameField}"; var eb = new EmbedBuilder() - .Author(new Embed.EmbedAuthor(nameField, IconUrl: target.IconFor(pctx), Url: $"https://dash.pluralkit.me/profile/g/{target.Hid}")) + .Author(new Embed.EmbedAuthor(nameField, IconUrl: target.IconFor(pctx), Url: $"{_coreConfig.DashboardBaseUrl}/profile/g/{target.Hid}")) .Color(target.Color?.ToDiscordColor()); eb.Footer(new Embed.EmbedFooter($"System ID: {system.DisplayHid(ctx.Config)} | Group ID: {target.DisplayHid(ctx.Config)}{(target.MetadataPrivacy.CanAccess(pctx) ? $" | Created on {target.Created.FormatZoned(ctx.Zone)}" : "")}")); diff --git a/PluralKit.Core/CoreConfig.cs b/PluralKit.Core/CoreConfig.cs index 1e77271b..9792bc8e 100644 --- a/PluralKit.Core/CoreConfig.cs +++ b/PluralKit.Core/CoreConfig.cs @@ -16,6 +16,7 @@ public class CoreConfig public string? SeqLogUrl { get; set; } public string? DispatchProxyUrl { get; set; } public string? DispatchProxyToken { get; set; } + public string DashboardBaseUrl { get; set; } = "https://dash.pluralkit.local"; public LogEventLevel ConsoleLogLevel { get; set; } = LogEventLevel.Debug; public LogEventLevel ElasticLogLevel { get; set; } = LogEventLevel.Information;