PluralKit/PluralKit.Bot/Commands/SystemList.cs

41 lines
1.1 KiB
C#
Raw Normal View History

2020-06-04 11:21:47 +00:00
using System.Text;
2020-02-01 12:03:02 +00:00
using System.Threading.Tasks;
using PluralKit.Core;
2020-02-01 12:03:02 +00:00
namespace PluralKit.Bot
2020-02-01 12:03:02 +00:00
{
public class SystemList
{
2020-06-13 17:36:43 +00:00
private readonly IDatabase _db;
2021-08-27 15:03:47 +00:00
public SystemList(IDatabase db)
2020-02-01 12:03:02 +00:00
{
2020-06-04 11:21:47 +00:00
_db = db;
2020-02-01 12:03:02 +00:00
}
2020-06-04 11:21:47 +00:00
public async Task MemberList(Context ctx, PKSystem target)
2020-02-13 15:35:50 +00:00
{
2020-06-04 11:21:47 +00:00
if (target == null) throw Errors.NoSystemError;
ctx.CheckSystemPrivacy(target, target.MemberListPrivacy);
2020-02-13 15:35:50 +00:00
2020-07-07 18:57:22 +00:00
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target));
2021-03-28 17:22:31 +00:00
await ctx.RenderMemberList(ctx.LookupContextFor(target), _db, target.Id, GetEmbedTitle(target, opts), target.Color, opts);
2020-02-01 12:03:02 +00:00
}
2020-07-07 18:57:22 +00:00
private string GetEmbedTitle(PKSystem target, MemberListOptions opts)
2020-02-13 15:35:50 +00:00
{
2020-06-04 11:21:47 +00:00
var title = new StringBuilder("Members of ");
2021-08-27 15:03:47 +00:00
if (target.Name != null)
2020-07-07 18:57:22 +00:00
title.Append($"{target.Name} (`{target.Hid}`)");
2021-08-27 15:03:47 +00:00
else
2020-07-07 18:57:22 +00:00
title.Append($"`{target.Hid}`");
2021-08-27 15:03:47 +00:00
2020-07-07 18:57:22 +00:00
if (opts.Search != null)
title.Append($" matching **{opts.Search}**");
2021-08-27 15:03:47 +00:00
2020-06-04 11:21:47 +00:00
return title.ToString();
2020-02-13 15:35:50 +00:00
}
2020-02-01 12:03:02 +00:00
}
}