Skip to content

Commit

Permalink
Invalid command msg
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jul 29, 2024
1 parent ddf9b1f commit 168f0fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -88,7 +87,7 @@ default CommandCallable getCallable(String fullCommand, StringBuilder remainder)
return subCommand;
}
}
return this;
return root;
}

default CommandCallable getCallable(List<String> args, boolean allowRemainder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,22 +801,25 @@ public void run(LocalValueStore<Object> 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<String> validIds = new ArrayList<>(group.primarySubCommandIds());
List<String> 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<String> 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<String> validIds = new ArrayList<>(group.primarySubCommandIds());
List<String> 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;
}
Expand Down

0 comments on commit 168f0fd

Please sign in to comment.