Add group member list command

This commit is contained in:
Ske
2020-07-07 19:34:23 +02:00
parent 0f4c40b344
commit 8a28d836c7
4 changed files with 35 additions and 3 deletions

View File

@@ -48,6 +48,7 @@ namespace PluralKit.Bot
public static Command GroupInfo = new Command("group", "group <name>", "Looks up information about a group");
public static Command GroupNew = new Command("group new", "group new <name>", "Creates a new group");
public static Command GroupList = new Command("group list", "group list", "Lists all groups in this system");
public static Command GroupMemberList = new Command("group members", "group <group> list", "Lists all members in a group");
public static Command GroupRename = new Command("group rename", "group <group> name <new name>", "Renames a group");
public static Command GroupDesc = new Command("group description", "group <group> description [description]", "Changes a group's description");
public static Command GroupAdd = new Command("group add", "group <group> add <member> [member 2] [member 3...]", "Adds one or more members to a group");
@@ -339,6 +340,8 @@ namespace PluralKit.Bot
await ctx.Execute<Groups>(GroupAdd,g => g.AddRemoveMembers(ctx, target, Groups.AddRemoveOperation.Add));
else if (ctx.Match("remove", "rem", "r"))
await ctx.Execute<Groups>(GroupRemove, g => g.AddRemoveMembers(ctx, target, Groups.AddRemoveOperation.Remove));
else if (ctx.Match("members", "list", "ms", "l"))
await ctx.Execute<Groups>(GroupMemberList, g => g.ListGroupMembers(ctx, target));
else if (!ctx.HasNext())
await ctx.Execute<Groups>(GroupInfo, g => g.ShowGroupCard(ctx, target));
else

View File

@@ -5,6 +5,8 @@ using System.Threading.Tasks;
using DSharpPlus.Entities;
using NodaTime;
using PluralKit.Core;
namespace PluralKit.Bot
@@ -176,6 +178,26 @@ namespace PluralKit.Bot
}
}
public async Task ListGroupMembers(Context ctx, PKGroup target)
{
await using var conn = await _db.Obtain();
var targetSystem = await GetGroupSystem(ctx, target, conn);
ctx.CheckSystemPrivacy(targetSystem, targetSystem.MemberListPrivacy);
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target.System));
opts.GroupFilter = target.Id;
var title = new StringBuilder($"Members of {target.Name} (`{target.Hid}`) in ");
if (targetSystem.Name != null)
title.Append($"{targetSystem.Name} (`{targetSystem.Hid}`)");
else
title.Append($"`{targetSystem.Hid}`");
if (opts.Search != null)
title.Append($" matching **{opts.Search}**");
await ctx.RenderMemberList(ctx.LookupContextFor(target.System), _db, target.System, title.ToString(), opts);
}
public enum AddRemoveOperation
{
Add,

View File

@@ -16,6 +16,7 @@ namespace PluralKit.Bot
public bool Reverse { get; set; }
public PrivacyLevel? PrivacyFilter { get; set; } = PrivacyLevel.Public;
public GroupId? GroupFilter { get; set; }
public string? Search { get; set; }
public bool SearchDescription { get; set; }
@@ -55,7 +56,7 @@ namespace PluralKit.Bot
PrivacyLevel.Public => "", // (default, no extra line needed)
_ => new ArgumentOutOfRangeException($"Couldn't find readable string for privacy filter {PrivacyFilter}")
});
return str.ToString();
}
@@ -63,6 +64,7 @@ namespace PluralKit.Bot
new DatabaseViewsExt.MemberListQueryOptions
{
PrivacyFilter = PrivacyFilter,
GroupFilter = GroupFilter,
Search = Search,
SearchDescription = SearchDescription
};