mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 14:27:54 +00:00
implement command root
This commit is contained in:
parent
c1ed7487d7
commit
15ffd16c01
11 changed files with 107 additions and 170 deletions
|
|
@ -1,40 +1,16 @@
|
|||
using Humanizer;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
namespace PluralKit.Bot;
|
||||
|
||||
public partial class CommandTree
|
||||
{
|
||||
private async Task PrintCommandNotFoundError(Context ctx, params Command[] potentialCommands)
|
||||
private async Task PrintCommandList(Context ctx, string subject, string commands)
|
||||
{
|
||||
var commandListStr = CreatePotentialCommandList(ctx.DefaultPrefix, potentialCommands);
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Error} Unknown command `{ctx.DefaultPrefix}{ctx.FullCommand().Truncate(100)}`. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
||||
}
|
||||
|
||||
private async Task PrintCommandExpectedError(Context ctx, params Command[] potentialCommands)
|
||||
{
|
||||
var commandListStr = CreatePotentialCommandList(ctx.DefaultPrefix, potentialCommands);
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Error} You need to pass a command. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
||||
}
|
||||
|
||||
private static string CreatePotentialCommandList(string prefix, params Command[] potentialCommands)
|
||||
{
|
||||
return string.Join("\n", potentialCommands.Select(cmd => $"- **{prefix}{cmd.Usage}** - *{cmd.Description}*"));
|
||||
}
|
||||
|
||||
private async Task PrintCommandList(Context ctx, string subject, params Command[] commands)
|
||||
{
|
||||
var str = CreatePotentialCommandList(ctx.DefaultPrefix, commands);
|
||||
await ctx.Reply(
|
||||
$"Here is a list of commands related to {subject}:",
|
||||
embed: new Embed()
|
||||
{
|
||||
Description = $"{str}\nFor a full list of possible commands, see <https://pluralkit.me/commands>.",
|
||||
Description = $"{commands}\nFor a full list of possible commands, see <https://pluralkit.me/commands>.",
|
||||
Color = DiscordUtils.Blue,
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ public partial class CommandTree
|
|||
{
|
||||
return command switch
|
||||
{
|
||||
Commands.CommandsList(var param, _) => PrintCommandList(ctx, param.subject, Parameters.GetRelatedCommands(ctx.DefaultPrefix, param.subject)),
|
||||
Commands.Dashboard => ctx.Execute<Help>(Dashboard, m => m.Dashboard(ctx)),
|
||||
Commands.Explain => ctx.Execute<Help>(Explain, m => m.Explain(ctx)),
|
||||
Commands.Help(_, var flags) => ctx.Execute<Help>(Help, m => m.HelpRoot(ctx, flags.show_embed)),
|
||||
|
|
@ -330,70 +331,5 @@ public partial class CommandTree
|
|||
ctx.Reply(
|
||||
$"{Emojis.Error} Parsed command {ctx.Parameters.Callback().AsCode()} not implemented in PluralKit.Bot!"),
|
||||
};
|
||||
// Legacy command routing - these are kept for backwards compatibility until fully migrated to new system
|
||||
if (ctx.Match("commands", "cmd", "c"))
|
||||
return CommandHelpRoot(ctx);
|
||||
}
|
||||
|
||||
private async Task CommandHelpRoot(Context ctx)
|
||||
{
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
await ctx.Reply(
|
||||
"Available command help targets: `system`, `member`, `group`, `switch`, `config`, `autoproxy`, `log`, `blacklist`."
|
||||
+ $"\n- **{ctx.DefaultPrefix}commands <target>** - *View commands related to a help target.*"
|
||||
+ "\n\nFor the full list of commands, see the website: <https://pluralkit.me/commands>");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ctx.PeekArgument())
|
||||
{
|
||||
case "system":
|
||||
case "systems":
|
||||
case "s":
|
||||
case "account":
|
||||
case "acc":
|
||||
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 "config":
|
||||
case "cfg":
|
||||
await PrintCommandList(ctx, "settings", ConfigCommands);
|
||||
break;
|
||||
case "serverconfig":
|
||||
case "guildconfig":
|
||||
case "scfg":
|
||||
await PrintCommandList(ctx, "server settings", ServerConfigCommands);
|
||||
break;
|
||||
case "autoproxy":
|
||||
case "ap":
|
||||
await PrintCommandList(ctx, "autoproxy", AutoproxyCommands);
|
||||
break;
|
||||
default:
|
||||
await ctx.Reply("For the full list of commands, see the website: <https://pluralkit.me/commands>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,6 +55,11 @@ public class Parameters
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetRelatedCommands(string prefix, string subject)
|
||||
{
|
||||
return CommandsMethods.GetRelatedCommands(prefix, subject);
|
||||
}
|
||||
|
||||
public string Callback()
|
||||
{
|
||||
return _cb;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue