completed support for optional wildcards

Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
deepCurse 2021-12-07 08:40:06 -04:00
parent addfa80197
commit 153e76b3e0
No known key found for this signature in database
GPG key ID: EEBCBB60C9DFC782
4 changed files with 85 additions and 81 deletions

View file

@ -39,6 +39,7 @@ public interface CommandInterface { // TODO rewrite to implement type args?
public default String getUsage() {
return Global.prefix + getCommandName();
}
public default int getTimeout() {
return 0;
}
@ -81,4 +82,8 @@ public interface CommandInterface { // TODO rewrite to implement type args?
}
}
public default String getCompleteUsage() {
return Global.prefix + getCommandName();
}
}

View file

@ -3,6 +3,7 @@ package pkg.deepCurse.nopalmo.command.commands.info;
import java.util.HashMap;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
@ -40,4 +41,10 @@ public class Git implements DualCommandInterface {
public String getHelp() {
return "Posts my github link";
}
@Override
public String getCompleteUsage() {
return Global.prefix + getCommandName() + " [-test]";
}
}

View file

@ -24,7 +24,7 @@ public class Help implements GuildCommandInterface {
@Override
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
if (argumentMap.isEmpty()) {
if (argumentMap.isEmpty() || argumentMap.get("dev") != null) {
EmbedBuilder embed = new EmbedBuilder().setTitle("Commands:");
HashMap<HelpPage, List<String>> commandHash = new HashMap<HelpPage, List<String>>();
@ -40,7 +40,10 @@ public class Help implements GuildCommandInterface {
}
for (HelpPage i : HelpPage.values()) {
if (commandHash.get(i) != null) {
if ((i == HelpPage.DEV || i == HelpPage.TESTING || i == HelpPage.EGG)
&& argumentMap.get("dev") == null) {
} else if (commandHash.get(i) != null) {
StringBuilder sB = new StringBuilder();
@ -56,6 +59,7 @@ public class Help implements GuildCommandInterface {
embed.addField(i.toString(), sB.toString(), true);
}
}
StringBuilder sB = new StringBuilder();
@ -92,8 +96,52 @@ public class Help implements GuildCommandInterface {
blob.getEvent().getChannel().sendMessageEmbeds(embed.build()).queue();
return;
} else {
} else if (argumentMap.get("commandName") != null) {
GuildCommandInterface command = manager.getCommand(argumentMap.get("commandName").getWildCardString());
if (command.getHelpPage() != HelpPage.EGG) {
EmbedBuilder eB = new EmbedBuilder();
eB.setTitle("Help results for: " + command.getCommandName());
if (command.getHelp() != null) {
eB.addField("Help info:", command.getHelp(), false);
}
eB.addField("Usage:", command.getUsage(), false);
eB.setFooter("Page: " + command.getHelpPage().toString());
String alias = "`";
for (int i = 1; i < command.getCommandCalls().length; i++) {
if (i == 1) {
alias += command.getCommandCalls()[i];
} else {
alias += ", " + command.getCommandCalls()[i];
}
}
alias += "`";
String endAilias = "";
if (!alias.contentEquals("``")) {
endAilias = "Aliases: " + alias + "\n";
} else {
endAilias = "Aliases: none\n";
}
eB.setColor(0);
StringBuilder sB = new StringBuilder();
sB.append(endAilias);
try {
sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
} catch (NullPointerException e) {
}
if (command.getTimeout() > 0) {
sB.append("Usage Timeout: " + command.getTimeout() + "\n");
}
sB.append("Premium: " + command.isPremium() + "\n");
eB.addField("Misc", sB.toString(), false);
blob.getEvent().getChannel().sendMessageEmbeds(eB.build()).queue();
} else {
throw new NullPointerException("Invalid input");
}
}
// ##########################################################################################################################
@ -105,64 +153,6 @@ public class Help implements GuildCommandInterface {
// ##########################################################################################################################
// ##########################################################################################################################
// try {
// GuildCommandInterface command = manager.getCommand(String.join("", blob.getArgs()));
//
// // event.getChannel().sendMessage("Command help for `" + command.commandName() +
// // "`:\n\tUsage: "+ command.usageString() + "\n" +
// // command.helpString()).queue();
// if (command.getHelpPage() != HelpPage.EGG) {
// EmbedBuilder eB = new EmbedBuilder();
// eB.setTitle("Help results for: " + command.getCommandName());
// if (command.getHelp() != null) {
// eB.addField("Help info:", command.getHelp(), false);
// }
// eB.addField("Usage:", command.getUsage(), false);
// eB.setFooter("Page: " + command.getHelpPage().toString());
// String alias = "`";
// for (int i = 1; i < command.getCommandCalls().length; i++) {
//
// if (i == 1) {
// alias += command.getCommandCalls()[i];
// } else {
// alias += ", " + command.getCommandCalls()[i];
// }
// }
// alias += "`";
//
// String endAilias = "";
//
// if (!alias.contentEquals("``")) {
// endAilias = "Aliases: " + alias + "\n";
// } else {
// endAilias = "Aliases: none\n";
// }
// eB.setColor(0);
// StringBuilder sB = new StringBuilder();
// sB.append(endAilias);
// try {
// sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
// } catch (NullPointerException e) {
// }
// if (command.getTimeout() > 0) {
// sB.append("Usage Timeout: " + command.getTimeout() + "\n");
// }
// sB.append("Premium: " + command.isPremium() + "\n");
// eB.addField("Misc", sB.toString(), false);
// blob.getEvent().getChannel().sendMessageEmbeds(eB.build()).queue();
// } else {
// throw new NullPointerException("Invalid input");
// }
//
// } catch (java.lang.NullPointerException e) {
// e.printStackTrace();
// blob.getEvent().getChannel()
// .sendMessage("The command `" + String.join("", blob.getArgs()) + "` does not exist!\n" + "Use `"
// + Global.prefix + getCommandCalls()[0] + "` for a list of all my commands!")
// .queue();
// return;
//
// }
// }
// https://download.java.net/java/GA/jdk16/7863447f0ab643c585b9bdebf67c69db/36/GPL/openjdk-16_linux-x64_bin.tar.gz
@ -189,6 +179,11 @@ public class Help implements GuildCommandInterface {
public String getUsage() {
return Global.prefix + getCommandCalls()[0] + " [Command name]";
}
@Override
public String getCompleteUsage() {
return Global.prefix + getCommandCalls()[0] + " [Command name | -dev]";
}
@Override
public HashMap<String, Argument> getArguments() {

View file

@ -131,7 +131,7 @@ public class GuildCommandManager extends CommandManager {
if (argSkipCount <= 0) {
if (guildCommand.getArguments() != null) {
if (positionalArgs.get(i) == null) {
// if (positionalArgs.get(i) == null) {
if (x.startsWith(Argument.argumentPrefix)) {
@ -163,27 +163,24 @@ public class GuildCommandManager extends CommandManager {
}
}
} else {
Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
remainsValid = false;
if (positionalArgs.get(i).getIsWildcard()) {
argumentList.put(positionalArgs.get(i).getArgName(),
positionalArgs.get(i).setWildCardString(x));
} else {
Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
remainsValid = false;
}
if (positionalArgs.get(i).isAutoStartRunnable()
&& positionalArgs.get(i).getRunnableArg() != null) {
positionalArgs.get(i).getRunnableArg()
.run(new CommandBlob(commandBlob));
}
}
}
} else {
if (guildCommand.getArguments().get(x) == null) {
if (positionalArgs.get(i).getIsWildcard()) {
argumentList.put(positionalArgs.get(i).getArgName(),
positionalArgs.get(i).setWildCardString(x));
}
if (positionalArgs.get(i).isAutoStartRunnable()
&& positionalArgs.get(i).getRunnableArg() != null) {
positionalArgs.get(i).getRunnableArg()
.run(new CommandBlob(commandBlob));
}
} else {
// argumentList.put(x, guildCommand.getArguments().get(x));
// i--;
}
}
// }
} else {
Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
remainsValid = false;
}
}
}