From 168f0fd9c1901b9af1996a3e0d380bf8bc443fec Mon Sep 17 00:00:00 2001 From: test Date: Mon, 29 Jul 2024 16:49:41 +1000 Subject: [PATCH] Invalid command msg --- .../manager/v2/command/CommandCallable.java | 3 +- .../manager/v2/command/CommandGroup.java | 5 +-- .../manager/v2/impl/pw/CommandManager2.java | 31 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandCallable.java b/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandCallable.java index ce11ca98..28642f2c 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandCallable.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandCallable.java @@ -66,7 +66,6 @@ default CommandCallable getCallable(String fullCommand, StringBuilder remainder) remainder.append(fullCommand); return this; } - String original = fullCommand; CommandGroup root = (CommandGroup) this; while (!fullCommand.isEmpty()) { String rootRemaining = fullCommand; @@ -88,7 +87,7 @@ default CommandCallable getCallable(String fullCommand, StringBuilder remainder) return subCommand; } } - return this; + return root; } default CommandCallable getCallable(List args, boolean allowRemainder) { diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandGroup.java b/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandGroup.java index f07c49d1..047206ba 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandGroup.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/command/CommandGroup.java @@ -177,8 +177,9 @@ public CommandGroup createSubGroup(String... aliases) { @Override public Object call(ArgumentStack stack) { if (!stack.hasNext()) { - throw new CommandUsageException(this, "No subcommand specified. Valid subcommands\n" + - "- " + StringMan.join(primarySubCommandIds(), "\n- ")); + String prefix = "/" + getFullPath(); + throw new CommandUsageException(this, "No subcommand specified (2). Valid subcommands\n" + + "- `" + prefix + StringMan.join(primarySubCommandIds(), "`\n- `" + prefix) + "`"); } String arg = stack.consumeNext(); CommandCallable subcommand = subcommands.get(arg.toLowerCase()); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java index 40a0f94f..2e6168da 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java @@ -801,22 +801,25 @@ public void run(LocalValueStore existingLocals, IMessageIO io, String fu } StringBuilder remaining = new StringBuilder(); CommandCallable callable = commands.getCallable(fullCmdStr, remaining); - if (callable instanceof CommandGroup group && !remaining.isEmpty()) { + if (callable instanceof CommandGroup group) { if (returnNotFound) { - String commandId = fullCmdStr.replace(remaining.toString(), ""); - if (commandId.isEmpty()) { - commandId = fullCmdStr.split(" ")[0]; + String prefix = group.getFullPath(); + prefix = "/" + prefix + (prefix.isEmpty() ? "" : " "); + if (!remaining.isEmpty()) { + String[] lastCommandIdSplit = remaining.toString().split(" "); + String lastCommandId = lastCommandIdSplit[0]; + List validIds = new ArrayList<>(group.primarySubCommandIds()); + List closest = StringMan.getClosest(lastCommandId, validIds, false); + if (closest.size() > 5) closest = closest.subList(0, 5); + + io.send("No subcommand found for `" + lastCommandId + "`\n" + + "Did you mean:\n- `" + prefix + StringMan.join(closest, "`\n- `" + prefix) + + "`\n\nSee also: " + CM.help.find_command.cmd.toSlashMention()); + } else { + Set options = group.primarySubCommandIds(); + io.send("No subcommand found for `" + prefix.trim() + "`. Options:\n" + + "`" + prefix + StringMan.join(options, "`\n`" + prefix) + "`"); } - // last string in split by space - String[] lastCommandIdSplit = commandId.split(" "); - String lastCommandId = lastCommandIdSplit[lastCommandIdSplit.length - 1]; - List validIds = new ArrayList<>(group.primarySubCommandIds()); - List closest = StringMan.getClosest(lastCommandId, validIds, false); - if (closest.size() > 5) closest = closest.subList(0, 5); - - io.send("No command found for `" + commandId + "`\n" + - "Did you mean:\n- " + group.getFullPath() + StringMan.join(closest, "\n- " + group.getFullPath()) + - "\n\nSee also: " + CM.help.find_command.cmd.toSlashMention()); } return; }