From 9d80b7b141285869aec6155676b34b9984da3182 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Tue, 9 Feb 2021 23:36:43 +0100 Subject: [PATCH 1/9] Add group front percentages Also add a title to the system frontpercent embed, and tweak the footer --- PluralKit.Bot/Commands/CommandTree.cs | 5 +++- PluralKit.Bot/Commands/Groups.cs | 27 +++++++++++++++++++ PluralKit.Bot/Commands/SystemFront.cs | 10 +++++-- PluralKit.Bot/Services/EmbedService.cs | 5 ++-- .../Repository/ModelRepository.Switch.cs | 15 ++++++++--- PluralKit.Core/Services/DataFileService.cs | 2 +- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index f418d784..cfd59279 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -60,6 +60,7 @@ namespace PluralKit.Bot public static Command GroupPrivacy = new Command("group privacy", "group privacy ", "Changes a group's privacy settings"); public static Command GroupIcon = new Command("group icon", "group icon [url|@mention]", "Changes a group's icon"); public static Command GroupDelete = new Command("group delete", "group delete", "Deletes a group"); + public static Command GroupFrontPercent = new Command("group frontpercent", "group frontpercent [timespan]", "Shows a group's front breakdown."); public static Command GroupMemberRandom = new Command("group random", "group random", "Shows the info card of a randomly selected member in a group."); public static Command GroupRandom = new Command("random", "random group", "Shows the info card of a randomly selected group in your system."); public static Command Switch = new Command("switch", "switch [member 2] [member 3...]", "Registers a switch"); @@ -107,7 +108,7 @@ namespace PluralKit.Bot public static Command[] GroupCommandsTargeted = { GroupInfo, GroupAdd, GroupRemove, GroupMemberList, GroupRename, GroupDesc, GroupIcon, GroupPrivacy, - GroupDelete, GroupMemberRandom + GroupDelete, GroupMemberRandom, GroupFrontPercent }; public static Command[] SwitchCommands = {Switch, SwitchOut, SwitchMove, SwitchDelete, SwitchDeleteAll}; @@ -397,6 +398,8 @@ namespace PluralKit.Bot await ctx.Execute(GroupDelete, g => g.DeleteGroup(ctx, target)); else if (ctx.Match("avatar", "picture", "icon", "image", "pic", "pfp")) await ctx.Execute(GroupIcon, g => g.GroupIcon(ctx, target)); + else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown")) + await ctx.Execute(GroupFrontPercent, g => g.GroupFrontPercent(ctx, target)); else if (!ctx.HasNext()) await ctx.Execute(GroupInfo, g => g.ShowGroupCard(ctx, target)); else diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index ce93f8fe..4259dff8 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -8,6 +8,8 @@ using Dapper; using Humanizer; +using NodaTime; + using Myriad.Builders; using PluralKit.Core; @@ -428,6 +430,31 @@ namespace PluralKit.Bot await ctx.Reply($"{Emojis.Success} Group deleted."); } + public async Task GroupFrontPercent(Context ctx, PKGroup target) + { + await using var conn = await _db.Obtain(); + + var targetSystem = await GetGroupSystem(ctx, target, conn); + ctx.CheckSystemPrivacy(targetSystem, targetSystem.FrontHistoryPrivacy); + + string durationStr = ctx.RemainderOrNull() ?? "30d"; + + var now = SystemClock.Instance.GetCurrentInstant(); + + var rangeStart = DateUtils.ParseDateTime(durationStr, true, targetSystem.Zone); + if (rangeStart == null) throw Errors.InvalidDateTime(durationStr); + if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture; + + var title = new StringBuilder($"Frontpercent of {target.DisplayName ?? target.Name} (`{target.Hid}`) in "); + if (targetSystem.Name != null) + title.Append($"{targetSystem.Name} (`{targetSystem.Hid}`)"); + else + title.Append($"`{targetSystem.Hid}`"); + + var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, targetSystem.Id, target.Id, rangeStart.Value.ToInstant(), now)); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target, targetSystem.Zone, ctx.LookupContextFor(targetSystem), title.ToString())); + } + private async Task GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn) { var system = ctx.System; diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 3f8cbc0b..d9531216 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -124,8 +124,14 @@ namespace PluralKit.Bot if (rangeStart == null) throw Errors.InvalidDateTime(durationStr); if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture; - var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system.Zone, ctx.LookupContextFor(system))); + var title = new StringBuilder($"Frontpercent of "); + if (system.Name != null) + title.Append($"{system.Name} (`{system.Hid}`)"); + else + title.Append($"`{system.Hid}`"); + + var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, null, rangeStart.Value.ToInstant(), now)); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString())); } } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index fd0a971a..5528f1cf 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -293,12 +293,13 @@ namespace PluralKit.Bot { return eb.Build(); } - public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, DateTimeZone tz, LookupContext ctx) + public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle) { var actualPeriod = breakdown.RangeEnd - breakdown.RangeStart; var eb = new EmbedBuilder() + .Title(embedTitle) .Color(DiscordUtils.Gray) - .Footer(new($"Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)")); + .Footer(new($"System ID: {system.Hid} | {(group != null ? $"Group ID: {group.Hid} | " : "") }Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)")); var maxEntriesToDisplay = 24; // max 25 fields allowed in embed - reserve 1 for "others" diff --git a/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs b/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs index f313f00a..d8633acf 100644 --- a/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs +++ b/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs @@ -122,7 +122,7 @@ namespace PluralKit.Core await GetSwitches(conn, system).FirstOrDefaultAsync(); public async Task> GetPeriodFronters(IPKConnection conn, - SystemId system, Instant periodStart, + SystemId system, GroupId? group, Instant periodStart, Instant periodEnd) { // TODO: IAsyncEnumerable-ify this one @@ -139,7 +139,14 @@ namespace PluralKit.Core new {Switches = switchMembers.Select(m => m.Member.Value).Distinct().ToList()}); var memberObjects = membersList.ToDictionary(m => m.Id); + // check if a group ID is provided. if so, query DB for all members of said group, otherwise use membersList + var groupMembersList = group != null ? await conn.QueryAsync( + "select * from members inner join group_members on members.id = group_members.member_id where group_id = @id", + new {id = group}) : membersList; + var groupMemberObjects = groupMembersList.ToDictionary(m => m.Id); + // Initialize entries - still need to loop to determine the TimespanEnd below + // use groupMemberObjects to make sure no members outside of the specified group (if present) are selected var entries = from item in switchMembers group item by item.Timestamp @@ -147,7 +154,7 @@ namespace PluralKit.Core select new SwitchListEntry { TimespanStart = g.Key, - Members = g.Where(x => x.Member != default(MemberId)).Select(x => memberObjects[x.Member]) + Members = g.Where(x => x.Member != default(MemberId) && groupMemberObjects.Any(m => x.Member == m.Key) ).Select(x => memberObjects[x.Member]) .ToList() }; @@ -174,7 +181,7 @@ namespace PluralKit.Core return outList; } - public async Task GetFrontBreakdown(IPKConnection conn, SystemId system, Instant periodStart, + public async Task GetFrontBreakdown(IPKConnection conn, SystemId system, GroupId? group, Instant periodStart, Instant periodEnd) { // TODO: this doesn't belong in the repo @@ -188,7 +195,7 @@ namespace PluralKit.Core var actualStart = periodEnd; // will be "pulled" down var actualEnd = periodStart; // will be "pulled" up - foreach (var sw in await GetPeriodFronters(conn, system, periodStart, periodEnd)) + foreach (var sw in await GetPeriodFronters(conn, system, group, periodStart, periodEnd)) { var span = sw.TimespanEnd - sw.TimespanStart; foreach (var member in sw.Members) diff --git a/PluralKit.Core/Services/DataFileService.cs b/PluralKit.Core/Services/DataFileService.cs index c694a156..0601efd9 100644 --- a/PluralKit.Core/Services/DataFileService.cs +++ b/PluralKit.Core/Services/DataFileService.cs @@ -51,7 +51,7 @@ namespace PluralKit.Core // Export switches var switches = new List(); - var switchList = await _repo.GetPeriodFronters(conn, system.Id, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant()); + var switchList = await _repo.GetPeriodFronters(conn, system.Id, null, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant()); switches.AddRange(switchList.Select(x => new DataFileSwitch { Timestamp = x.TimespanStart.FormatExport(), From 3603d52e9eac33bdc87a9ba0fd0768ec8746848e Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:02:41 +0200 Subject: [PATCH 2/9] Add group and system colors --- .gitignore | 3 +- PluralKit.Bot/Commands/CommandTree.cs | 10 ++++- PluralKit.Bot/Commands/Groups.cs | 48 ++++++++++++++++++++++ PluralKit.Bot/Commands/SystemEdit.cs | 42 +++++++++++++++++++ PluralKit.Bot/Services/EmbedService.cs | 25 ++++++++++- PluralKit.Core/Database/Database.cs | 2 +- PluralKit.Core/Database/Migrations/13.sql | 7 ++++ PluralKit.Core/Models/PKGroup.cs | 1 + PluralKit.Core/Models/PKSystem.cs | 1 + PluralKit.Core/Models/Patch/GroupPatch.cs | 2 + PluralKit.Core/Models/Patch/SystemPatch.cs | 2 + 11 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 PluralKit.Core/Database/Migrations/13.sql diff --git a/.gitignore b/.gitignore index 35c2cd6f..764fd1b3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ pluralkit.*.conf *.DotSettings.user # Generated -logs/ \ No newline at end of file +logs/ +*.dll diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index ad763670..a36f9090 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -13,6 +13,7 @@ namespace PluralKit.Bot public static Command SystemNew = new Command("system new", "system new [name]", "Creates a new system"); public static Command SystemRename = new Command("system name", "system rename [name]", "Renames your system"); public static Command SystemDesc = new Command("system description", "system description [description]", "Changes your system's description"); + public static Command SystemColor = new Command("system color", "system color [color]", "Changes your system's color"); public static Command SystemTag = new Command("system tag", "system tag [tag]", "Changes your system's tag"); public static Command SystemAvatar = new Command("system icon", "system icon [url|@mention]", "Changes your system's icon"); public static Command SystemDelete = new Command("system delete", "system delete", "Deletes your system"); @@ -55,6 +56,7 @@ namespace PluralKit.Bot public static Command GroupRename = new Command("group rename", "group rename ", "Renames a group"); public static Command GroupDisplayName = new Command("group displayname", "group displayname [display name]", "Changes a group's display name"); public static Command GroupDesc = new Command("group description", "group description [description]", "Changes a group's description"); + public static Command GroupColor = new Command("group color", "group color [color]", "Changes a group's color"); public static Command GroupAdd = new Command("group add", "group add [member 2] [member 3...]", "Adds one or more members to a group"); public static Command GroupRemove = new Command("group remove", "group remove [member 2] [member 3...]", "Removes one or more members from a group"); public static Command GroupPrivacy = new Command("group privacy", "group privacy ", "Changes a group's privacy settings"); @@ -89,7 +91,7 @@ namespace PluralKit.Bot public static Command PermCheck = new Command("permcheck", "permcheck ", "Checks whether a server's permission setup is correct"); public static Command[] SystemCommands = { - SystemInfo, SystemNew, SystemRename, SystemTag, SystemDesc, SystemAvatar, SystemDelete, SystemTimezone, + SystemInfo, SystemNew, SystemRename, SystemTag, SystemDesc, SystemAvatar, SystemColor, SystemDelete, SystemTimezone, SystemList, SystemFronter, SystemFrontHistory, SystemFrontPercent, SystemPrivacy, SystemProxy }; @@ -102,7 +104,7 @@ namespace PluralKit.Bot public static Command[] GroupCommands = { GroupInfo, GroupList, GroupNew, GroupAdd, GroupRemove, GroupMemberList, GroupRename, GroupDesc, - GroupIcon, GroupPrivacy, GroupDelete + GroupIcon, GroupColor, GroupPrivacy, GroupDelete }; public static Command[] GroupCommandsTargeted = @@ -218,6 +220,8 @@ namespace PluralKit.Bot await ctx.Execute(SystemTag, m => m.Tag(ctx)); else if (ctx.Match("description", "desc", "bio")) await ctx.Execute(SystemDesc, m => m.Description(ctx)); + else if (ctx.Match("color", "colour")) + await ctx.Execute(SystemColor, m => m.Color(ctx)); else if (ctx.Match("avatar", "picture", "icon", "image", "pic", "pfp")) await ctx.Execute(SystemAvatar, m => m.Avatar(ctx)); else if (ctx.Match("delete", "remove", "destroy", "erase", "yeet")) @@ -398,6 +402,8 @@ namespace PluralKit.Bot await ctx.Execute(GroupDelete, g => g.DeleteGroup(ctx, target)); else if (ctx.Match("avatar", "picture", "icon", "image", "pic", "pfp")) await ctx.Execute(GroupIcon, g => g.GroupIcon(ctx, target)); + else if (ctx.Match("color", "colour")) + await ctx.Execute(GroupColor, g => g.GroupColor(ctx, target)); else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown")) await ctx.Execute(GroupFrontPercent, g => g.GroupFrontPercent(ctx, target)); else if (!ctx.HasNext()) diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 4259dff8..6c68bb24 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Dapper; @@ -226,6 +227,53 @@ namespace PluralKit.Bot else await ShowIcon(); } + public async Task GroupColor(Context ctx, PKGroup target) + { + var color = ctx.RemainderOrNull(); + if (await ctx.MatchClear()) + { + ctx.CheckOwnGroup(target); + + var patch = new GroupPatch {Color = Partial.Null()}; + await _db.Execute(conn => _repo.UpdateGroup(conn, target.Id, patch)); + + await ctx.Reply($"{Emojis.Success} Group color cleared."); + } + else if (!ctx.HasNext()) + { + + if (target.Color == null) + if (ctx.System?.Id == target.System) + await ctx.Reply( + $"This group does not have a color set. To set one, type `pk;group {target.Reference()} color `."); + else + await ctx.Reply("This group does not have a color set."); + else + await ctx.Reply(embed: new EmbedBuilder() + .Title("Group color") + .Color(target.Color.ToDiscordColor()) + .Thumbnail(new($"https://fakeimg.pl/256x256/{target.Color}/?text=%20")) + .Description($"This group's color is **#{target.Color}**." + + (ctx.System?.Id == target.System ? $" To clear it, type `pk;group {target.Reference()} color -clear`." : "")) + .Build()); + } + else + { + ctx.CheckOwnGroup(target); + + if (color.StartsWith("#")) color = color.Substring(1); + if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color); + + var patch = new GroupPatch {Color = Partial.Present(color.ToLowerInvariant())}; + await _db.Execute(conn => _repo.UpdateGroup(conn, target.Id, patch)); + + await ctx.Reply(embed: new EmbedBuilder() + .Title($"{Emojis.Success} Group color changed.") + .Color(color.ToDiscordColor()) + .Thumbnail(new($"https://fakeimg.pl/256x256/{color}/?text=%20")) + .Build()); + } + } public async Task ListSystemGroups(Context ctx, PKSystem system) { diff --git a/PluralKit.Bot/Commands/SystemEdit.cs b/PluralKit.Bot/Commands/SystemEdit.cs index 7895b932..915d3bd8 100644 --- a/PluralKit.Bot/Commands/SystemEdit.cs +++ b/PluralKit.Bot/Commands/SystemEdit.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Myriad.Builders; @@ -91,6 +92,47 @@ namespace PluralKit.Bot await ctx.Reply($"{Emojis.Success} System description changed."); } } + + public async Task Color(Context ctx) { + ctx.CheckSystem(); + + if (await ctx.MatchClear()) + { + var patch = new SystemPatch {Color = Partial.Null()}; + await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch)); + + await ctx.Reply($"{Emojis.Success} System color cleared."); + } + else if (!ctx.HasNext()) + { + if (ctx.System.Color == null) + await ctx.Reply( + $"Your system does not have a color set. To set one, type `pk;system color `."); + else + await ctx.Reply(embed: new EmbedBuilder() + .Title("System color") + .Color(ctx.System.Color.ToDiscordColor()) + .Thumbnail(new($"https://fakeimg.pl/256x256/{ctx.System.Color}/?text=%20")) + .Description($"Your system's color is **#{ctx.System.Color}**. To clear it, type `pk;s color -clear`.") + .Build()); + } + else + { + var color = ctx.RemainderOrNull(); + + if (color.StartsWith("#")) color = color.Substring(1); + if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color); + + var patch = new SystemPatch {Color = Partial.Present(color.ToLowerInvariant())}; + await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch)); + + await ctx.Reply(embed: new EmbedBuilder() + .Title($"{Emojis.Success} Member color changed.") + .Color(color.ToDiscordColor()) + .Thumbnail(new($"https://fakeimg.pl/256x256/{color}/?text=%20")) + .Build()); + } + } public async Task Tag(Context ctx) { diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 5528f1cf..c0ec8265 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -53,11 +53,22 @@ namespace PluralKit.Bot { var memberCount = cctx.MatchPrivateFlag(ctx) ? await _repo.GetSystemMemberCount(conn, system.Id, PrivacyLevel.Public) : await _repo.GetSystemMemberCount(conn, system.Id); + uint color; + try + { + color = system.Color?.ToDiscordColor() ?? DiscordUtils.Gray; + } + catch (ArgumentException) + { + // There's no API for system colors yet, but defaulting to a blank color in advance can't be a bad idea + color = DiscordUtils.Gray; + } + var eb = new EmbedBuilder() .Title(system.Name) .Thumbnail(new(system.AvatarUrl)) .Footer(new($"System ID: {system.Hid} | Created on {system.Created.FormatZoned(system)}")) - .Color(DiscordUtils.Gray); + .Color(color); var latestSwitch = await _repo.GetLatestSwitch(conn, system.Id); if (latestSwitch != null && system.FrontPrivacy.CanAccess(ctx)) @@ -187,8 +198,20 @@ namespace PluralKit.Bot { if (system.Name != null) nameField = $"{nameField} ({system.Name})"; + uint color; + try + { + color = target.Color?.ToDiscordColor() ?? DiscordUtils.Gray; + } + catch (ArgumentException) + { + // There's no API for group colors yet, but defaulting to a blank color regardless + color = DiscordUtils.Gray; + } + var eb = new EmbedBuilder() .Author(new(nameField, IconUrl: DiscordUtils.WorkaroundForUrlBug(target.IconFor(pctx)))) + .Color(color) .Footer(new($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}")); if (target.DisplayName != null) diff --git a/PluralKit.Core/Database/Database.cs b/PluralKit.Core/Database/Database.cs index 72a8591e..043b9e68 100644 --- a/PluralKit.Core/Database/Database.cs +++ b/PluralKit.Core/Database/Database.cs @@ -19,7 +19,7 @@ namespace PluralKit.Core internal class Database: IDatabase { private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files - private const int TargetSchemaVersion = 12; + private const int TargetSchemaVersion = 13; private readonly CoreConfig _config; private readonly ILogger _logger; diff --git a/PluralKit.Core/Database/Migrations/13.sql b/PluralKit.Core/Database/Migrations/13.sql new file mode 100644 index 00000000..0ada9d65 --- /dev/null +++ b/PluralKit.Core/Database/Migrations/13.sql @@ -0,0 +1,7 @@ +-- SCHEMA VERSION 13: 2021-03-28 -- +-- Add system and group colors -- + +alter table systems add column color char(6); +alter table groups add column color char(6); + +update info set schema_version = 13; \ No newline at end of file diff --git a/PluralKit.Core/Models/PKGroup.cs b/PluralKit.Core/Models/PKGroup.cs index 7a45e900..21bea358 100644 --- a/PluralKit.Core/Models/PKGroup.cs +++ b/PluralKit.Core/Models/PKGroup.cs @@ -13,6 +13,7 @@ namespace PluralKit.Core public string? DisplayName { get; private set; } public string? Description { get; private set; } public string? Icon { get; private set; } + public string? Color { get; private set; } public PrivacyLevel DescriptionPrivacy { get; private set; } public PrivacyLevel IconPrivacy { get; private set; } diff --git a/PluralKit.Core/Models/PKSystem.cs b/PluralKit.Core/Models/PKSystem.cs index 436f9cc9..88d42266 100644 --- a/PluralKit.Core/Models/PKSystem.cs +++ b/PluralKit.Core/Models/PKSystem.cs @@ -14,6 +14,7 @@ namespace PluralKit.Core { public string Description { get; } public string Tag { get; } public string AvatarUrl { get; } + public string Color { get; } public string Token { get; } public Instant Created { get; } public string UiTz { get; set; } diff --git a/PluralKit.Core/Models/Patch/GroupPatch.cs b/PluralKit.Core/Models/Patch/GroupPatch.cs index 2f154c90..ee624df8 100644 --- a/PluralKit.Core/Models/Patch/GroupPatch.cs +++ b/PluralKit.Core/Models/Patch/GroupPatch.cs @@ -7,6 +7,7 @@ namespace PluralKit.Core public Partial DisplayName { get; set; } public Partial Description { get; set; } public Partial Icon { get; set; } + public Partial Color { get; set; } public Partial DescriptionPrivacy { get; set; } public Partial IconPrivacy { get; set; } @@ -18,6 +19,7 @@ namespace PluralKit.Core .With("display_name", DisplayName) .With("description", Description) .With("icon", Icon) + .With("color", Color) .With("description_privacy", DescriptionPrivacy) .With("icon_privacy", IconPrivacy) .With("list_privacy", ListPrivacy) diff --git a/PluralKit.Core/Models/Patch/SystemPatch.cs b/PluralKit.Core/Models/Patch/SystemPatch.cs index 7c3a9551..0f787749 100644 --- a/PluralKit.Core/Models/Patch/SystemPatch.cs +++ b/PluralKit.Core/Models/Patch/SystemPatch.cs @@ -7,6 +7,7 @@ namespace PluralKit.Core public Partial Description { get; set; } public Partial Tag { get; set; } public Partial AvatarUrl { get; set; } + public Partial Color { get; set; } public Partial Token { get; set; } public Partial UiTz { get; set; } public Partial DescriptionPrivacy { get; set; } @@ -22,6 +23,7 @@ namespace PluralKit.Core .With("description", Description) .With("tag", Tag) .With("avatar_url", AvatarUrl) + .With("color", Color) .With("token", Token) .With("ui_tz", UiTz) .With("description_privacy", DescriptionPrivacy) From ba30a96c7cf1462115dee070f0fa9962fcd6531b Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:07:25 +0200 Subject: [PATCH 3/9] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 764fd1b3..3c4fe014 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,3 @@ pluralkit.*.conf # Generated logs/ -*.dll From e7cfd85bd5f6b86887239a3af6acd2a63c6057f3 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:15:21 +0200 Subject: [PATCH 4/9] I messed up the branches oops --- PluralKit.Bot/Commands/CommandTree.cs | 2 -- PluralKit.Bot/Commands/Groups.cs | 25 ------------------- PluralKit.Bot/Commands/SystemFront.cs | 2 +- .../Repository/ModelRepository.Switch.cs | 15 +++-------- PluralKit.Core/Services/DataFileService.cs | 2 +- 5 files changed, 6 insertions(+), 40 deletions(-) diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index a36f9090..08c56ba6 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -404,8 +404,6 @@ namespace PluralKit.Bot await ctx.Execute(GroupIcon, g => g.GroupIcon(ctx, target)); else if (ctx.Match("color", "colour")) await ctx.Execute(GroupColor, g => g.GroupColor(ctx, target)); - else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown")) - await ctx.Execute(GroupFrontPercent, g => g.GroupFrontPercent(ctx, target)); else if (!ctx.HasNext()) await ctx.Execute(GroupInfo, g => g.ShowGroupCard(ctx, target)); else diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 6c68bb24..f9b7b73e 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -478,31 +478,6 @@ namespace PluralKit.Bot await ctx.Reply($"{Emojis.Success} Group deleted."); } - public async Task GroupFrontPercent(Context ctx, PKGroup target) - { - await using var conn = await _db.Obtain(); - - var targetSystem = await GetGroupSystem(ctx, target, conn); - ctx.CheckSystemPrivacy(targetSystem, targetSystem.FrontHistoryPrivacy); - - string durationStr = ctx.RemainderOrNull() ?? "30d"; - - var now = SystemClock.Instance.GetCurrentInstant(); - - var rangeStart = DateUtils.ParseDateTime(durationStr, true, targetSystem.Zone); - if (rangeStart == null) throw Errors.InvalidDateTime(durationStr); - if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture; - - var title = new StringBuilder($"Frontpercent of {target.DisplayName ?? target.Name} (`{target.Hid}`) in "); - if (targetSystem.Name != null) - title.Append($"{targetSystem.Name} (`{targetSystem.Hid}`)"); - else - title.Append($"`{targetSystem.Hid}`"); - - var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, targetSystem.Id, target.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target, targetSystem.Zone, ctx.LookupContextFor(targetSystem), title.ToString())); - } - private async Task GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn) { var system = ctx.System; diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index d9531216..9121be04 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -130,7 +130,7 @@ namespace PluralKit.Bot else title.Append($"`{system.Hid}`"); - var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, null, rangeStart.Value.ToInstant(), now)); + var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, rangeStart.Value.ToInstant(), now)); await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString())); } } diff --git a/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs b/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs index d8633acf..f313f00a 100644 --- a/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs +++ b/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs @@ -122,7 +122,7 @@ namespace PluralKit.Core await GetSwitches(conn, system).FirstOrDefaultAsync(); public async Task> GetPeriodFronters(IPKConnection conn, - SystemId system, GroupId? group, Instant periodStart, + SystemId system, Instant periodStart, Instant periodEnd) { // TODO: IAsyncEnumerable-ify this one @@ -139,14 +139,7 @@ namespace PluralKit.Core new {Switches = switchMembers.Select(m => m.Member.Value).Distinct().ToList()}); var memberObjects = membersList.ToDictionary(m => m.Id); - // check if a group ID is provided. if so, query DB for all members of said group, otherwise use membersList - var groupMembersList = group != null ? await conn.QueryAsync( - "select * from members inner join group_members on members.id = group_members.member_id where group_id = @id", - new {id = group}) : membersList; - var groupMemberObjects = groupMembersList.ToDictionary(m => m.Id); - // Initialize entries - still need to loop to determine the TimespanEnd below - // use groupMemberObjects to make sure no members outside of the specified group (if present) are selected var entries = from item in switchMembers group item by item.Timestamp @@ -154,7 +147,7 @@ namespace PluralKit.Core select new SwitchListEntry { TimespanStart = g.Key, - Members = g.Where(x => x.Member != default(MemberId) && groupMemberObjects.Any(m => x.Member == m.Key) ).Select(x => memberObjects[x.Member]) + Members = g.Where(x => x.Member != default(MemberId)).Select(x => memberObjects[x.Member]) .ToList() }; @@ -181,7 +174,7 @@ namespace PluralKit.Core return outList; } - public async Task GetFrontBreakdown(IPKConnection conn, SystemId system, GroupId? group, Instant periodStart, + public async Task GetFrontBreakdown(IPKConnection conn, SystemId system, Instant periodStart, Instant periodEnd) { // TODO: this doesn't belong in the repo @@ -195,7 +188,7 @@ namespace PluralKit.Core var actualStart = periodEnd; // will be "pulled" down var actualEnd = periodStart; // will be "pulled" up - foreach (var sw in await GetPeriodFronters(conn, system, group, periodStart, periodEnd)) + foreach (var sw in await GetPeriodFronters(conn, system, periodStart, periodEnd)) { var span = sw.TimespanEnd - sw.TimespanStart; foreach (var member in sw.Members) diff --git a/PluralKit.Core/Services/DataFileService.cs b/PluralKit.Core/Services/DataFileService.cs index cc259d3b..05dd3b37 100644 --- a/PluralKit.Core/Services/DataFileService.cs +++ b/PluralKit.Core/Services/DataFileService.cs @@ -51,7 +51,7 @@ namespace PluralKit.Core // Export switches var switches = new List(); - var switchList = await _repo.GetPeriodFronters(conn, system.Id, null, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant()); + var switchList = await _repo.GetPeriodFronters(conn, system.Id, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant()); switches.AddRange(switchList.Select(x => new DataFileSwitch { Timestamp = x.TimespanStart.FormatExport(), From 1e876ce283a0656a155861c30b5d884a0c531f3e Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:20:01 +0200 Subject: [PATCH 5/9] more branch fixing --- PluralKit.Bot/Commands/CommandTree.cs | 3 +-- PluralKit.Bot/Commands/Groups.cs | 2 -- PluralKit.Bot/Commands/SystemFront.cs | 8 +------- PluralKit.Bot/Services/EmbedService.cs | 6 ++---- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index 08c56ba6..b76d6261 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -62,7 +62,6 @@ namespace PluralKit.Bot public static Command GroupPrivacy = new Command("group privacy", "group privacy ", "Changes a group's privacy settings"); public static Command GroupIcon = new Command("group icon", "group icon [url|@mention]", "Changes a group's icon"); public static Command GroupDelete = new Command("group delete", "group delete", "Deletes a group"); - public static Command GroupFrontPercent = new Command("group frontpercent", "group frontpercent [timespan]", "Shows a group's front breakdown."); public static Command GroupMemberRandom = new Command("group random", "group random", "Shows the info card of a randomly selected member in a group."); public static Command GroupRandom = new Command("random", "random group", "Shows the info card of a randomly selected group in your system."); public static Command Switch = new Command("switch", "switch [member 2] [member 3...]", "Registers a switch"); @@ -110,7 +109,7 @@ namespace PluralKit.Bot public static Command[] GroupCommandsTargeted = { GroupInfo, GroupAdd, GroupRemove, GroupMemberList, GroupRename, GroupDesc, GroupIcon, GroupPrivacy, - GroupDelete, GroupMemberRandom, GroupFrontPercent + GroupDelete, GroupMemberRandom }; public static Command[] SwitchCommands = {Switch, SwitchOut, SwitchMove, SwitchDelete, SwitchDeleteAll}; diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index f9b7b73e..ac4d4425 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -9,8 +9,6 @@ using Dapper; using Humanizer; -using NodaTime; - using Myriad.Builders; using PluralKit.Core; diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 9121be04..6fba56e6 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -124,14 +124,8 @@ namespace PluralKit.Bot if (rangeStart == null) throw Errors.InvalidDateTime(durationStr); if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture; - var title = new StringBuilder($"Frontpercent of "); - if (system.Name != null) - title.Append($"{system.Name} (`{system.Hid}`)"); - else - title.Append($"`{system.Hid}`"); - var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString())); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, system.Zone, ctx.LookupContextFor(system), title.ToString())); } } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index c0ec8265..b80c0aa5 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -316,14 +316,12 @@ namespace PluralKit.Bot { return eb.Build(); } - public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle) + public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, DateTimeZone tz, LookupContext ctx, string embedTitle) { var actualPeriod = breakdown.RangeEnd - breakdown.RangeStart; var eb = new EmbedBuilder() - .Title(embedTitle) .Color(DiscordUtils.Gray) - .Footer(new($"System ID: {system.Hid} | {(group != null ? $"Group ID: {group.Hid} | " : "") }Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)")); - + .Footer(new($"Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)")); var maxEntriesToDisplay = 24; // max 25 fields allowed in embed - reserve 1 for "others" // We convert to a list of pairs so we can add the no-fronter value From 5a9671559a1f08cc250ec765e40b80fa6db8ad1f Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:21:06 +0200 Subject: [PATCH 6/9] more... branch fixing --- PluralKit.Bot/Commands/SystemFront.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 6fba56e6..3d2f10aa 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -125,7 +125,7 @@ namespace PluralKit.Bot if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture; var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, system.Zone, ctx.LookupContextFor(system), title.ToString())); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system.Zone, ctx.LookupContextFor(system), title.ToString())); } } } \ No newline at end of file From 8da5c94b1c40ea7c8e49b93ce29a99d7ffb37282 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:22:19 +0200 Subject: [PATCH 7/9] even more branch fixing --- PluralKit.Bot/Commands/SystemFront.cs | 2 +- PluralKit.Bot/Services/EmbedService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 3d2f10aa..3f8cbc0b 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -125,7 +125,7 @@ namespace PluralKit.Bot if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture; var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system.Zone, ctx.LookupContextFor(system), title.ToString())); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system.Zone, ctx.LookupContextFor(system))); } } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index b80c0aa5..ee246a18 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -316,7 +316,7 @@ namespace PluralKit.Bot { return eb.Build(); } - public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, DateTimeZone tz, LookupContext ctx, string embedTitle) + public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, DateTimeZone tz, LookupContext ctx) { var actualPeriod = breakdown.RangeEnd - breakdown.RangeStart; var eb = new EmbedBuilder() From 2898b3989af1899dc3b10b9d94e7aeedcb40f585 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 19:22:31 +0200 Subject: [PATCH 8/9] Add color to all lists --- PluralKit.Bot/Commands/Groups.cs | 4 ++-- PluralKit.Bot/Commands/Lists/ContextListExt.cs | 4 ++-- PluralKit.Bot/Commands/ServerConfig.cs | 1 + PluralKit.Bot/Commands/SystemFront.cs | 1 + PluralKit.Bot/Commands/SystemList.cs | 2 +- PluralKit.Bot/Utils/ContextUtils.cs | 4 +++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index ac4d4425..eb23c685 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -311,7 +311,7 @@ namespace PluralKit.Bot } var title = system.Name != null ? $"Groups of {system.Name} (`{system.Hid}`)" : $"Groups of `{system.Hid}`"; - await ctx.Paginate(groups.ToAsyncEnumerable(), groups.Count, 25, title, Renderer); + await ctx.Paginate(groups.ToAsyncEnumerable(), groups.Count, 25, title, ctx.System.Color, Renderer); Task Renderer(EmbedBuilder eb, IEnumerable page) { @@ -390,7 +390,7 @@ namespace PluralKit.Bot if (opts.Search != null) title.Append($" matching **{opts.Search}**"); - await ctx.RenderMemberList(ctx.LookupContextFor(target.System), _db, target.System, title.ToString(), opts); + await ctx.RenderMemberList(ctx.LookupContextFor(target.System), _db, target.System, title.ToString(), target.Color, opts); } public enum AddRemoveOperation diff --git a/PluralKit.Bot/Commands/Lists/ContextListExt.cs b/PluralKit.Bot/Commands/Lists/ContextListExt.cs index acca3b5f..fa990c4b 100644 --- a/PluralKit.Bot/Commands/Lists/ContextListExt.cs +++ b/PluralKit.Bot/Commands/Lists/ContextListExt.cs @@ -78,7 +78,7 @@ namespace PluralKit.Bot return p; } - public static async Task RenderMemberList(this Context ctx, LookupContext lookupCtx, IDatabase db, SystemId system, string embedTitle, MemberListOptions opts) + public static async Task RenderMemberList(this Context ctx, LookupContext lookupCtx, IDatabase db, SystemId system, string embedTitle, string color, MemberListOptions opts) { // We take an IDatabase instead of a IPKConnection so we don't keep the handle open for the entire runtime // We wanna release it as soon as the member list is actually *fetched*, instead of potentially minutes later (paginate timeout) @@ -87,7 +87,7 @@ namespace PluralKit.Bot .ToList(); var itemsPerPage = opts.Type == ListType.Short ? 25 : 5; - await ctx.Paginate(members.ToAsyncEnumerable(), members.Count, itemsPerPage, embedTitle, Renderer); + await ctx.Paginate(members.ToAsyncEnumerable(), members.Count, itemsPerPage, embedTitle, color, Renderer); // Base renderer, dispatches based on type Task Renderer(EmbedBuilder eb, IEnumerable page) diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index e29db8d4..12641288 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -107,6 +107,7 @@ namespace PluralKit.Bot await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25, $"Blacklisted channels for {ctx.Guild.Name}", + null, (eb, l) => { string CategoryName(ulong? id) => diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 3f8cbc0b..cde6359d 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -69,6 +69,7 @@ namespace PluralKit.Bot totalSwitches, 10, embedTitle, + system.Color, async (builder, switches) => { var sb = new StringBuilder(); diff --git a/PluralKit.Bot/Commands/SystemList.cs b/PluralKit.Bot/Commands/SystemList.cs index 493e5bda..8a33e552 100644 --- a/PluralKit.Bot/Commands/SystemList.cs +++ b/PluralKit.Bot/Commands/SystemList.cs @@ -20,7 +20,7 @@ namespace PluralKit.Bot ctx.CheckSystemPrivacy(target, target.MemberListPrivacy); var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target)); - await ctx.RenderMemberList(ctx.LookupContextFor(target), _db, target.Id, GetEmbedTitle(target, opts), opts); + await ctx.RenderMemberList(ctx.LookupContextFor(target), _db, target.Id, GetEmbedTitle(target, opts), target.Color, opts); } private string GetEmbedTitle(PKSystem target, MemberListOptions opts) diff --git a/PluralKit.Bot/Utils/ContextUtils.cs b/PluralKit.Bot/Utils/ContextUtils.cs index 2472c098..9f24d176 100644 --- a/PluralKit.Bot/Utils/ContextUtils.cs +++ b/PluralKit.Bot/Utils/ContextUtils.cs @@ -96,7 +96,7 @@ namespace PluralKit.Bot { return string.Equals(msg.Content, expectedReply, StringComparison.InvariantCultureIgnoreCase); } - public static async Task Paginate(this Context ctx, IAsyncEnumerable items, int totalCount, int itemsPerPage, string title, Func, Task> renderer) { + public static async Task Paginate(this Context ctx, IAsyncEnumerable items, int totalCount, int itemsPerPage, string title, string color, Func, Task> renderer) { // TODO: make this generic enough we can use it in Choose below var buffer = new List(); @@ -111,6 +111,8 @@ namespace PluralKit.Bot { var eb = new EmbedBuilder(); eb.Title(pageCount > 1 ? $"[{page+1}/{pageCount}] {title}" : title); + if (color != null) + eb.Color(color.ToDiscordColor()); await renderer(eb, buffer.Skip(page*itemsPerPage).Take(itemsPerPage)); return eb.Build(); } From c764f922ecb8bcb2bccf42b5db48deb5a9df57ee Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 19:22:45 +0200 Subject: [PATCH 9/9] Add color field to embeds --- PluralKit.Bot/Services/EmbedService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index ee246a18..2a9d5bff 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -79,7 +79,10 @@ namespace PluralKit.Bot { } if (system.Tag != null) - eb.Field(new("Tag", system.Tag.EscapeMarkdown())); + eb.Field(new("Tag", system.Tag.EscapeMarkdown(), true)); + + if (!system.Color.EmptyOrNull()) eb.Field(new("Color", $"#{system.Color}", true)); + eb.Field(new("Linked accounts", string.Join("\n", users).Truncate(1000), true)); if (system.MemberListPrivacy.CanAccess(ctx)) @@ -215,15 +218,17 @@ namespace PluralKit.Bot { .Footer(new($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}")); if (target.DisplayName != null) - eb.Field(new("Display Name", target.DisplayName)); + eb.Field(new("Display Name", target.DisplayName, true)); + + if (!target.Color.EmptyOrNull()) eb.Field(new("Color", $"#{target.Color}", true)); if (target.ListPrivacy.CanAccess(pctx)) { if (memberCount == 0 && pctx == LookupContext.ByOwner) // Only suggest the add command if this is actually the owner lol - eb.Field(new("Members (0)", $"Add one with `pk;group {target.Reference()} add `!", true)); + eb.Field(new("Members (0)", $"Add one with `pk;group {target.Reference()} add `!", false)); else - eb.Field(new($"Members ({memberCount})", $"(see `pk;group {target.Reference()} list`)", true)); + eb.Field(new($"Members ({memberCount})", $"(see `pk;group {target.Reference()} list`)", false)); } if (target.DescriptionFor(pctx) is { } desc)