2020-06-04 13:21:47 +02:00
|
|
|
using System.Text;
|
2020-02-01 13:03:02 +01:00
|
|
|
|
2022-01-23 01:47:55 -05:00
|
|
|
using Humanizer;
|
|
|
|
|
|
2020-02-12 15:16:19 +01:00
|
|
|
using PluralKit.Core;
|
2020-02-01 13:03:02 +01:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
namespace PluralKit.Bot;
|
2021-08-27 11:03:47 -04:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
public class SystemList
|
|
|
|
|
{
|
2025-09-30 18:45:35 +00:00
|
|
|
public async Task MemberList(Context ctx, PKSystem target, string? query, IHasListOptions flags)
|
2021-11-26 21:10:56 -05:00
|
|
|
{
|
2025-09-30 18:45:35 +00:00
|
|
|
ctx.CheckSystem(target);
|
|
|
|
|
|
2024-12-31 08:09:18 -07:00
|
|
|
if (target == null) throw Errors.NoSystemError(ctx.DefaultPrefix);
|
2021-12-07 01:32:29 -05:00
|
|
|
ctx.CheckSystemPrivacy(target.Id, target.MemberListPrivacy);
|
2021-11-26 21:10:56 -05:00
|
|
|
|
2025-09-30 18:45:35 +00:00
|
|
|
var opts = flags.GetListOptions(ctx, target.Id);
|
|
|
|
|
opts.Search = query;
|
|
|
|
|
|
2021-12-07 01:32:29 -05:00
|
|
|
// explanation of privacy lookup here:
|
2022-01-14 22:30:02 -05:00
|
|
|
// - ParseListOptions checks list access privacy and sets the privacy filter (which members show up in list)
|
2021-12-07 01:32:29 -05:00
|
|
|
// - RenderMemberList checks the indivual privacy for each member (NameFor, etc)
|
|
|
|
|
// the own system is always allowed to look up their list
|
2021-11-26 21:10:56 -05:00
|
|
|
await ctx.RenderMemberList(
|
2021-12-06 00:32:54 -05:00
|
|
|
ctx.LookupContextFor(target.Id),
|
2021-11-26 21:10:56 -05:00
|
|
|
target.Id,
|
2023-07-19 12:48:04 +12:00
|
|
|
await GetEmbedTitle(target, opts, ctx),
|
2021-11-26 21:10:56 -05:00
|
|
|
target.Color,
|
|
|
|
|
opts
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-02-01 13:03:02 +01:00
|
|
|
|
2023-07-19 12:48:04 +12:00
|
|
|
private async Task<string> GetEmbedTitle(PKSystem target, ListOptions opts, Context ctx)
|
2021-11-26 21:10:56 -05:00
|
|
|
{
|
|
|
|
|
var title = new StringBuilder("Members of ");
|
2021-08-27 11:03:47 -04:00
|
|
|
|
2023-07-19 12:48:04 +12:00
|
|
|
var systemGuildSettings = ctx.Guild != null ? await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id) : null;
|
|
|
|
|
if (systemGuildSettings != null && systemGuildSettings.DisplayName != null)
|
2024-04-28 15:46:06 +12:00
|
|
|
title.Append($"{systemGuildSettings.DisplayName} (`{target.DisplayHid(ctx.Config)}`)");
|
2023-07-19 12:48:04 +12:00
|
|
|
else if (target.NameFor(ctx) != null)
|
2024-04-28 15:46:06 +12:00
|
|
|
title.Append($"{target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
2021-11-26 21:10:56 -05:00
|
|
|
else
|
2024-04-28 15:46:06 +12:00
|
|
|
title.Append($"`{target.DisplayHid(ctx.Config)}`");
|
2021-08-27 11:03:47 -04:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
if (opts.Search != null)
|
2022-01-23 01:47:55 -05:00
|
|
|
title.Append($" matching **{opts.Search.Truncate(100)}**");
|
2021-08-27 11:03:47 -04:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
return title.ToString();
|
2020-02-01 13:03:02 +01:00
|
|
|
}
|
|
|
|
|
}
|