2020-06-13 19:49:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-06-04 11:21:47 +00:00
|
|
|
|
|
|
|
|
|
using DSharpPlus.Entities;
|
|
|
|
|
|
|
|
|
|
using Humanizer;
|
|
|
|
|
|
2020-06-06 23:30:19 +00:00
|
|
|
|
using NodaTime;
|
|
|
|
|
|
2020-06-04 11:21:47 +00:00
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
|
{
|
|
|
|
|
public class LongRenderer: IListRenderer
|
|
|
|
|
{
|
|
|
|
|
public int MembersPerPage => 5;
|
|
|
|
|
|
|
|
|
|
private readonly MemberFields _fields;
|
|
|
|
|
public LongRenderer(MemberFields fields)
|
|
|
|
|
{
|
|
|
|
|
_fields = fields;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-13 19:49:31 +00:00
|
|
|
|
public void RenderPage(DiscordEmbedBuilder eb, DateTimeZone zone, IEnumerable<ListedMember> members)
|
2020-06-04 11:21:47 +00:00
|
|
|
|
{
|
2020-06-13 19:49:31 +00:00
|
|
|
|
string FormatTimestamp(Instant timestamp) => DateTimeFormats.ZonedDateTimeFormat.Format(timestamp.InZone(zone));
|
|
|
|
|
|
2020-06-04 11:21:47 +00:00
|
|
|
|
foreach (var m in members)
|
|
|
|
|
{
|
|
|
|
|
var profile = $"**ID**: {m.Hid}";
|
|
|
|
|
if (_fields.ShowDisplayName && m.DisplayName != null) profile += $"\n**Display name**: {m.DisplayName}";
|
|
|
|
|
if (_fields.ShowPronouns && m.Pronouns != null) profile += $"\n**Pronouns**: {m.Pronouns}";
|
|
|
|
|
if (_fields.ShowBirthday && m.Birthday != null) profile += $"\n**Birthdate**: {m.BirthdayString}";
|
|
|
|
|
if (_fields.ShowPronouns && m.ProxyTags.Count > 0) profile += $"\n**Proxy tags:** {m.ProxyTagsString()}";
|
|
|
|
|
if (_fields.ShowMessageCount && m.MessageCount > 0) profile += $"\n**Message count:** {m.MessageCount}";
|
2020-06-13 19:49:31 +00:00
|
|
|
|
if (_fields.ShowLastMessage && m.LastMessage != null) profile += $"\n**Last message:** {FormatTimestamp(DiscordUtils.SnowflakeToInstant(m.LastMessage.Value))}";
|
|
|
|
|
if (_fields.ShowLastSwitch && m.LastSwitchTime != null) profile += $"\n**Last switched in:** {FormatTimestamp(m.LastSwitchTime.Value)}";
|
2020-06-04 11:21:47 +00:00
|
|
|
|
if (_fields.ShowDescription && m.Description != null) profile += $"\n\n{m.Description}";
|
|
|
|
|
if (_fields.ShowPrivacy && m.MemberPrivacy == PrivacyLevel.Private)
|
|
|
|
|
profile += "\n*(this member is private)*";
|
|
|
|
|
|
|
|
|
|
eb.AddField(m.Name, profile.Truncate(1024));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-13 19:49:31 +00:00
|
|
|
|
|
2020-06-04 11:21:47 +00:00
|
|
|
|
public class MemberFields
|
|
|
|
|
{
|
|
|
|
|
public bool ShowDisplayName = true;
|
2020-06-06 23:30:19 +00:00
|
|
|
|
public bool ShowCreated = false;
|
2020-06-04 11:21:47 +00:00
|
|
|
|
public bool ShowPronouns = true;
|
|
|
|
|
public bool ShowBirthday = true;
|
|
|
|
|
public bool ShowProxyTags = true;
|
|
|
|
|
public bool ShowDescription = true;
|
|
|
|
|
public bool ShowPrivacy = true;
|
|
|
|
|
|
2020-06-06 23:30:19 +00:00
|
|
|
|
public bool ShowMessageCount = false;
|
|
|
|
|
public bool ShowLastSwitch = false;
|
|
|
|
|
public bool ShowLastMessage = false;
|
|
|
|
|
|
2020-06-04 11:21:47 +00:00
|
|
|
|
public static MemberFields FromFlags(Context ctx)
|
|
|
|
|
{
|
2020-06-06 23:30:19 +00:00
|
|
|
|
var def = new MemberFields();
|
|
|
|
|
if (ctx.MatchFlag("with-last-switch", "with-last-fronted", "with-last-front", "wls", "wlf"))
|
|
|
|
|
def.ShowLastSwitch = true;
|
|
|
|
|
if (ctx.MatchFlag("with-message-count", "wmc"))
|
|
|
|
|
def.ShowMessageCount = true;
|
|
|
|
|
if (ctx.MatchFlag("with-last-message", "with-last-proxy", "wlm", "wlp"))
|
|
|
|
|
def.ShowLastMessage = true;
|
|
|
|
|
return def;
|
2020-06-04 11:21:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|