PluralKit/PluralKit.Bot/Commands/SystemList.cs

51 lines
1.8 KiB
C#
Raw Normal View History

2020-06-04 13:21:47 +02:00
using System.Text;
2020-02-01 13:03:02 +01:00
using Humanizer;
using PluralKit.Core;
2020-02-01 13:03:02 +01:00
namespace PluralKit.Bot;
2021-08-27 11:03:47 -04:00
public class SystemList
{
public async Task MemberList(Context ctx, PKSystem target, string? query, IHasListOptions flags)
{
ctx.CheckSystem(target);
if (target == null) throw Errors.NoSystemError(ctx.DefaultPrefix);
ctx.CheckSystemPrivacy(target.Id, target.MemberListPrivacy);
var opts = flags.GetListOptions(ctx, target.Id);
opts.Search = query;
// explanation of privacy lookup here:
// - ParseListOptions checks list access privacy and sets the privacy filter (which members show up in list)
// - RenderMemberList checks the indivual privacy for each member (NameFor, etc)
// the own system is always allowed to look up their list
await ctx.RenderMemberList(
ctx.LookupContextFor(target.Id),
target.Id,
await GetEmbedTitle(target, opts, ctx),
target.Color,
opts
);
}
2020-02-01 13:03:02 +01:00
private async Task<string> GetEmbedTitle(PKSystem target, ListOptions opts, Context ctx)
{
var title = new StringBuilder("Members of ");
2021-08-27 11:03:47 -04: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)}`)");
else if (target.NameFor(ctx) != null)
2024-04-28 15:46:06 +12:00
title.Append($"{target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
else
2024-04-28 15:46:06 +12:00
title.Append($"`{target.DisplayHid(ctx.Config)}`");
2021-08-27 11:03:47 -04:00
if (opts.Search != null)
title.Append($" matching **{opts.Search.Truncate(100)}**");
2021-08-27 11:03:47 -04:00
return title.ToString();
2020-02-01 13:03:02 +01:00
}
}