diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index aa7f095d..a2b8e8e2 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -19,6 +19,7 @@ namespace PluralKit.Bot public static Command SystemTimezone = new Command("system timezone", "system timezone [timezone]", "Changes your system's time zone"); public static Command SystemProxy = new Command("system proxy", "system proxy [on|off]", "Enables or disables message proxying in a specific server"); public static Command SystemList = new Command("system list", "system [system] list [full]", "Lists a system's members"); + public static Command SystemFind = new Command("system find", "system [system] find [full] ", "Searches a system's members given a search term"); public static Command SystemFronter = new Command("system fronter", "system [system] fronter", "Shows a system's fronter(s)"); public static Command SystemFrontHistory = new Command("system fronthistory", "system [system] fronthistory", "Shows a system's front history"); public static Command SystemFrontPercent = new Command("system frontpercent", "system [system] frontpercent [timespan]", "Shows a system's front breakdown"); @@ -91,6 +92,10 @@ namespace PluralKit.Bot return HandleSwitchCommand(ctx); if (ctx.Match("ap", "autoproxy", "auto")) return ctx.Execute(Autoproxy, m => m.AutoproxyRoot(ctx)); + if (ctx.Match("list", "l", "members")) + return ctx.Execute(SystemList, m => m.MemberList(ctx, ctx.System)); + if (ctx.Match("f", "find", "search", "query", "fd")) + return ctx.Execute(SystemFind, m => m.MemberFind(ctx, ctx.System)); if (ctx.Match("link")) return ctx.Execute(Link, m => m.LinkSystem(ctx)); if (ctx.Match("unlink")) @@ -173,6 +178,8 @@ namespace PluralKit.Bot await ctx.Execute(SystemProxy, m => m.SystemProxy(ctx)); else if (ctx.Match("list", "l", "members")) await ctx.Execute(SystemList, m => m.MemberList(ctx, ctx.System)); + else if (ctx.Match("find", "search", "query", "fd", "s")) + await ctx.Execute(SystemFind, m => m.MemberFind(ctx, ctx.System)); else if (ctx.Match("f", "front", "fronter", "fronters")) { if (ctx.Match("h", "history")) @@ -208,6 +215,8 @@ namespace PluralKit.Bot } else if (ctx.Match("list", "l", "members")) await ctx.Execute(SystemList, m => m.MemberList(ctx, target)); + else if (ctx.Match("find", "search", "query", "fd", "s")) + await ctx.Execute(SystemFind, m => m.MemberFind(ctx, ctx.System)); else if (ctx.Match("f", "front", "fronter", "fronters")) { if (ctx.Match("h", "history")) diff --git a/PluralKit.Bot/Commands/SystemList.cs b/PluralKit.Bot/Commands/SystemList.cs index 8f26b0ef..5de969a3 100644 --- a/PluralKit.Bot/Commands/SystemList.cs +++ b/PluralKit.Bot/Commands/SystemList.cs @@ -107,5 +107,29 @@ namespace PluralKit.Bot else await RenderMemberList(ctx, system, canShowPrivate, 25, embedTitle, _ => true, ShortRenderer); } + + public async Task MemberFind(Context ctx, PKSystem system) + { + if (system == null) throw Errors.NoSystemError; + ctx.CheckSystemPrivacy(system, system.MemberListPrivacy); + + var shouldShowLongList = ctx.Match("f", "full", "big", "details", "long"); + var canShowPrivate = ctx.Match("a", "all", "everyone", "private"); + + var searchTerm = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must specify a search term."); + + var embedTitle = system.Name != null + ? $"Members of {system.Name.SanitizeMentions()} (`{system.Hid}`) **{searchTerm.SanitizeMentions()}**" + : $"Members of `{system.Hid}` matching **{searchTerm.SanitizeMentions()}**"; + + bool Filter(PKMember member) => + member.Name.Contains(searchTerm, StringComparison.InvariantCultureIgnoreCase) || + (member.DisplayName?.Contains(searchTerm, StringComparison.InvariantCultureIgnoreCase) ?? false); + + if (shouldShowLongList) + await RenderMemberList(ctx, system, canShowPrivate, 5, embedTitle, Filter, LongRenderer); + else + await RenderMemberList(ctx, system, canShowPrivate, 25, embedTitle, Filter, ShortRenderer); + } } } \ No newline at end of file