43 lines
1.2 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 System.Threading.Tasks;
using NodaTime;
using PluralKit.Core;
2020-02-01 13:03:02 +01:00
namespace PluralKit.Bot
2020-02-01 13:03:02 +01:00
{
public class SystemList
{
2020-06-13 19:36:43 +02:00
private readonly IDatabase _db;
2020-06-04 13:21:47 +02:00
public SystemList(IDatabase db)
2020-02-01 13:03:02 +01:00
{
2020-06-04 13:21:47 +02:00
_db = db;
2020-02-01 13:03:02 +01:00
}
2020-06-04 13:21:47 +02:00
public async Task MemberList(Context ctx, PKSystem target)
2020-02-13 16:35:50 +01:00
{
2020-06-04 13:21:47 +02:00
if (target == null) throw Errors.NoSystemError;
ctx.CheckSystemPrivacy(target, target.MemberListPrivacy);
2020-02-13 16:35:50 +01:00
2020-07-07 20:57:22 +02:00
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target));
await ctx.RenderMemberList(ctx.LookupContextFor(target), _db, target.Id, GetEmbedTitle(target, opts), opts);
2020-02-01 13:03:02 +01:00
}
2020-07-07 20:57:22 +02:00
private string GetEmbedTitle(PKSystem target, MemberListOptions opts)
2020-02-13 16:35:50 +01:00
{
2020-06-04 13:21:47 +02:00
var title = new StringBuilder("Members of ");
2020-07-07 20:57:22 +02:00
if (target.Name != null)
title.Append($"{target.Name} (`{target.Hid}`)");
else
title.Append($"`{target.Hid}`");
2020-06-04 13:21:47 +02:00
2020-07-07 20:57:22 +02:00
if (opts.Search != null)
title.Append($" matching **{opts.Search}**");
2020-06-04 13:21:47 +02:00
return title.ToString();
2020-02-13 16:35:50 +01:00
}
2020-02-01 13:03:02 +01:00
}
}