From 9babde3c82aa6a73040fb1dd90f745c70266e2c4 Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 19 Nov 2020 17:58:57 -0500 Subject: [PATCH] Add basic command help functionality to pk;commands --- PluralKit.Bot/Commands/CommandTree.cs | 55 +++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index ff220c56..e6b79377 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -107,6 +107,8 @@ namespace PluralKit.Bot public static Command[] SwitchCommands = {Switch, SwitchOut, SwitchMove, SwitchDelete}; public static Command[] LogCommands = {LogChannel, LogChannelClear, LogEnable, LogDisable}; + + public static Command[] BlacklistCommands = {BlacklistAdd, BlacklistRemove, BlacklistShow}; private DiscordShardedClient _client; @@ -126,6 +128,8 @@ namespace PluralKit.Bot return HandleGroupCommand(ctx); if (ctx.Match("switch", "sw")) return HandleSwitchCommand(ctx); + if (ctx.Match("commands")) + return CommandHelpRoot(ctx); if (ctx.Match("ap", "autoproxy", "auto")) return ctx.Execute(Autoproxy, m => m.AutoproxyRoot(ctx)); if (ctx.Match("list", "find", "members", "search", "query", "l", "f", "fd")) @@ -151,8 +155,6 @@ namespace PluralKit.Bot else return ctx.Execute(Help, m => m.HelpRoot(ctx)); if (ctx.Match("explain")) return ctx.Execute(Explain, m => m.Explain(ctx)); - if (ctx.Match("commands")) - return ctx.Reply("For the list of commands, see the website: "); if (ctx.Match("message", "msg")) return ctx.Execute(Message, m => m.GetMessage(ctx)); if (ctx.Match("log")) @@ -174,7 +176,9 @@ namespace PluralKit.Bot return ctx.Execute(BlacklistRemove, m => m.SetBlacklisted(ctx, false)); else if (ctx.Match("list", "show")) return ctx.Execute(BlacklistShow, m => m.ShowBlacklisted(ctx)); - else return PrintCommandExpectedError(ctx, BlacklistAdd, BlacklistRemove, BlacklistShow); + else if (ctx.Match("commands")) + return PrintCommandList(ctx, "channel blacklisting", BlacklistCommands); + else return PrintCommandExpectedError(ctx, BlacklistCommands); if (ctx.Match("proxy", "enable", "disable")) return ctx.Execute(SystemProxy, m => m.SystemProxy(ctx)); if (ctx.Match("invite")) return ctx.Execute(Invite, m => m.Invite(ctx)); @@ -404,6 +408,51 @@ namespace PluralKit.Bot await PrintCommandNotFoundError(ctx, Switch, SwitchOut, SwitchMove, SwitchDelete, SystemFronter, SystemFrontHistory); } + private async Task CommandHelpRoot(Context ctx) + { + if (!ctx.HasNext()) + { + await ctx.Reply($"{Emojis.Error} You need to pass a target command.\nAvailable command help targets: `system`, `member`, `group`, `switch`, `log`, `blacklist`.\nFor the full list of commands, see the website: "); + return; + } + + switch (ctx.PeekArgument()) { + case "system": + case "systems": + case "s": + await PrintCommandList(ctx, "systems", SystemCommands); + break; + case "member": + case "members": + case "m": + await PrintCommandList(ctx, "members", MemberCommands); + break; + case "group": + case "groups": + case "g": + await PrintCommandList(ctx, "groups", GroupCommands); + break; + case "switch": + case "switches": + case "switching": + case "sw": + await PrintCommandList(ctx, "switching", SwitchCommands); + break; + case "log": + await PrintCommandList(ctx, "message logging", LogCommands); + break; + case "blacklist": + case "bl": + await PrintCommandList(ctx, "channel blacklisting", BlacklistCommands); + break; + // case "autoproxy": (add this when #232 is merged) + // todo: are there any commands that still need to be added? + default: + await ctx.Reply("For the full list of commands, see the website: "); + break; + } + } + private async Task PrintCommandNotFoundError(Context ctx, params Command[] potentialCommands) { var commandListStr = CreatePotentialCommandList(potentialCommands);