some sheeet

added a lock and finished the broken half created command manager (for
now)

Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
lever1209 2021-12-07 16:01:12 -04:00
commit 7a57e8a39d
No known key found for this signature in database
GPG key ID: EEBCBB60C9DFC782
14 changed files with 298 additions and 103 deletions

View file

@ -8,6 +8,7 @@ import java.util.List;
import net.dv8tion.jda.api.EmbedBuilder;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.global.Tools;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
@ -24,8 +25,17 @@ public class Help implements GuildCommandInterface {
@Override
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
if (argumentMap.isEmpty() || argumentMap.get("dev") != null) {
EmbedBuilder embed = new EmbedBuilder().setTitle("Commands:");
boolean isDevEnabled = argumentMap.get("dev") != null;
final List<HelpPage> deniedPages = new ArrayList<HelpPage>();
deniedPages.add(HelpPage.DEV);
deniedPages.add(HelpPage.EGG);
deniedPages.add(HelpPage.TESTING);
// System.out.println(argumentMap.size()+":"+devEnabled+"\n"+argumentMap.toString());
if (argumentMap.isEmpty() || (isDevEnabled && argumentMap.size() == 1)) {
EmbedBuilder embed = new EmbedBuilder().setTitle(isDevEnabled ? "^Commands:" : "Commands:");
HashMap<HelpPage, List<String>> commandHash = new HashMap<HelpPage, List<String>>();
@ -40,8 +50,7 @@ public class Help implements GuildCommandInterface {
}
for (HelpPage i : HelpPage.values()) {
if ((i == HelpPage.DEV || i == HelpPage.TESTING || i == HelpPage.EGG)
&& argumentMap.get("dev") == null) {
if (deniedPages.contains(i) && argumentMap.get("dev") == null) {
} else if (commandHash.get(i) != null) {
@ -93,69 +102,65 @@ public class Help implements GuildCommandInterface {
embed.setTimestamp(Instant.now());
embed.setColor(0);
blob.getEvent().getChannel().sendMessageEmbeds(embed.build()).queue();
blob.getChannel().sendMessageEmbeds(embed.build()).queue();
return;
} else if (argumentMap.get("commandName") != null) {
GuildCommandInterface command = manager.getCommand(argumentMap.get("commandName").getWildCardString());
if (command.getHelpPage() != HelpPage.EGG) {
if (command != null && ((deniedPages.contains(command.getHelpPage()) && isDevEnabled)
|| !deniedPages.contains(command.getHelpPage()))) {
if (!command.isNSFW()) {
EmbedBuilder eB = new EmbedBuilder();
eB.setColor(0);
StringBuilder sB = new StringBuilder();
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.addField("Help info:", "This command does not contain help information", false);
}
eB.setColor(0);
StringBuilder sB = new StringBuilder();
sB.append(endAilias);
try {
eB.addField("Usage:", command.getUsage(), false);
eB.setFooter("Page: " + command.getHelpPage().toString());
if (command.getCommandCalls().length > 1) {
for (int i = 1; i < command.getCommandCalls().length; i++) {
sB.append("`"+command.getCommandCalls()[i]+"` ");
}
sB.append("\n");
}
if (command.isNSFW()) {
sB.append("Is nsfw: "+command.isNSFW());
}
if (command.getRequiredPermission() != null) {
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();
blob.getChannel().sendMessageEmbeds(eB.build()).queue();
} else {
blob.getChannel().sendMessage("Sorry, but you are not allowed to view information about that command here, try somewhere more private").queue();
}
} else {
throw new NullPointerException("Invalid input");
// Tools.wrongUsage(blob.getChannel(), command);
blob.getChannel().sendMessage(
"Sorry, but there is no command named: " + argumentMap.get("commandName").getWildCardString())
.queue();
}
}
// ##########################################################################################################################
// ##########################################################################################################################
// ##########################################################################################################################
// ##########################################################################################################################
// ##########################################################################################################################
// }
// https://download.java.net/java/GA/jdk16/7863447f0ab643c585b9bdebf67c69db/36/GPL/openjdk-16_linux-x64_bin.tar.gz
}
@Override
@ -179,7 +184,7 @@ 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]";
@ -191,8 +196,8 @@ public class Help implements GuildCommandInterface {
args.put("commandName", new Argument("commandName").setPosition(0).setIsWildcard(true));
args.put("dev", new Argument("dev", (CommandBlob blob) -> {
blob.getChannel().sendMessage("dev").queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true));
blob.getChannel().sendMessage("DEV FLAG USED").queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setPermissionLevel("infopermission"));
return args;
}