diff --git a/PluralKit.Bot/Commands/Lists/ContextListExt.cs b/PluralKit.Bot/Commands/Lists/ContextListExt.cs index 57096c44..1b8a562c 100644 --- a/PluralKit.Bot/Commands/Lists/ContextListExt.cs +++ b/PluralKit.Bot/Commands/Lists/ContextListExt.cs @@ -78,8 +78,8 @@ public static class ContextListExt if (ctx.MatchFlag("with-birthday", "wbd", "wb")) p.IncludeBirthday = true; - // Always show the sort property, too (unless this is the short list) - if (p.Type != ListType.Short) + // Always show the sort property, too (unless this is the short list and we are already showing something else) + if (p.Type != ListType.Short || p.includedCount == 0) { if (p.SortProperty == SortProperty.DisplayName) p.IncludeDisplayName = true; if (p.SortProperty == SortProperty.MessageCount) p.IncludeMessageCount = true; @@ -131,89 +131,28 @@ public static class ContextListExt { var ret = $"[`{m.Hid}`] **{m.NameFor(ctx)}** "; - switch (opts.SortProperty) + if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count) + ret += $"({count} messages)"; + else if (opts.IncludeLastSwitch && m.MetadataPrivacy.TryGet(lookupCtx, m.LastSwitchTime, out var lastSw)) + ret += $"(last switched in: )"; + // else if (opts.IncludeLastMessage && m.MetadataPrivacy.TryGet(lookupCtx, m.LastMessage, out var lastMsg)) + // ret += $"(last message: )"; + else if (opts.IncludeCreated && m.MetadataPrivacy.TryGet(lookupCtx, m.Created, out var created)) + ret += $"(created at )"; + else if (opts.IncludeAvatar && m.AvatarFor(lookupCtx) is { } avatarUrl) + ret += $"([avatar URL]({avatarUrl}))"; + else if (opts.IncludePronouns && m.PronounsFor(lookupCtx) is { } pronouns) + ret += $"({pronouns})"; + else if (opts.IncludeDisplayName && m.DisplayName != null && m.NamePrivacy.CanAccess(lookupCtx)) + ret += $"({m.DisplayName})"; + else if (opts.IncludeBirthday && m.BirthdayFor(lookupCtx) is { } birthday) + ret += $"(birthday: {m.BirthdayString})"; + else if (m.HasProxyTags) { - case SortProperty.Birthdate: - { - var birthday = m.BirthdayFor(lookupCtx); - if (birthday != null) - ret += $"(birthday: {m.BirthdayString})"; - break; - } - case SortProperty.DisplayName: - { - if (m.DisplayName != null && m.NamePrivacy.CanAccess(lookupCtx)) - ret += $"({m.DisplayName})"; - break; - } - case SortProperty.MessageCount: - { - if (m.MessageCountFor(lookupCtx) is { } count) - ret += $"({count} messages)"; - break; - } - case SortProperty.LastSwitch: - { - if (m.MetadataPrivacy.TryGet(lookupCtx, m.LastSwitchTime, out var lastSw)) - ret += $"(last switched in: )"; - break; - } - // case SortProperty.LastMessage: - // { - // if (m.MetadataPrivacy.TryGet(lookupCtx, m.LastMessage, out var lastMsg)) - // ret += $"(last message: )"; - // break; - // } - case SortProperty.CreationDate: - { - if (m.MetadataPrivacy.TryGet(lookupCtx, m.Created, out var created)) - ret += $"(created at )"; - break; - } - default: - { - if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count) - { - ret += $"({count} messages)"; - } - else if (opts.IncludeDisplayName && m.DisplayName != null && m.NamePrivacy.CanAccess(lookupCtx)) - { - ret += $"({m.DisplayName})"; - } - else if (opts.IncludeLastSwitch && - m.MetadataPrivacy.TryGet(lookupCtx, m.LastSwitchTime, out var lastSw)) - { - ret += $"(last switched in: )"; - } - // else if (opts.IncludeLastMessage && m.MetadataPrivacy.TryGet(lookupCtx, m.LastMessage, out var lastMsg)) - // ret += $"(last message: )"; - else if (opts.IncludeCreated && - m.MetadataPrivacy.TryGet(lookupCtx, m.Created, out var created)) - { - ret += $"(created at )"; - } - else if (opts.IncludeAvatar && m.AvatarFor(lookupCtx) is { } avatarUrl) - { - ret += $"([avatar URL]({avatarUrl}))"; - } - else if (opts.IncludePronouns && m.PronounsFor(lookupCtx) is { } pronouns) - { - ret += $"({pronouns})"; - } - else if (opts.IncludeBirthday && m.BirthdayFor(lookupCtx) is {} birthday) - { - ret += $"(birthday: {m.BirthdayString})"; - } - else if (m.HasProxyTags) - { - var proxyTagsString = m.ProxyTagsString(); - if (proxyTagsString.Length > 100) // arbitrary threshold for now, tweak? - proxyTagsString = "tags too long, see member card"; - ret += $"*(*{proxyTagsString}*)*"; - } - - break; - } + var proxyTagsString = m.ProxyTagsString(); + if (proxyTagsString.Length > 100) // arbitrary threshold for now, tweak? + proxyTagsString = "tags too long, see member card"; + ret += $"*(*{proxyTagsString}*)*"; } return ret; diff --git a/PluralKit.Bot/Commands/Lists/ListOptions.cs b/PluralKit.Bot/Commands/Lists/ListOptions.cs index 3a6937d3..c3d3c23c 100644 --- a/PluralKit.Bot/Commands/Lists/ListOptions.cs +++ b/PluralKit.Bot/Commands/Lists/ListOptions.cs @@ -42,6 +42,18 @@ public class ListOptions public bool IncludeDisplayName { get; set; } public bool IncludeBirthday { get; set; } + // hacky but works, remember to update this when more include flags are added + public int includedCount => new[] { + IncludeMessageCount, + IncludeLastSwitch, + IncludeLastMessage, + IncludeCreated, + IncludeAvatar, + IncludePronouns, + IncludeDisplayName, + IncludeBirthday, + }.Sum(x => Convert.ToInt32(x)); + public string CreateFilterString() { var str = new StringBuilder(); @@ -165,22 +177,8 @@ public static class ListOptionsExt public static void AssertIsValid(this ListOptions opts) { - if (opts.Type == ListType.Short) - { - var hasMultipleIncluded = new[] { - opts.IncludeMessageCount, - opts.IncludeLastSwitch, - opts.IncludeLastMessage, - opts.IncludeCreated, - opts.IncludeAvatar, - opts.IncludePronouns, - opts.IncludeDisplayName, - opts.IncludeBirthday, - }.Sum(x => Convert.ToInt32(x)) > 1; - - if (hasMultipleIncluded) - throw new PKError("The short list does not support showing items from multiple flags. Try using the full list instead."); - } + if (opts.Type == ListType.Short && opts.includedCount > 1) + throw new PKError("The short list does not support showing items from multiple flags. Try using the full list instead."); // the check for multiple *sorting* property flags is done in SortProperty setter } diff --git a/docs/content/tips-and-tricks.md b/docs/content/tips-and-tricks.md index c67a2fe6..259ddd40 100644 --- a/docs/content/tips-and-tricks.md +++ b/docs/content/tips-and-tricks.md @@ -65,6 +65,7 @@ You cannot look up private members or groups of another system. |-with-avatar|-wa, -wi, -ia, -ii, -img|Member, Group|Show each item's avatar URL| |-with-pronouns|-wp -wprns|Member|Show each member's pronouns in the short list (shown by default in full list)| |-with-displayname|-wdn|Member, Group|Show each item's displayname| +|-with-birthday|-wbd, -wb|Member|Show each member's birthday in the short list (shown by default in full list)| ## Miscellaneous flags |Command|Flag|Aliases|Description|