added almost complete support for bontebok

also some minor patches and whatever else needed to be done

Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
lever1209 2021-12-14 13:46:36 -04:00
commit 1f32a0fa23
No known key found for this signature in database
GPG key ID: EEBCBB60C9DFC782
19 changed files with 361 additions and 187 deletions

View file

@ -37,31 +37,34 @@ public interface CommandInterface { // TODO rewrite to implement type args?
public default String getUsage(boolean hasPermissionInfo) { public default String getUsage(boolean hasPermissionInfo) {
StringBuilder sB = new StringBuilder(); StringBuilder sB = new StringBuilder();
for (Argument i : getArguments().values()) { if (getArguments() != null) {
if ((i.isDeveloper() && hasPermissionInfo) || !i.isDeveloper()) { for (Argument i : getArguments().values()) {
if (i.isRequired()) { if ((i.isDeveloper() && hasPermissionInfo) || !i.isDeveloper()) {
sB.append("<"); if (i.isRequired()) {
} else { sB.append("<");
sB.append("["); } else {
} sB.append("[");
}
sB.append((i.isPrefixRequired() ? Argument.argumentPrefix : "")+i.getArgName()); sB.append((i.isPrefixRequired() ? Argument.argumentPrefix : "") + i.getArgName());
if (i.getAliases() != null) { if (i.getAliases() != null) {
for (String j : i.getAliases()) { for (String j : i.getAliases()) {
sB.append(" | " + (i.isPrefixRequired() ? Argument.argumentPrefix : "") + j); sB.append(" | " + (i.isPrefixRequired() ? Argument.argumentPrefix : "") + j);
}
}
if (i.isRequired()) {
sB.append("> ");
} else {
sB.append("] ");
} }
} }
if (i.isRequired()) {
sB.append("> ");
} else {
sB.append("] ");
}
} }
return Global.prefix + getCommandName() + " " + sB.toString().trim();
} }
return Global.prefix + getCommandName() + " " + sB.toString().trim(); return Global.prefix + getCommandName();
} }
public default int getTimeout() { public default int getTimeout() {
@ -103,42 +106,4 @@ public interface CommandInterface { // TODO rewrite to implement type args?
} }
} }
} }
/*
*
*
* StringBuilder sB = new StringBuilder(); if (getArguments() != null) { for
* (String i : getArguments().keySet()) { // sB.delete(0, sB.length()); if
* (!getArguments().get(i).isDeveloper() || (hasPermissionInfo &&
* getArguments().get(i).isDeveloper())) {
* sB.append(getArguments().get(i).isRequired() ? "<" : "[");
*
* sB.append((getArguments().get(i).isPrefixRequired() ?
* sB.append(Argument.argumentPrefix) : ""));
*
* sB.append(i); // System.out.println("01"+sB.toString()); // for (int j = 0; j
* < getArguments().get(i).getAliases().size(); j++) { // sB.append((j <
* getArguments().get(i).getAliases().size() ? " | " : "") // +
* (getArguments().get(i).isPrefixRequired() ?
* sB.append(Argument.argumentPrefix) : "") // +
* getArguments().get(i).getAliases().get(j)); //
* System.out.println("02"+sB.toString()); // }
* sB.append(getArguments().get(i).isRequired() ? "> " : "] ");
* System.out.println("[000] :\t"+sB.toString()); } } }
*
* System.out.println("[001] :\t"+sB.toString()); return (Global.prefix +
* getCommandName() + " " + sB.toString()).strip();
*
* //StringBuilder sB = new StringBuilder(); //if (getArguments() != null) { //
* for (String i : getArguments().keySet()) { // if
* (!getArguments().get(i).isDeveloper() // || (hasPermissionInfo &&
* getArguments().get(i).isDeveloper())) { //
* sB.append(getArguments().get(i).isRequired() ? "<" : "["); // if
* (getArguments().get(i).isPrefixRequired()) { //
* sB.append(Argument.argumentPrefix); // } // sB.append(i); // for (int j = 0;
* j < getArguments().get(i).getAliases().size(); j++) { // sB.append((j <
* getArguments().get(i).getAliases().size() ? " | " : "") // +
* getArguments().get(i).getAliases().get(j)); // } //
* sB.append(getArguments().get(i).isRequired() ? "> " : "] "); // } // } //} //
* //return (Global.prefix + getCommandName() + " " + sB.toString()).strip();
*/

View file

@ -0,0 +1,45 @@
package pkg.deepCurse.nopalmo.command.commands.fun;
import java.util.HashMap;
import org.jetbrains.annotations.Nullable;
import net.dv8tion.jda.api.entities.Member;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
public class Stupid implements GuildCommandInterface {
@Override
public String[] getCommandCalls() {
return new String[] { "stupid", "dumb" };
}
@Override
public HelpPage getHelpPage() {
return HelpPage.Fun;
}
@Override
public String getHelp() {
return "This calls someone stupid, stupid";
}
@Override
public @Nullable HashMap<String, Argument> getArguments() {
return null;
}
@Override
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
StringBuilder sB = new StringBuilder();
for (Member i : blob.getMessage().getMentionedMembers()) {
sB.append(i.getAsMention() + " ");
}
blob.getMessage().delete().queue();
blob.getChannel().sendMessage(blob.getAuthor().getName() + " calls you stupid! " + sB.toString()).queue();
}
}

View file

@ -27,12 +27,12 @@ public class Test implements GuildCommandInterface {
@Override @Override
public boolean isNSFW() { public boolean isNSFW() {
return true; return false;
} }
@Override @Override
public int getPremiumLevel() { public int getPremiumLevel() {
return 1; return 0;
} }
@Override @Override

View file

@ -18,32 +18,32 @@ public class Help implements GuildCommandInterface {
public final CommandManager manager; public final CommandManager manager;
public static final List<HelpPage> deniedPages = new ArrayList<HelpPage>();
public Help(CommandManager m) { public Help(CommandManager m) {
this.manager = m; this.manager = m;
deniedPages.add(HelpPage.DEV);
deniedPages.add(HelpPage.EGG);
deniedPages.add(HelpPage.TESTING);
} }
@Override @Override
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception { public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
boolean isDevEnabled = argumentMap.get("dev") != null; // boolean blob.isDeveloper() = argumentMap.get("dev") != null;
final List<HelpPage> deniedPages = new ArrayList<HelpPage>();
deniedPages.add(HelpPage.DEV);
deniedPages.add(HelpPage.EGG);
deniedPages.add(HelpPage.TESTING);
if (argumentMap.get("commandName") == null) { if (argumentMap.get("commandName") == null) {
EmbedBuilder embed = new EmbedBuilder().setTitle(isDevEnabled ? "^Commands:" : "Commands:"); EmbedBuilder embed = new EmbedBuilder().setTitle(
blob.isDeveloper() ? "^Commands:" + blob.isDeveloper() : "Commands:" + blob.isDeveloper());
HashMap<HelpPage, ArrayList<String>> commandHash = new HashMap<HelpPage, ArrayList<String>>(); HashMap<HelpPage, ArrayList<String>> commandHash = new HashMap<HelpPage, ArrayList<String>>();
// TODO yet another rewrite
// TODO add command to log a string // TODO add command to log a string
for (HelpPage i : HelpPage.values()) { for (HelpPage i : HelpPage.values()) {
ArrayList<String> commandNameList = commandHash.get(i); ArrayList<String> commandNameList = commandHash.get(i);
for (CommandInterface command : manager.getCommands()) { for (CommandInterface command : manager.getCommands()) {
if (!(deniedPages.contains(i) && argumentMap.get("dev") == null)) { if (!(deniedPages.contains(i) && !blob.isDeveloper())) {
if (command.getHelpPage() == i) { if (command.getHelpPage() == i) {
if (commandNameList == null) { if (commandNameList == null) {
commandNameList = new ArrayList<String>(); commandNameList = new ArrayList<String>();
@ -60,7 +60,7 @@ public class Help implements GuildCommandInterface {
} }
commandNameList = null; commandNameList = null;
} }
// blob.getChannel().sendMessage(commandHash.toString()).queue(); // blob.getChannel().sendMessage(commandHash.toString()).queue();
for (HelpPage i : HelpPage.values()) { for (HelpPage i : HelpPage.values()) {
@ -110,17 +110,17 @@ public class Help implements GuildCommandInterface {
CommandInterface ping = blob.getCommandManager().getCommand("ping"); CommandInterface ping = blob.getCommandManager().getCommand("ping");
if (ping != null) { if (ping != null) {
sB.append("`" + ping.getUsage(isDevEnabled) + "`\n"); sB.append("`" + ping.getUsage(blob.isDeveloper()) + "`\n");
} }
CommandInterface info = blob.getCommandManager().getCommand("info"); CommandInterface info = blob.getCommandManager().getCommand("info");
if (info != null) { if (info != null) {
sB.append("`" + info.getUsage(isDevEnabled) + "`\n"); sB.append("`" + info.getUsage(blob.isDeveloper()) + "`\n");
} }
CommandInterface prefix = blob.getCommandManager().getCommand("prefix"); CommandInterface prefix = blob.getCommandManager().getCommand("prefix");
if (prefix != null) { if (prefix != null) {
sB.append("`" + prefix.getUsage(isDevEnabled) + "`\n"); sB.append("`" + prefix.getUsage(blob.isDeveloper()) + "`\n");
} }
embed.addField("Information:", "Commands to take note of:\n" + sB, false); embed.addField("Information:", "Commands to take note of:\n" + sB, false);
@ -136,7 +136,7 @@ public class Help implements GuildCommandInterface {
CommandInterface command = manager.getCommand(argumentMap.get("commandName").getWildCardString()); CommandInterface command = manager.getCommand(argumentMap.get("commandName").getWildCardString());
if (command != null && ((deniedPages.contains(command.getHelpPage()) && isDevEnabled) if (command != null && ((deniedPages.contains(command.getHelpPage()) && blob.isDeveloper())
|| !deniedPages.contains(command.getHelpPage()))) { || !deniedPages.contains(command.getHelpPage()))) {
if (!blob.isFromGuild() ? true : !(command.isNSFW() && !((TextChannel) blob.getChannel()).isNSFW())) { if (!blob.isFromGuild() ? true : !(command.isNSFW() && !((TextChannel) blob.getChannel()).isNSFW())) {
EmbedBuilder eB = new EmbedBuilder(); EmbedBuilder eB = new EmbedBuilder();
@ -151,7 +151,7 @@ public class Help implements GuildCommandInterface {
eB.addField("Help info:", "This command does not contain help information", false); eB.addField("Help info:", "This command does not contain help information", false);
} }
eB.addField("Usage:", "`" + command.getUsage(isDevEnabled) + "`", false); eB.addField("Usage:", "`" + command.getUsage(blob.isDeveloper()) + "`", false);
eB.addField("Page:", command.getHelpPage().toString(), true); // ("Page: " + eB.addField("Page:", command.getHelpPage().toString(), true); // ("Page: " +
// command.getHelpPage().toString()); // command.getHelpPage().toString());
@ -221,8 +221,8 @@ public class Help implements GuildCommandInterface {
HashMap<String, Argument> args = new HashMap<String, Argument>(); HashMap<String, Argument> args = new HashMap<String, Argument>();
args.put("commandName", new Argument("commandName").setPosition(0).setIsWildcard(true)); args.put("commandName", new Argument("commandName").setPosition(0).setIsWildcard(true));
args.put("dev", new Argument("dev").setPrefixRequirement(true).setPermissionLevel("infopermission") // args.put("dev", new Argument("dev").setPrefixRequirement(true).setPermissionLevel("infopermission")
.addAliases("d", "developer", "extra", "shit", "to", "test")); // .addAliases("d", "developer", "extra", "shit", "to", "test"));
return args; return args;
} }

View file

@ -30,12 +30,12 @@ public class Info implements GuildCommandInterface, PrivateCommandInterface {
@Override @Override
public @Nullable HashMap<String, Argument> getArguments() { public @Nullable HashMap<String, Argument> getArguments() {
HashMap<String, Argument> args = new HashMap<String, Argument>(); HashMap<String, Argument> args = new HashMap<String, Argument>();
args.put("userdump", new Argument("userdump", (CommandBlob blob) -> { args.put("userdump", new Argument("userdump", (CommandBlob blob) -> {
blob.getChannel().sendMessage(!Users.dump(blob.getAuthorID()).isEmpty() ? Users.dump(blob.getAuthorID()) blob.getChannel().sendMessage(!Users.dump(blob.getAuthorID()).isEmpty() ? Users.dump(blob.getAuthorID())
: "Sorry, but this user does not exist in the database").queue(); : "Sorry, but this user does not exist in the database").queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true).addAliases("u")); }).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true).addAliases("u"));
return args; return args;
} }
@ -45,6 +45,9 @@ public class Info implements GuildCommandInterface, PrivateCommandInterface {
@Override @Override
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception { public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
blob.getChannel().sendMessage("This command is used to send data stored in the database to whoever is authorized to view it, to view your own data, use `"+getCommandName()+" -userdump`").queue(); blob.getChannel().sendMessage(
"This command is used to send data stored in the database to whoever is authorized to view it, to view your own data, use `"
+ getCommandName() + " -userdump`")
.queue();
} }
} }

View file

@ -5,14 +5,17 @@ import java.util.HashMap;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface; import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.global.Reactions;
import pkg.deepCurse.nopalmo.manager.Argument; import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob; import pkg.deepCurse.nopalmo.manager.CommandBlob;
import pkg.deepCurse.nopalmo.manager.StatusManager;
import pkg.deepCurse.nopalmo.utils.LogHelper;
public class Reload implements DualCommandInterface { public class Reload implements DualCommandInterface {
@Override @Override
public String[] getCommandCalls() { public String[] getCommandCalls() {
return new String[] {"reload"}; return new String[] { "reload", "r" };
} }
@Override @Override
@ -32,7 +35,43 @@ public class Reload implements DualCommandInterface {
@Override @Override
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception { public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
blob.getCommandManager().init(); StringBuilder sB = new StringBuilder();
LogHelper.log("Init reaction/emote list", getClass());
sB.append("Init reaction/emote list\n");
try {
Reactions.init();
LogHelper.log("Initialized reaction/emote list. . .", getClass());
sB.append("Initialized reaction/emote list. . .\n");
} catch (Exception e) {
LogHelper.log("Failed to initialize reaction/emote list. . .\n" + e + "\n", getClass());
sB.append("Failed to initialize reaction/emote list. . .\n" + e + "\n");
}
LogHelper.log("Init command list", getClass());
sB.append("Init command list\n");
try {
blob.getCommandManager().init();
LogHelper.log("Initialized command list. . .", getClass());
sB.append("Initialized command list. . .\n");
} catch (Exception e) {
LogHelper.log("Failed to initialize command list. . .\n" + e + "\n", getClass());
sB.append("Failed to initialize command list. . .\n" + e + "\n");
}
LogHelper.log("Init status list", getClass());
sB.append("Init status list\n");
try {
StatusManager.init();
LogHelper.log("Initialized status list. . .", getClass());
sB.append("Initialized status list. . .\n");
} catch (Exception e) {
LogHelper.log("Failed to initialize status list. . .\n" + e + "\n", getClass());
sB.append("Failed to initialize status list. . .\n" + e + "\n");
}
blob.getChannel().sendMessage(sB.toString()).queue();
} }
} }

View file

@ -0,0 +1,52 @@
package pkg.deepCurse.nopalmo.command.commands.testing;
import java.util.HashMap;
import org.jetbrains.annotations.Nullable;
import pkg.deepCurse.bontebok.core.BontebokInterpreter;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
public class BontebokInterpret implements DualCommandInterface {
@Override
public String[] getCommandCalls() {
return new String[] { "bontebok", "interpret", "int", "bo" };
}
@Override
public HelpPage getHelpPage() {
return HelpPage.TESTING;
}
@Override
public String getHelp() {
return "This command will interpret a string using the bontebok interpreter";
}
@Override
public @Nullable HashMap<String, Argument> getArguments() {
return null;
}
@Override
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
blob.getChannel().sendMessage("Interpreting. . .").queue();
String returnValue = BontebokInterpreter.InterpretString(argumentMap.get("null").getWildCardString(), null);
switch (returnValue.substring(0, 1)) {
// case "0":
// blob.getChannel().sendMessage("Operation completed with return value 0").queue();
// break;
case "1":
blob.getChannel().sendMessage("Operation failed with return value 1"
+ (returnValue.substring(1).isBlank() ? "" : ": " + returnValue.substring(1))).queue();
break;
}
}
}

View file

@ -41,54 +41,56 @@ public class Boot {
public static void main(String[] args) { public static void main(String[] args) {
PhoenixSettings settings = new PhoenixSettings().setAuthentication(args[3]).setCommandSplitRegex(", ").setCommandManager(new PhoenixCommandManager()); PhoenixSettings settings = new PhoenixSettings().setAuthentication(args[3]).setCommandSplitRegex(", ")
.setCommandManager(new PhoenixCommandManager());
// TODO using join and a while last time + 15000 < current time, then kill and
// proceed as a failure
// TODO using join and a while last time + 15000 < current time, then kill and proceed as a failure
settings.commandManager.addCommand("phoenix-update", (PhoenixRuntime runtime, List<String> commandArgs) -> { settings.commandManager.addCommand("phoenix-update", (PhoenixRuntime runtime, List<String> commandArgs) -> {
System.out.println("Received <phoenix-update>"); LogHelper.log("Received <phoenix-update>", Boot.class);
Socks.sendStringSock(settings.address, settings.commonPort, "phoenix-update-confirm"); Socks.sendStringSock(settings.address, settings.commonPort, "phoenix-update-confirm");
System.out.println("Sent <phoenix-update-confirm>"); LogHelper.log("Sent <phoenix-update-confirm>", Boot.class);
if (bot != null) { if (bot != null) {
bot.shutdown(); bot.shutdown();
} }
runtime.shutdown(9); runtime.shutdown(9);
}); });
// settings.actions.put("phoenix-update-confirm", (PhoenixRuntime runtime) -> { // settings.actions.put("phoenix-update-confirm", (PhoenixRuntime runtime) -> {
// System.out.println("Received <phoenix-update-confirm>"); // LogHelper.log("Received <phoenix-update-confirm>");
// }); // });
PhoenixRuntime runtime = new PhoenixRuntime(settings, new PhoenixInterface() { PhoenixRuntime runtime = new PhoenixRuntime(settings, new PhoenixInterface() {
@Override @Override
public void boot() { public void boot() {
LogHelper.boot("Booting: <" + pid + ">"); LogHelper.log("Booting: <" + pid + ">", Boot.class);
long preBootTime = System.currentTimeMillis(); long preBootTime = System.currentTimeMillis();
isProd = args[2].contentEquals("prod"); isProd = args[2].contentEquals("prod");
LogHelper.boot("Connecting to mariadb:nopalmo"); LogHelper.log("Connecting to mariadb:nopalmo", Boot.class);
try { try {
databaseTools = new DatabaseTools(args[1]); databaseTools = new DatabaseTools(args[1]);
LogHelper.boot("Connected. . ."); LogHelper.log("Connected. . .", Boot.class);
} catch (SQLException | ClassNotFoundException e1) { } catch (SQLException | ClassNotFoundException e1) {
e1.printStackTrace(); e1.printStackTrace();
LogHelper.boot("Failed to connect\nShutting down. . ."); LogHelper.log("Failed to connect\nShutting down. . .", Boot.class);
System.exit(4); System.exit(4);
} }
LogHelper.boot("Init reaction/emote list"); LogHelper.log("Init reaction/emote list", Boot.class);
Reactions.init(); Reactions.init();
LogHelper.boot("Initialized reaction/emote list. . ."); LogHelper.log("Initialized reaction/emote list. . .", Boot.class);
LogHelper.boot("Init commands list"); LogHelper.log("Init commands list", Boot.class);
commandManager.init(); commandManager.init();
LogHelper.boot("Initialized commands list. . ."); LogHelper.log("Initialized commands list. . .", Boot.class);
try { try {
// bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL) // bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL)
@ -133,23 +135,21 @@ public class Boot {
} catch (Exception e) { } catch (Exception e) {
LogHelper.crash(e); LogHelper.crash(e);
} }
LogHelper.boot("Using account: " + bot.getSelfUser().getName()); LogHelper.log("Using account: " + bot.getSelfUser().getName(), Boot.class);
bot.getPresence().setStatus(OnlineStatus.ONLINE); bot.getPresence().setStatus(OnlineStatus.ONLINE);
bot.getPresence().setActivity(Activity.listening("Infected Mushroom")); bot.getPresence().setActivity(Activity.listening("Infected Mushroom"));
LogHelper.boot("Init status list"); LogHelper.log("Init status list", Boot.class);
StatusManager.init(); StatusManager.init();
LogHelper.boot("Initialized status list. . ."); LogHelper.log("Initialized status list. . .", Boot.class);
long bootTime = System.currentTimeMillis() - preBootTime; long bootTime = System.currentTimeMillis() - preBootTime;
LogHelper.boot("Taken " + bootTime + "ms to boot"); LogHelper.log("Taken " + bootTime + "ms to boot", Boot.class);
LogHelper.boot("Starting loop"); LogHelper.log("Starting loop", Boot.class);
loop(); loop();
} }
@ -171,7 +171,7 @@ public class Boot {
if (now > lastTime + dynamicWait) { // dynamic wait loop if (now > lastTime + dynamicWait) { // dynamic wait loop
lastTime = now; lastTime = now;
try { try {
bot.getSelfUser(); bot.getSelfUser();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -206,10 +206,8 @@ public class Boot {
}); });
runtime.setLockedRunnable(() -> { runtime.setLockedRunnable(() -> {
System.out.println("System is locked\nSending <phoenix-update> instead. . . "); LogHelper.log("System is locked\nSending <phoenix-update> instead. . . ", Boot.class);
try { try {
Socket cSocket = new Socket("127.0.0.1", settings.commonPort); Socket cSocket = new Socket("127.0.0.1", settings.commonPort);
DataOutputStream dOut = new DataOutputStream(cSocket.getOutputStream()); DataOutputStream dOut = new DataOutputStream(cSocket.getOutputStream());
@ -220,11 +218,9 @@ public class Boot {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
// settings.getRuntime().shutdown(0); // settings.getRuntime().shutdown(0);
}); });
runtime.launch(); runtime.launch();

View file

@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
import pkg.deepCurse.nopalmo.core.Boot; import pkg.deepCurse.nopalmo.core.Boot;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global; import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.utils.LogHelper;
public class DatabaseTools { public class DatabaseTools {
@ -44,11 +45,14 @@ public class DatabaseTools {
public static void checkUpdateCounts(String action, int[] updateCounts) { public static void checkUpdateCounts(String action, int[] updateCounts) {
for (int i = 0; i < updateCounts.length; i++) { for (int i = 0; i < updateCounts.length; i++) {
if (updateCounts[i] >= 0) { if (updateCounts[i] >= 0) {
System.out.println("Successfully executed; updateCount=" + updateCounts[i] + "; On action " + action); LogHelper.log("Successfully executed; updateCount=" + updateCounts[i] + "; On action " + action,
DatabaseTools.class);
} else if (updateCounts[i] == Statement.SUCCESS_NO_INFO) { } else if (updateCounts[i] == Statement.SUCCESS_NO_INFO) {
System.out.println("Successfully executed; updateCount=Statement.SUCCESS_NO_INFO; On action " + action); LogHelper.log("Successfully executed; updateCount=Statement.SUCCESS_NO_INFO; On action " + action,
DatabaseTools.class);
} else if (updateCounts[i] == Statement.EXECUTE_FAILED) { } else if (updateCounts[i] == Statement.EXECUTE_FAILED) {
System.out.println("Failed to execute; updateCount=Statement.EXECUTE_FAILED; On action " + action); LogHelper.log("Failed to execute; updateCount=Statement.EXECUTE_FAILED; On action " + action,
DatabaseTools.class);
} }
} }
} }
@ -140,7 +144,7 @@ public class DatabaseTools {
} }
public static void addUser(long idLong) { public static void addUser(long idLong) {
} }
} }
@ -268,7 +272,7 @@ public class DatabaseTools {
} catch (SQLException e) { } catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode()); SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee"); // LogHelper.log("eeeeee");
return false; return false;
} finally { } finally {
try { try {
@ -306,7 +310,7 @@ public class DatabaseTools {
} catch (SQLException e) { } catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode()); SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee"); // LogHelper.log("eeeeee");
return null; return null;
} finally { } finally {
try { try {
@ -363,7 +367,7 @@ public class DatabaseTools {
} catch (SQLException e) { } catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode()); SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee"); // LogHelper.log("eeeeee");
throw new SQLException(e); throw new SQLException(e);
} finally { } finally {
try { try {
@ -400,7 +404,7 @@ public class DatabaseTools {
} catch (SQLException e) { } catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode()); SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee"); // LogHelper.log("eeeeee");
return false; return false;
} finally { } finally {
try { try {
@ -437,7 +441,7 @@ public class DatabaseTools {
} catch (SQLException e) { } catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode()); SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee"); // LogHelper.log("eeeeee");
return 45000; return 45000;
} finally { } finally {
try { try {
@ -474,7 +478,7 @@ public class DatabaseTools {
} catch (SQLException e) { } catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode()); SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee"); // LogHelper.log("eeeeee");
return 0; return 0;
} finally { } finally {
try { try {
@ -515,7 +519,7 @@ public class DatabaseTools {
// //
// } catch (SQLException e) { // } catch (SQLException e) {
// sqlTranslate(query, e.getErrorCode()); // sqlTranslate(query, e.getErrorCode());
// // System.out.println("eeeeee"); // // LogHelper.log("eeeeee");
// return null; // return null;
// } finally { // } finally {
// try { // try {

View file

@ -3,12 +3,12 @@ package pkg.deepCurse.nopalmo.database;
import java.util.HashMap; import java.util.HashMap;
public class RamDisk { public class RamDisk {
public static HashMap<String, Boolean> bools = new HashMap<String, Boolean>(); public static HashMap<String, Boolean> bools = new HashMap<String, Boolean>();
// public static // public static
public static void init() { public static void init() {
bools.put("shouldRun", true); bools.put("shouldRun", true);
} }
} }

View file

@ -28,7 +28,8 @@ public class Reactions {
} }
public static String getEmote(String id) { public static String getEmote(String id) {
return id.startsWith(":") ? internalReactionMap.get(id.substring(1)) : "<:" + id + ":" + reactionMap.get(id) + ">"; return id.startsWith(":") ? internalReactionMap.get(id.substring(1))
: "<:" + id + ":" + reactionMap.get(id) + ">";
} }
} }

View file

@ -10,14 +10,15 @@ import pkg.deepCurse.nopalmo.core.Boot;
import pkg.deepCurse.nopalmo.database.DatabaseTools; import pkg.deepCurse.nopalmo.database.DatabaseTools;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global; import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.global.Reactions; import pkg.deepCurse.nopalmo.global.Reactions;
import pkg.deepCurse.nopalmo.utils.LogHelper;
public class MessageReceivedListener extends ListenerAdapter { public class MessageReceivedListener extends ListenerAdapter {
@Override @Override
public void onReady(@Nonnull ReadyEvent event) { public void onReady(@Nonnull ReadyEvent event) {
System.out.println("MessageReceivedListener is now ready\n" + event.getGuildAvailableCount() + "/" LogHelper.log("MessageReceivedListener is now ready\n" + event.getGuildAvailableCount() + "/"
+ event.getGuildTotalCount() + " : " + event.getGuildUnavailableCount() + " <" + event.getGuildTotalCount() + " : " + event.getGuildUnavailableCount() + " <"
+ event.getResponseNumber() + ">"); + event.getResponseNumber() + ">", getClass());
} }
@Override @Override

View file

@ -5,21 +5,6 @@ import java.util.List;
public class Argument { public class Argument {
// README
//
// This tool is used simply for now, but it will be worth while if you get used
// to it
//
// this allows extra organization and ease of use throughout the creation of
// commands
// instead of one simple list where if args[1] == "all" do code
// this allows the same functionality, if not more with a little bit of learning
// you can go back to what it was before, but i honestly believe this system is
// worthwhile
// it just needs polish and reports on usage for optimization
//
//// TL;DR ITS A NEW FEATURE, GIVE IT TIME
private int requiredArgs = 0; private int requiredArgs = 0;
private String argName = null; private String argName = null;
private Argument[] subArgs = null; private Argument[] subArgs = null;

View file

@ -0,0 +1,59 @@
package pkg.deepCurse.nopalmo.manager;
import java.util.List;
import pkg.deepCurse.bontebok.core.BontebokFunctionInterface;
import pkg.deepCurse.bontebok.core.BontebokInterpreter;
import pkg.deepCurse.nopalmo.global.Reactions;
public class BontebokManager {
public static void init() {
BontebokInterpreter.functionMap.put("reply", new BontebokNopalmoFunctionInterface() {
@Override
public void run(List<String> args, CommandBlob blob) {
StringBuilder sB = new StringBuilder();
for (String i : args) {
sB.append(i);
}
blob.getMessage().reply(sB.toString()).queue();
}
@Override
public int getRequiredArgs() {
return -1;
}
});
BontebokInterpreter.functionMap.put("react", new BontebokNopalmoFunctionInterface() {
@Override
public void run(List<String> args, CommandBlob blob) {
try {
blob.getMessage().addReaction(Reactions.getReaction(args.get(0))).queue();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int getRequiredArgs() {
return 1;
}
});
}
public interface BontebokNopalmoFunctionInterface extends BontebokFunctionInterface {
@Override
public default void run(List<String> args) {
}
void run(List<String> args, CommandBlob blob);
}
}

View file

@ -29,6 +29,7 @@ public class CommandBlob {
private Member member = null; private Member member = null;
private Message message = null; private Message message = null;
private boolean isDeveloper = false;
private boolean isWebhookMessage = false; private boolean isWebhookMessage = false;
private boolean isFromGuild = false; private boolean isFromGuild = false;
@ -163,4 +164,12 @@ public class CommandBlob {
public void setFromGuild(boolean isFromGuild) { public void setFromGuild(boolean isFromGuild) {
this.isFromGuild = isFromGuild; this.isFromGuild = isFromGuild;
} }
public boolean isDeveloper() {
return isDeveloper;
}
public void setDeveloper(boolean isDeveloper) {
this.isDeveloper = isDeveloper;
}
} }

View file

@ -18,6 +18,7 @@ import pkg.deepCurse.nopalmo.command.CommandInterface;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface; import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface; import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.command.CommandInterface.PrivateCommandInterface; import pkg.deepCurse.nopalmo.command.CommandInterface.PrivateCommandInterface;
import pkg.deepCurse.nopalmo.command.commands.fun.Stupid;
import pkg.deepCurse.nopalmo.command.commands.general.Prefix; import pkg.deepCurse.nopalmo.command.commands.general.Prefix;
import pkg.deepCurse.nopalmo.command.commands.general.Test; import pkg.deepCurse.nopalmo.command.commands.general.Test;
import pkg.deepCurse.nopalmo.command.commands.info.Git; import pkg.deepCurse.nopalmo.command.commands.info.Git;
@ -25,10 +26,12 @@ import pkg.deepCurse.nopalmo.command.commands.info.Help;
import pkg.deepCurse.nopalmo.command.commands.info.Info; import pkg.deepCurse.nopalmo.command.commands.info.Info;
import pkg.deepCurse.nopalmo.command.commands.info.Ping; import pkg.deepCurse.nopalmo.command.commands.info.Ping;
import pkg.deepCurse.nopalmo.command.commands.info.Reload; import pkg.deepCurse.nopalmo.command.commands.info.Reload;
import pkg.deepCurse.nopalmo.command.commands.testing.BontebokInterpret;
import pkg.deepCurse.nopalmo.command.commands.testing.GuildCommand; import pkg.deepCurse.nopalmo.command.commands.testing.GuildCommand;
import pkg.deepCurse.nopalmo.command.commands.testing.PrivateCommand; import pkg.deepCurse.nopalmo.command.commands.testing.PrivateCommand;
import pkg.deepCurse.nopalmo.core.Boot; import pkg.deepCurse.nopalmo.core.Boot;
import pkg.deepCurse.nopalmo.database.DatabaseTools; import pkg.deepCurse.nopalmo.database.DatabaseTools;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Developers;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global; import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users; import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
import pkg.deepCurse.nopalmo.global.Tools; import pkg.deepCurse.nopalmo.global.Tools;
@ -56,13 +59,15 @@ public class CommandManager {
addCommand(new GuildCommand()); // guild addCommand(new GuildCommand()); // guild
addCommand(new PrivateCommand()); // private addCommand(new PrivateCommand()); // private
addCommand(new Reload()); // dual addCommand(new Reload()); // dual
addCommand(new BontebokInterpret()); // dual
addCommand(new Stupid()); // guild
} }
private void addCommand(CommandInterface c) { private void addCommand(CommandInterface c) {
for (String i : c.getCommandCalls()) { for (String i : c.getCommandCalls()) {
// if (!commandMap.containsKey(i)) { // if (!commandMap.containsKey(i)) {
commandMap.put(i, c); commandMap.put(i, c);
// } // }
} }
} }
@ -96,9 +101,9 @@ public class CommandManager {
} else { } else {
return; return;
} }
Users.addUser(event.getAuthor().getIdLong()); Users.addUser(event.getAuthor().getIdLong());
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+"); final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
final String commandCall = split[0].toLowerCase(); final String commandCall = split[0].toLowerCase();
@ -111,7 +116,7 @@ public class CommandManager {
try { try {
CommandBlob commandBlob = new CommandBlob(event, this); CommandBlob commandBlob = new CommandBlob(event, this);
CommandInterface command = commandMap.get(commandCall); CommandInterface command = commandMap.get(commandCall);
HashMap<String, Argument> argumentList = new HashMap<String, Argument>(); HashMap<String, Argument> argumentMap = new HashMap<String, Argument>();
boolean printTime = false; boolean printTime = false;
byte argSkipCount = 0; byte argSkipCount = 0;
@ -148,6 +153,10 @@ public class CommandManager {
break; break;
} }
} }
commandBlob.setDeveloper(
Developers.getDeveloperBoolean(commandBlob.getAuthorID(), "developercommandpermission"));
// split up so global commands are actually global, and will not be affected by // split up so global commands are actually global, and will not be affected by
// neighboring local args // neighboring local args
for (int i = 0; i < newArgs.size(); i++) { for (int i = 0; i < newArgs.size(); i++) {
@ -168,7 +177,7 @@ public class CommandManager {
if (command.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) { if (command.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
remainsValid = false; remainsValid = false;
} }
argumentList.put(pre, command.getArguments().get(pre)); argumentMap.put(pre, command.getArguments().get(pre));
if (command.getArguments().get(pre).isAutoStartRunnable() if (command.getArguments().get(pre).isAutoStartRunnable()
&& command.getArguments().get(pre).getRunnableArg() != null) { && command.getArguments().get(pre).getRunnableArg() != null) {
command.getArguments().get(pre).getRunnableArg().run(commandBlob); command.getArguments().get(pre).getRunnableArg().run(commandBlob);
@ -191,7 +200,7 @@ public class CommandManager {
if (command.getArguments().get(x).isSkipOriginalTaskOnRunnable()) { if (command.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
remainsValid = false; remainsValid = false;
} }
argumentList.put(x, command.getArguments().get(x)); argumentMap.put(x, command.getArguments().get(x));
offset++; offset++;
if (command.getArguments().get(x).isAutoStartRunnable() if (command.getArguments().get(x).isAutoStartRunnable()
&& command.getArguments().get(x).getRunnableArg() != null) { && command.getArguments().get(x).getRunnableArg() != null) {
@ -211,7 +220,7 @@ public class CommandManager {
remainsValid = false; remainsValid = false;
} }
if (positionalArgs.get(i - offset).getIsWildcard()) { if (positionalArgs.get(i - offset).getIsWildcard()) {
argumentList.put(positionalArgs.get(i - offset).getArgName(), argumentMap.put(positionalArgs.get(i - offset).getArgName(),
positionalArgs.get(i - offset).setWildCardString(x)); positionalArgs.get(i - offset).setWildCardString(x));
} else { } else {
Tools.wrongUsage(event.getChannel(), command); Tools.wrongUsage(event.getChannel(), command);
@ -231,8 +240,8 @@ public class CommandManager {
} }
} else { } else {
Tools.wrongUsage(event.getChannel(), command); // Tools.wrongUsage(event.getChannel(), command);
remainsValid = false; // remainsValid = false;
} }
} }
@ -246,6 +255,14 @@ public class CommandManager {
remainsValid = false; remainsValid = false;
} }
if (Help.deniedPages.contains(command.getHelpPage())) {
if (!commandBlob.isDeveloper()) {
commandBlob.getChannel()
.sendMessage("Sorry, but you are not allowed to run this command. . ").queue();
remainsValid = false;
}
}
commandBlob.setCommandManager(this); commandBlob.setCommandManager(this);
if (event.isFromGuild()) { if (event.isFromGuild()) {
@ -258,15 +275,26 @@ public class CommandManager {
} }
if (remainsValid) { if (remainsValid) {
if (command instanceof DualCommandInterface) {
((DualCommandInterface) command).runDualCommand(commandBlob, argumentList); if (command.getArguments() == null) {
} else if (command instanceof GuildCommandInterface && event.isFromGuild()) { StringBuilder sB = new StringBuilder();
((GuildCommandInterface) command).runGuildCommand(commandBlob, argumentList); for (String i : newArgs) {
} else if (command instanceof PrivateCommandInterface && !event.isFromGuild()) { sB.append(i + " ");
((PrivateCommandInterface) command).runPrivateCommand(commandBlob, argumentList); }
argumentMap.clear();
argumentMap.put("null", new Argument("null").setWildCardString(sB.toString().trim()));
} }
if (command instanceof GuildCommandInterface && !event.isFromGuild() && !(command instanceof PrivateCommandInterface)) { if (command instanceof DualCommandInterface) {
((DualCommandInterface) command).runDualCommand(commandBlob, argumentMap);
} else if (command instanceof GuildCommandInterface && event.isFromGuild()) {
((GuildCommandInterface) command).runGuildCommand(commandBlob, argumentMap);
} else if (command instanceof PrivateCommandInterface && !event.isFromGuild()) {
((PrivateCommandInterface) command).runPrivateCommand(commandBlob, argumentMap);
}
if (command instanceof GuildCommandInterface && !event.isFromGuild()
&& !(command instanceof PrivateCommandInterface)) {
event.getChannel() event.getChannel()
.sendMessage( .sendMessage(
"Sorry, but you need to be in a " "Sorry, but you need to be in a "
@ -274,7 +302,8 @@ public class CommandManager {
commandBlob.getAuthorID()) ? "guild" : "server") commandBlob.getAuthorID()) ? "guild" : "server")
+ " to use this command. . .") + " to use this command. . .")
.queue(); .queue();
} else if (command instanceof PrivateCommandInterface && event.isFromGuild() && !(command instanceof GuildCommandInterface)) { } else if (command instanceof PrivateCommandInterface && event.isFromGuild()
&& !(command instanceof GuildCommandInterface)) {
event.getChannel().sendMessage("Sorry, but this command will only run in dms. . .").queue(); event.getChannel().sendMessage("Sorry, but this command will only run in dms. . .").queue();
} }
} }

View file

@ -5,7 +5,7 @@ import java.io.IOException;
import java.net.Socket; import java.net.Socket;
public class Socks { public class Socks {
public static void sendStringSock(String address, int port, String input) { public static void sendStringSock(String address, int port, String input) {
try { try {
Socket cSocket = new Socket(address, port); Socket cSocket = new Socket(address, port);
@ -18,5 +18,5 @@ public class Socks {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View file

@ -1,7 +1,5 @@
package pkg.deepCurse.nopalmo.utils; package pkg.deepCurse.nopalmo.utils;
import pkg.deepCurse.nopalmo.core.Boot;
/** /**
* this class exists for the sole reason of im lazy, as far as i know, this is * this class exists for the sole reason of im lazy, as far as i know, this is
* really bad practice and i will replace it at some point, or at least upgrade * really bad practice and i will replace it at some point, or at least upgrade
@ -16,13 +14,13 @@ public class LogHelper {
public static boolean bootEnabled = true; public static boolean bootEnabled = true;
public static boolean guildCommandManagerEnabled = true; public static boolean guildCommandManagerEnabled = true;
public static void boot(String text) { public static void log(String text, Class<?> clazz) {
boot(text, 0); log(text, 0, clazz);
} }
public static void boot(String text, int level) { public static void log(String text, int level, Class<?> clazz) {
if (bootEnabled && level <= loggerLevel) { if (bootEnabled && level <= loggerLevel) {
System.out.println(Boot.class + ": " + text); System.out.println(clazz + ": " + text);
} }
} }
@ -30,14 +28,4 @@ public class LogHelper {
e.printStackTrace(); e.printStackTrace();
System.exit(8); System.exit(8);
} }
public static void guildCommandManager(String text) {
guildCommandManager(text);
}
public static void guildCommandManager(String text, int level) {
if (guildCommandManagerEnabled && level <= loggerLevel) {
System.out.println(Boot.class + ": " + text);
}
}
} }

View file

@ -25,8 +25,6 @@ public class UptimePing {
} }
// System.out.println("fix me"); // not sure why this is here
if (socketAddress.getAddress() == null) { if (socketAddress.getAddress() == null) {
return -1; return -1;
} else { } else {