2020-06-04 11:21:47 +00:00
|
|
|
using System.Text;
|
2020-02-01 12:03:02 +00:00
|
|
|
|
2022-01-23 06:47:55 +00:00
|
|
|
using Humanizer;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
2020-02-01 12:03:02 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Bot;
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class SystemList
|
|
|
|
{
|
|
|
|
public async Task MemberList(Context ctx, PKSystem target)
|
|
|
|
{
|
|
|
|
if (target == null) throw Errors.NoSystemError;
|
2021-12-07 06:32:29 +00:00
|
|
|
ctx.CheckSystemPrivacy(target.Id, target.MemberListPrivacy);
|
2021-11-27 02:10:56 +00:00
|
|
|
|
2021-12-07 06:32:29 +00:00
|
|
|
// explanation of privacy lookup here:
|
2022-01-15 03:30:02 +00:00
|
|
|
// - ParseListOptions checks list access privacy and sets the privacy filter (which members show up in list)
|
2021-12-07 06:32:29 +00:00
|
|
|
// - RenderMemberList checks the indivual privacy for each member (NameFor, etc)
|
|
|
|
// the own system is always allowed to look up their list
|
2022-01-15 03:30:02 +00:00
|
|
|
var opts = ctx.ParseListOptions(ctx.DirectLookupContextFor(target.Id));
|
2021-11-27 02:10:56 +00:00
|
|
|
await ctx.RenderMemberList(
|
2021-12-06 05:32:54 +00:00
|
|
|
ctx.LookupContextFor(target.Id),
|
2021-11-27 02:10:56 +00:00
|
|
|
target.Id,
|
|
|
|
GetEmbedTitle(target, opts),
|
|
|
|
target.Color,
|
|
|
|
opts
|
|
|
|
);
|
|
|
|
}
|
2020-02-01 12:03:02 +00:00
|
|
|
|
2022-01-15 03:30:02 +00:00
|
|
|
private string GetEmbedTitle(PKSystem target, ListOptions opts)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
|
|
|
var title = new StringBuilder("Members of ");
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (target.Name != null)
|
|
|
|
title.Append($"{target.Name} (`{target.Hid}`)");
|
|
|
|
else
|
|
|
|
title.Append($"`{target.Hid}`");
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (opts.Search != null)
|
2022-01-23 06:47:55 +00:00
|
|
|
title.Append($" matching **{opts.Search.Truncate(100)}**");
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return title.ToString();
|
2020-02-01 12:03:02 +00:00
|
|
|
}
|
|
|
|
}
|