feat(bot): -with-birthday flag for showing birthday in short member list
This commit is contained in:
parent
44fe3d538a
commit
a2b38c45e2
@ -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,79 +131,22 @@ public static class ContextListExt
|
||||
{
|
||||
var ret = $"[`{m.Hid}`] **{m.NameFor(ctx)}** ";
|
||||
|
||||
switch (opts.SortProperty)
|
||||
{
|
||||
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: <t:{lastSw.Value.ToUnixTimeSeconds()}>)";
|
||||
break;
|
||||
}
|
||||
// case SortProperty.LastMessage:
|
||||
// {
|
||||
// if (m.MetadataPrivacy.TryGet(lookupCtx, m.LastMessage, out var lastMsg))
|
||||
// ret += $"(last message: <t:{DiscordUtils.SnowflakeToInstant(lastMsg.Value).ToUnixTimeSeconds()}>)";
|
||||
// break;
|
||||
// }
|
||||
case SortProperty.CreationDate:
|
||||
{
|
||||
if (m.MetadataPrivacy.TryGet(lookupCtx, m.Created, out var created))
|
||||
ret += $"(created at <t:{created.ToUnixTimeSeconds()}>)";
|
||||
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))
|
||||
{
|
||||
else if (opts.IncludeLastSwitch && m.MetadataPrivacy.TryGet(lookupCtx, m.LastSwitchTime, out var lastSw))
|
||||
ret += $"(last switched in: <t:{lastSw.Value.ToUnixTimeSeconds()}>)";
|
||||
}
|
||||
// else if (opts.IncludeLastMessage && m.MetadataPrivacy.TryGet(lookupCtx, m.LastMessage, out var lastMsg))
|
||||
// ret += $"(last message: <t:{DiscordUtils.SnowflakeToInstant(lastMsg.Value).ToUnixTimeSeconds()}>)";
|
||||
else if (opts.IncludeCreated &&
|
||||
m.MetadataPrivacy.TryGet(lookupCtx, m.Created, out var created))
|
||||
{
|
||||
else if (opts.IncludeCreated && m.MetadataPrivacy.TryGet(lookupCtx, m.Created, out var created))
|
||||
ret += $"(created at <t:{created.ToUnixTimeSeconds()}>)";
|
||||
}
|
||||
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)
|
||||
{
|
||||
var proxyTagsString = m.ProxyTagsString();
|
||||
@ -212,10 +155,6 @@ public static class ContextListExt
|
||||
ret += $"*(*{proxyTagsString}*)*";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}));
|
||||
}
|
||||
|
@ -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)
|
||||
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
|
||||
}
|
||||
|
@ -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|
|
||||
|
Loading…
Reference in New Issue
Block a user