721a4502bb
* Some reasons this needs to exist for it to run on my machine? I don't think it would hurt to have it in other machines so * Add options to member model * Add Privacy to member embed * Added member privacy display list * Update database settings * apparetnly this is nolonger needed? * Fix sql call * Fix more sql errors * Added in settings control * Add all subject to system privacy * Basic API Privacy * Name privacy in logs * update todo * remove CheckReadMemberPermission * Added name privacy to log embed * update todo * Update todo * Update api to handle privacy * update todo * Update systemlist full to respect privacy (as well as system list) * include colour as option for member privacy subject * move todo file (why was it there?) * Update TODO.md * Update TODO.md * Update TODO.md * Deleted to create pr * Update command usage and add to the command tree * Make api respect created privacy * Add editing privacy through the api * Fix pronoun privacy field in api * Fix info leak of display name in api * deprecate privacy field in api * Deprecate privacy diffrently * Update API * Update documentation * Update documentation * Remove comment in yml * Update userguide * Update migration (fix typo in 5.sql too) * Sanatize names * some full stops * Fix after merge * update migration * update schema version * update edit command * update privacy filter * fix a dumb mistake * clarify on what name privacy does * make it easier on someone else * Update docs * Comment out unused code * Add aliases for `member privacy all public` and `member privacy all private`
71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using PluralKit.Core;
|
|
|
|
namespace PluralKit.Bot
|
|
{
|
|
public class SystemList
|
|
{
|
|
private readonly IDatabase _db;
|
|
|
|
public SystemList(IDatabase db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
public async Task MemberList(Context ctx, PKSystem target)
|
|
{
|
|
if (target == null) throw Errors.NoSystemError;
|
|
ctx.CheckSystemPrivacy(target, target.MemberListPrivacy);
|
|
|
|
// GetRendererFor must be called before GetOptions as it consumes a potential positional full argument that'd otherwise land in the filter
|
|
var renderer = GetRendererFor(ctx);
|
|
var opts = GetOptions(ctx, target);
|
|
|
|
var members = (await _db.Execute(c => opts.Execute(c, target))).ToList();
|
|
await ctx.Paginate(
|
|
members.ToAsyncEnumerable(),
|
|
members.Count,
|
|
renderer.MembersPerPage,
|
|
GetEmbedTitle(target, opts),
|
|
(eb, ms) =>
|
|
{
|
|
eb.WithFooter($"{opts.CreateFilterString()}. {members.Count} results.");
|
|
renderer.RenderPage(eb, ctx.System.Zone, ms, ctx.LookupContextFor(target));
|
|
return Task.CompletedTask;
|
|
});
|
|
}
|
|
|
|
private string GetEmbedTitle(PKSystem target, SortFilterOptions opts)
|
|
{
|
|
var title = new StringBuilder("Members of ");
|
|
|
|
if (target.Name != null) title.Append($"{target.Name.SanitizeMentions()} (`{target.Hid}`)");
|
|
else title.Append($"`{target.Hid}`");
|
|
|
|
if (opts.Filter != null) title.Append($" matching **{opts.Filter.SanitizeMentions()}**");
|
|
|
|
return title.ToString();
|
|
}
|
|
|
|
private SortFilterOptions GetOptions(Context ctx, PKSystem target)
|
|
{
|
|
var opts = SortFilterOptions.FromFlags(ctx);
|
|
opts.Filter = ctx.RemainderOrNull();
|
|
// If we're *explicitly* trying to access non-public members of another system, error
|
|
if (opts.PrivacyFilter != PrivacyFilter.PublicOnly && ctx.LookupContextFor(target) != LookupContext.ByOwner)
|
|
throw new PKError("You cannot look up private members of another system.");
|
|
return opts;
|
|
}
|
|
|
|
private IListRenderer GetRendererFor(Context ctx)
|
|
{
|
|
var longList = ctx.Match("f", "full", "big", "details", "long") || ctx.MatchFlag("f", "full");
|
|
if (longList)
|
|
return new LongRenderer(LongRenderer.MemberFields.FromFlags(ctx));
|
|
return new ShortRenderer();
|
|
}
|
|
}
|
|
} |