Add member find/search command

This commit is contained in:
Ske 2020-02-13 16:49:45 +01:00
parent 883796de16
commit a76d7a6777
2 changed files with 33 additions and 0 deletions

View File

@ -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 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 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 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] <search term>", "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 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 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"); 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); return HandleSwitchCommand(ctx);
if (ctx.Match("ap", "autoproxy", "auto")) if (ctx.Match("ap", "autoproxy", "auto"))
return ctx.Execute<Autoproxy>(Autoproxy, m => m.AutoproxyRoot(ctx)); return ctx.Execute<Autoproxy>(Autoproxy, m => m.AutoproxyRoot(ctx));
if (ctx.Match("list", "l", "members"))
return ctx.Execute<SystemList>(SystemList, m => m.MemberList(ctx, ctx.System));
if (ctx.Match("f", "find", "search", "query", "fd"))
return ctx.Execute<SystemList>(SystemFind, m => m.MemberFind(ctx, ctx.System));
if (ctx.Match("link")) if (ctx.Match("link"))
return ctx.Execute<SystemLink>(Link, m => m.LinkSystem(ctx)); return ctx.Execute<SystemLink>(Link, m => m.LinkSystem(ctx));
if (ctx.Match("unlink")) if (ctx.Match("unlink"))
@ -173,6 +178,8 @@ namespace PluralKit.Bot
await ctx.Execute<SystemEdit>(SystemProxy, m => m.SystemProxy(ctx)); await ctx.Execute<SystemEdit>(SystemProxy, m => m.SystemProxy(ctx));
else if (ctx.Match("list", "l", "members")) else if (ctx.Match("list", "l", "members"))
await ctx.Execute<SystemList>(SystemList, m => m.MemberList(ctx, ctx.System)); await ctx.Execute<SystemList>(SystemList, m => m.MemberList(ctx, ctx.System));
else if (ctx.Match("find", "search", "query", "fd", "s"))
await ctx.Execute<SystemList>(SystemFind, m => m.MemberFind(ctx, ctx.System));
else if (ctx.Match("f", "front", "fronter", "fronters")) else if (ctx.Match("f", "front", "fronter", "fronters"))
{ {
if (ctx.Match("h", "history")) if (ctx.Match("h", "history"))
@ -208,6 +215,8 @@ namespace PluralKit.Bot
} }
else if (ctx.Match("list", "l", "members")) else if (ctx.Match("list", "l", "members"))
await ctx.Execute<SystemList>(SystemList, m => m.MemberList(ctx, target)); await ctx.Execute<SystemList>(SystemList, m => m.MemberList(ctx, target));
else if (ctx.Match("find", "search", "query", "fd", "s"))
await ctx.Execute<SystemList>(SystemFind, m => m.MemberFind(ctx, ctx.System));
else if (ctx.Match("f", "front", "fronter", "fronters")) else if (ctx.Match("f", "front", "fronter", "fronters"))
{ {
if (ctx.Match("h", "history")) if (ctx.Match("h", "history"))

View File

@ -107,5 +107,29 @@ namespace PluralKit.Bot
else else
await RenderMemberList(ctx, system, canShowPrivate, 25, embedTitle, _ => true, ShortRenderer); 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);
}
} }
} }