mass code dump
Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
parent
f71abeb499
commit
573443e4b4
17 changed files with 438 additions and 289 deletions
62
src/pkg/deepCurse/nopalmo/command/Command.java
Normal file
62
src/pkg/deepCurse/nopalmo/command/Command.java
Normal file
|
@ -0,0 +1,62 @@
|
|||
package pkg.deepCurse.nopalmo.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
|
||||
|
||||
public abstract class Command {
|
||||
|
||||
public abstract void runCommand(GuildCommandBlob blob, GuildCommandManager commandManager,
|
||||
HashMap<String, Argument> argumentList) throws Exception;
|
||||
|
||||
public abstract String[] getCommandCalls();
|
||||
|
||||
public String getCommandName() {
|
||||
return getCommandCalls()[0];
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPremium() { // im probably never gonna use this, but ill leave it in for those who want to
|
||||
// see how i would implement it
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract HelpPage getHelpPage();
|
||||
|
||||
public enum HelpPage {
|
||||
General, DEV, EGG, Moderation, Fun, Info
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public HashMap<String, Argument> getArguments() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,60 +1,15 @@
|
|||
package pkg.deepCurse.nopalmo.command;
|
||||
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
|
||||
|
||||
public abstract class GuildCommand {
|
||||
|
||||
public abstract void run(GuildCommandBlob blob, GuildCommandManager commandManager) throws Exception;
|
||||
|
||||
public abstract String[] getCommandCalls();
|
||||
|
||||
public String getCommandName() {
|
||||
return getCommandCalls()[0];
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract class GuildCommand extends Command {
|
||||
|
||||
public Permission[] getRequiredPermissions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPremium() { // im probably never gonna use this, but ill leave it in for those who want to
|
||||
// see how i would implement it
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract HelpPage getHelpPage();
|
||||
|
||||
public enum HelpPage {
|
||||
General, DEV, EGG, Moderation, Fun, Info
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Permission getRequiredPermission() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package pkg.deepCurse.nopalmo.command.guildCommand.info;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||
import pkg.deepCurse.nopalmo.command.GuildCommand;
|
||||
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.GuildCommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
|
||||
|
||||
|
@ -20,45 +23,32 @@ public class Help extends GuildCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void run(GuildCommandBlob blob, GuildCommandManager commandManager) throws Exception {
|
||||
// TextChannel channel = event.getChannel();
|
||||
// Member user = event.getMember();
|
||||
// if (Tools.devIdCheck(null, user.getId(), channel, null)) {
|
||||
if (blob.getArgs().size() > 1) {
|
||||
Tools.wrongUsage(blob.getGuildMessageEvent().getChannel(), this);
|
||||
return;
|
||||
}
|
||||
if (blob.getArgs().isEmpty()) {
|
||||
public void runCommand(GuildCommandBlob blob, GuildCommandManager commandManager,
|
||||
HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
if (argumentMap.isEmpty()) {
|
||||
EmbedBuilder embed = new EmbedBuilder().setTitle("Commands:");
|
||||
|
||||
for (HelpPage i : HelpPage.values()) {
|
||||
if (i != HelpPage.DEV) {
|
||||
StringBuilder pageData = new StringBuilder();
|
||||
HashMap<HelpPage, String> commandHash = new HashMap<HelpPage, String>();
|
||||
|
||||
for (GuildCommand command : manager.getGuildCommands()) {
|
||||
if (!command.isHidden() & command.getHelpPage() != HelpPage.EGG) {
|
||||
if (command.getHelpPage() == i) {
|
||||
for (GuildCommand command : manager.getGuildCommands()) {
|
||||
|
||||
if (!pageData.toString().contains(command.getCommandName())) {
|
||||
pageData.append("`" + command.getCommandName() + "`\n");
|
||||
}
|
||||
commandHash.put(command.getHelpPage(),
|
||||
commandHash.get(command.getHelpPage()) + command.getCommandName());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pageData.toString().isBlank()) {
|
||||
embed.addField(i.name() + ": ", pageData.toString(), true);
|
||||
}
|
||||
// pageData.delete(0, pageData.length());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sB = new StringBuilder();
|
||||
|
||||
sB.append("`manual`\n");
|
||||
sB.append("`ping`\n");
|
||||
sB.append("`support`\n");
|
||||
// sB.append("`"+Global.Prefix+"\n");
|
||||
GuildCommand ping = commandManager.getCommand("ping");
|
||||
if (ping != null) {
|
||||
sB.append("`"+ping.getUsage()+"`\n");
|
||||
}
|
||||
|
||||
GuildCommand help = commandManager.getCommand("help");
|
||||
if (help != null) {
|
||||
sB.append("`"+help.getUsage()+"`\n");
|
||||
}
|
||||
|
||||
embed.addField("Information:", "Commands to take note of:\n" + sB, false);
|
||||
|
||||
|
@ -74,7 +64,7 @@ public class Help extends GuildCommand {
|
|||
embed.setTimestamp(Instant.now());
|
||||
embed.setColor(0);
|
||||
if (embed.isValidLength()) {
|
||||
blob.getGuildMessageEvent().getChannel().sendMessage(embed.build()).queue();
|
||||
blob.getGuildMessageEvent().getChannel().sendMessageEmbeds(embed.build()).queue();
|
||||
} else {
|
||||
blob.getGuildMessageEvent().getChannel()
|
||||
.sendMessage(
|
||||
|
@ -88,6 +78,16 @@ public class Help extends GuildCommand {
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// ##########################################################################################################################
|
||||
|
||||
// ##########################################################################################################################
|
||||
|
||||
// ##########################################################################################################################
|
||||
|
||||
// ##########################################################################################################################
|
||||
|
||||
// ##########################################################################################################################
|
||||
try {
|
||||
GuildCommand command = manager.getCommand(String.join("", blob.getArgs()));
|
||||
|
||||
|
@ -132,15 +132,17 @@ public class Help extends GuildCommand {
|
|||
}
|
||||
sB.append("Premium: " + command.isPremium() + "\n");
|
||||
eB.addField("Misc", sB.toString(), false);
|
||||
blob.getGuildMessageEvent().getChannel().sendMessage(eB.build()).queue();
|
||||
blob.getGuildMessageEvent().getChannel().sendMessageEmbeds(eB.build()).queue();
|
||||
} else {
|
||||
throw new NullPointerException("Invalid input");
|
||||
}
|
||||
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
blob.getGuildMessageEvent().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();
|
||||
blob.getGuildMessageEvent().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;
|
||||
|
||||
}
|
||||
|
@ -176,9 +178,4 @@ public class Help extends GuildCommand {
|
|||
return Global.prefix + getCommandCalls()[0] + " [Command name]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,70 @@
|
|||
package pkg.deepCurse.nopalmo.command.guildCommand.info;
|
||||
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import pkg.deepCurse.nopalmo.command.GuildCommand;
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.global.Tools;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
|
||||
|
||||
public class Ping extends GuildCommand {
|
||||
|
||||
@Override
|
||||
public void run(GuildCommandBlob blob, GuildCommandManager commandManager)
|
||||
throws Exception {
|
||||
|
||||
public void runCommand(GuildCommandBlob blob, GuildCommandManager commandManager,
|
||||
HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
GuildMessageReceivedEvent event = blob.getGuildMessageEvent();
|
||||
|
||||
TextChannel channel = event.getChannel();
|
||||
if (argumentMap.isEmpty()) {
|
||||
event.getChannel().sendMessage("Pong!\n" + event.getJDA().getGatewayPing() + "ms\n").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
channel.sendMessage("You are: " + blob.getUserID()).queue();
|
||||
|
||||
if (blob.getArgs().size() == 0) {
|
||||
// new Main();
|
||||
channel.sendMessage("Pong!\n" + event.getJDA().getGatewayPing() + "ms\n"
|
||||
// + "Sorry if the ping is too high, im currently hosting on an under powered
|
||||
// laptop out in the countryside...\n"
|
||||
// + "This will be fixed in at most 2 days..."
|
||||
).queue();
|
||||
// long pang = Main.bot.getGatewayPing();
|
||||
if (argumentMap.get("all") != null) {
|
||||
|
||||
} else if (blob.getArgs().get(0).contentEquals("all")) {
|
||||
event.getChannel().sendMessage("Gathering data. . .").queue(msg -> {
|
||||
long timeToProcess = System.currentTimeMillis();
|
||||
|
||||
try { // TODO rewrite this block, all tries are not good practice
|
||||
|
||||
channel.sendMessage("Gathering data...").queue(msg -> {
|
||||
try {
|
||||
long timeToProcess = System.currentTimeMillis();
|
||||
|
||||
String out = "Pong!\n" + "Google: " + services.UptimePing.sendPing("www.google.com") + "ms\n"
|
||||
+ "JDA Gateway: " + event.getJDA().getGatewayPing() + "ms\n" + "www.discord.com: "
|
||||
+ services.UptimePing.sendPing("www.discord.com") + "ms";
|
||||
|
||||
|
||||
msg.editMessage(out + "\nTime to process: " + (timeToProcess - System.currentTimeMillis()) + "ms").queue();
|
||||
msg.editMessage(out + "\nTime to process: " + (System.currentTimeMillis() - timeToProcess) + "ms")
|
||||
.queue();
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
} else
|
||||
Tools.wrongUsage(channel, this);
|
||||
}
|
||||
|
||||
// if (argumentArray == null || argumentArray.isEmpty()) {
|
||||
//
|
||||
// return;
|
||||
// } else {
|
||||
//
|
||||
// for (Argument i : argumentArray) {
|
||||
// if (i.getArgName().contentEquals("all")) {
|
||||
//
|
||||
// } else {
|
||||
// Tools.wrongUsage(event.getChannel(), this);
|
||||
// }
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] {"ping"};
|
||||
return new String[] { "ping" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return Global.prefix+"ping [" + Argument.argumentPrefix + "all]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,4 +72,13 @@ public class Ping extends GuildCommand {
|
|||
return HelpPage.Info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Argument> getArguments() {
|
||||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
|
||||
args.put("all", new Argument("all").setPrefixRequirement(true));
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class Boot {
|
|||
|
||||
long bootTime = System.currentTimeMillis() - preBootTime;
|
||||
|
||||
System.out.println("Taken "+bootTime+"ms to boot");
|
||||
Log.boot("Taken "+bootTime+"ms to boot");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class DatabaseTools {
|
|||
Global.updatePrefix();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Connection createConnection(String password) throws SQLException {
|
||||
|
||||
String dbName = Boot.isProd ? "nopalmo" : "chaos";
|
||||
|
@ -40,34 +41,11 @@ public class DatabaseTools {
|
|||
try {
|
||||
return DriverManager.getConnection(url, username, password);
|
||||
} catch (SQLException e) {
|
||||
sqlTranslate("Generate connection", e);
|
||||
SQLCode.sqlTranslate("Generate connection", e);
|
||||
throw new SQLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void sqlTranslate(String action, int errorCode) {
|
||||
switch (errorCode) {
|
||||
case 1062:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; ER_DUP_ENTRY; On action " + action);
|
||||
break;
|
||||
case 1054:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; ER_BAD_FIELD_ERROR; On action " + action);
|
||||
break;
|
||||
default:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; Unknown code; On action " + action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void sqlTranslate(String action, SQLException e) {
|
||||
sqlTranslate(action, e.getErrorCode());
|
||||
}
|
||||
|
||||
private static void sqlTranslate(PreparedStatement pstmt, SQLException e) {
|
||||
sqlTranslate(pstmt.toString(), e.getErrorCode());
|
||||
}
|
||||
|
||||
private static void checkUpdateCounts(PreparedStatement pstmt, int[] updateCounts) {
|
||||
checkUpdateCounts(pstmt.toString(), updateCounts);
|
||||
}
|
||||
|
@ -87,8 +65,9 @@ public class DatabaseTools {
|
|||
|
||||
public class Tools {
|
||||
|
||||
// these sub classes will represent tables and the methods therein will be for actions within said table
|
||||
|
||||
// these sub classes will represent tables and the methods therein will be for
|
||||
// actions within said table
|
||||
|
||||
public class Guild {
|
||||
|
||||
public class Prefix {
|
||||
|
@ -110,7 +89,7 @@ public class DatabaseTools {
|
|||
return createPrefix(guildID, Global.prefix);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
sqlTranslate(query, e.getErrorCode());
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
return null;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
|
@ -143,7 +122,7 @@ public class DatabaseTools {
|
|||
// connection.commit();
|
||||
return prefix;
|
||||
} catch (SQLException e) {
|
||||
sqlTranslate(pstmt, e);
|
||||
SQLCode.sqlTranslate(pstmt, e);
|
||||
for (int i : new int[] { 1062 }) {
|
||||
if (i == e.getErrorCode()) {
|
||||
return setPrefix(connection, guildID, prefix);
|
||||
|
@ -181,7 +160,7 @@ public class DatabaseTools {
|
|||
conn.commit();
|
||||
return prefix;
|
||||
} catch (SQLException e) {
|
||||
sqlTranslate(pstmt, e);
|
||||
SQLCode.sqlTranslate(pstmt, e);
|
||||
try {
|
||||
conn.rollback();
|
||||
} catch (Exception e2) {
|
||||
|
@ -212,7 +191,7 @@ public class DatabaseTools {
|
|||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
sqlTranslate(query, e.getErrorCode());
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
return false;
|
||||
} finally {
|
||||
|
@ -236,7 +215,7 @@ public class DatabaseTools {
|
|||
}
|
||||
|
||||
public class Global {
|
||||
|
||||
|
||||
public static String prefix = null;
|
||||
|
||||
public static void updatePrefix() throws SQLException {
|
||||
|
@ -257,7 +236,7 @@ public class DatabaseTools {
|
|||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
sqlTranslate(query, e.getErrorCode());
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
throw new SQLException(e);
|
||||
} finally {
|
||||
|
|
33
src/pkg/deepCurse/nopalmo/database/SQLCode.java
Normal file
33
src/pkg/deepCurse/nopalmo/database/SQLCode.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package pkg.deepCurse.nopalmo.database;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLCode {
|
||||
|
||||
|
||||
|
||||
public static String getMessage(String action, int errorCode) {
|
||||
switch (errorCode) {
|
||||
case 1062:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; ER_DUP_ENTRY; On action " + action);
|
||||
return "";
|
||||
case 1054:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; ER_BAD_FIELD_ERROR; On action " + action);
|
||||
return "";
|
||||
default:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; Unknown code; On action " + action);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void sqlTranslate(String action, SQLException e) {
|
||||
SQLCode.getMessage(action, e.getErrorCode());
|
||||
}
|
||||
|
||||
public static void sqlTranslate(PreparedStatement pstmt, SQLException e) {
|
||||
SQLCode.getMessage(pstmt.toString(), e.getErrorCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ import pkg.deepCurse.nopalmo.command.GuildCommand;
|
|||
public class Tools {
|
||||
|
||||
public static void wrongUsage(TextChannel tc, GuildCommand c) {
|
||||
tc.sendMessage("Wrong Command Usage!\n" + c.getCommandName()).queue();
|
||||
tc.sendMessage("Wrong Command Usage!\n" + c.getUsage()).queue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.global.Reactions;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
|
||||
|
||||
public class GuildMessageReceivedListener extends ListenerAdapter {
|
||||
|
||||
|
||||
@Override
|
||||
public void onReady(@Nonnull ReadyEvent event) {
|
||||
System.out.println("GuildMessageReceivedListener is now ready\n" + event.getGuildAvailableCount() + "/"
|
||||
|
@ -25,38 +23,44 @@ public class GuildMessageReceivedListener extends ListenerAdapter {
|
|||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
||||
Message message = event.getMessage();
|
||||
String messageRaw = message.getContentRaw();
|
||||
|
||||
if (messageRaw.contentEquals(Global.prefix + Global.prefix)
|
||||
&& DatabaseTools.Tools.Developers.canPowerOffBot(event.getAuthor().getIdLong())) {
|
||||
|
||||
// message.addReaction(Reactions.getReaction("galaxyThumb")).complete(); TODO re enable
|
||||
|
||||
message.delete().complete();
|
||||
|
||||
// pause thread as last resort
|
||||
|
||||
event.getJDA().shutdown();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
String[] prefixArray = new String[] { DatabaseTools.Tools.Guild.Prefix.getPrefix(event.getGuild().getIdLong()),
|
||||
"<@!" + event.getJDA().getSelfUser().getIdLong() + ">" };
|
||||
|
||||
boolean shouldReturn = true;
|
||||
for (String i : prefixArray) {
|
||||
for (String i : prefixArray) { // switch to [] to skip for loop?
|
||||
|
||||
if (messageRaw.startsWith(i)) {
|
||||
|
||||
shouldReturn = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (messageRaw.contentEquals(Global.prefix + Global.prefix)
|
||||
&& DatabaseTools.Tools.Developers.canPowerOffBot(event.getAuthor().getIdLong())) {
|
||||
message.addReaction(Reactions.getReaction("galaxyThumb")).complete();
|
||||
|
||||
System.out.println("Shutting down; id " + event.getAuthor().getIdLong() + " used");
|
||||
|
||||
// pause thread as last resort
|
||||
|
||||
event.getJDA().shutdown();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// TODO add pre manager commands
|
||||
|
||||
|
||||
if (shouldReturn) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!event.getAuthor().isBot()) {
|
||||
|
||||
Boot.guildCommandManager.startCommand(event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
122
src/pkg/deepCurse/nopalmo/manager/Argument.java
Normal file
122
src/pkg/deepCurse/nopalmo/manager/Argument.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
package pkg.deepCurse.nopalmo.manager;
|
||||
|
||||
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 String argName = null;
|
||||
private Argument[] subArgs = null;
|
||||
private boolean requiresPrefix = false;
|
||||
public static final String argumentPrefix = "-"; // This exists for the sole reason of customization and will
|
||||
// generally not change, ever, its recommended you keep it to
|
||||
// something other than empty to help ensure that what the user
|
||||
// entered is an arg and not something else
|
||||
|
||||
/**
|
||||
* @implNote This is an experimental feature that has potential, but i have no
|
||||
* use for it currently, imagine it akin to redstone, mojang had no
|
||||
* idea people would build computers or 9x9 piston doors out of it
|
||||
* @param requiredArgs
|
||||
* @param argName
|
||||
* @param subArgs
|
||||
*/
|
||||
public Argument(int requiredArgs, String argName, Argument[] subArgs) {
|
||||
this.requiredArgs = requiredArgs;
|
||||
this.argName = argName;
|
||||
this.subArgs = subArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @implNote This is an experimental feature that has potential, but i have no
|
||||
* use for it currently, imagine it akin to redstone, mojang had no
|
||||
* idea people would build computers or 9x9 piston doors out of it
|
||||
* @param requiredArgs
|
||||
* @param argName
|
||||
* @param subArgs
|
||||
*/
|
||||
public Argument(int requiredArgs, String argName, Argument[] subArgs, RunnableArg runnableArg) {
|
||||
this.requiredArgs = requiredArgs;
|
||||
this.argName = argName;
|
||||
this.subArgs = subArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @implNote This is an experimental feature that has potential, but i have no
|
||||
* use for it currently, imagine it akin to redstone, mojang had no
|
||||
* idea people would build computers or 9x9 piston doors out of it
|
||||
* @param requiredArgs
|
||||
* @param argName
|
||||
* @param subArgs
|
||||
*/
|
||||
public Argument(String argName) {
|
||||
this.argName = argName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @implNote This is an experimental feature that has potential, but i have no
|
||||
* use for it currently, imagine it akin to redstone, mojang had no
|
||||
* idea people would build computers or 9x9 piston doors out of it
|
||||
* @param requiredArgs
|
||||
* @param argName
|
||||
* @param subArgs
|
||||
*/
|
||||
public Argument(String argName, RunnableArg runnableArg) {
|
||||
this.argName = argName;
|
||||
}
|
||||
|
||||
public int getRequiredArgs() {
|
||||
return requiredArgs;
|
||||
}
|
||||
|
||||
// public Argument setRequiredArgs(int requiredArgs) {
|
||||
// this.requiredArgs = requiredArgs;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public String getArgName() {
|
||||
return argName;
|
||||
}
|
||||
|
||||
// public Argument setArgName(String argName) {
|
||||
// this.argName = argName;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public Argument[] getSubArgs() {
|
||||
return subArgs;
|
||||
}
|
||||
|
||||
// public Argument setSubArgs(Argument[] subArgs) {
|
||||
// this.subArgs = subArgs;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public Argument setPrefixRequirement(Boolean bool) {
|
||||
this.requiresPrefix = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getPrefixRequirement() {
|
||||
return this.requiresPrefix;
|
||||
}
|
||||
|
||||
|
||||
public interface RunnableArg {
|
||||
|
||||
public void run();
|
||||
|
||||
}
|
||||
|
||||
}
|
32
src/pkg/deepCurse/nopalmo/manager/ArgumentList.java
Normal file
32
src/pkg/deepCurse/nopalmo/manager/ArgumentList.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package pkg.deepCurse.nopalmo.manager;
|
||||
|
||||
public class ArgumentList { // ON HOLD FOR NOW, IT MAY BE USELESS
|
||||
//
|
||||
// private HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
// private Command command = null;
|
||||
//
|
||||
// public ArgumentList(Command command) {
|
||||
// this.command = command;
|
||||
// }
|
||||
//
|
||||
// public void addArgument(String name) {
|
||||
//
|
||||
//
|
||||
//
|
||||
// args.put(null, null);
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// public ArrayList<Argument> getArguments() {
|
||||
// return (ArrayList<Argument>) args.values();
|
||||
// }
|
||||
//
|
||||
// public Argument getArgumentFromName(String argumentName) {
|
||||
// return args.get(argumentName);
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// public List<String> getArgumentNames() {
|
||||
// return (@Nullable List<String>) args.keySet();
|
||||
// }
|
||||
}
|
|
@ -33,24 +33,28 @@ public abstract class CommandBlob {
|
|||
return this.modifiedRaw;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ArrayList<String> getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public void setUser(long userID) {
|
||||
public CommandBlob setUser(long userID) {
|
||||
this.userID = userID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getUserID() {
|
||||
return this.userID;
|
||||
}
|
||||
|
||||
public void setJDA(JDA bot) {
|
||||
public CommandBlob setJDA(JDA bot) {
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public void setArgs(ArrayList<String> newArguments) {
|
||||
public CommandBlob setArgs(ArrayList<String> newArguments) {
|
||||
this.args = newArguments;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@ package pkg.deepCurse.nopalmo.manager;
|
|||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
|
||||
public class GuildCommandBlob extends CommandBlob {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
||||
String[][] argumentArray = null;
|
||||
|
||||
public GuildCommandBlob(GuildMessageReceivedEvent event) {
|
||||
super(event);
|
||||
setUser(event.getMessage().getAuthor().getIdLong());
|
||||
|
|
|
@ -2,7 +2,6 @@ package pkg.deepCurse.nopalmo.manager;
|
|||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -14,9 +13,11 @@ import java.util.regex.Pattern;
|
|||
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import pkg.deepCurse.nopalmo.command.GuildCommand;
|
||||
import pkg.deepCurse.nopalmo.command.guildCommand.info.Help;
|
||||
import pkg.deepCurse.nopalmo.command.guildCommand.info.Ping;
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools;
|
||||
import pkg.deepCurse.nopalmo.global.Tools;
|
||||
|
||||
public class GuildCommandManager {
|
||||
|
||||
|
@ -29,6 +30,7 @@ public class GuildCommandManager {
|
|||
}
|
||||
|
||||
public void init() {
|
||||
// addCommand(new Help(this)); FIXME
|
||||
addCommand(new Ping());
|
||||
}
|
||||
|
||||
|
@ -67,14 +69,16 @@ public class GuildCommandManager {
|
|||
long commandStartTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
ArrayList<String> newArguments = new ArrayList<String>();
|
||||
// ArrayList<String> newArguments = new ArrayList<String>();
|
||||
// ArrayList<String> commandFlags = new ArrayList<String>();
|
||||
// ArrayList<String[]> extractedFlags = new ArrayList<String[]>(); // not needed currently, remnant idea of bash-ish
|
||||
|
||||
GuildCommandBlob commandBlob = new GuildCommandBlob(guildMessage);
|
||||
GuildCommand guildCommand = guildCommandMap.get(command);
|
||||
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
||||
|
||||
boolean printTime = false;
|
||||
byte argSkipCount = 0;
|
||||
boolean remainsValid = true;
|
||||
|
||||
for (String x : args) {
|
||||
switch (x) {
|
||||
|
@ -88,52 +92,83 @@ public class GuildCommandManager {
|
|||
case "\\del":
|
||||
guildMessage.getMessage().delete().queue();
|
||||
break;
|
||||
default:
|
||||
if (argSkipCount<=0) {
|
||||
newArguments.add(x);
|
||||
default: // in the rewrite process
|
||||
if (argSkipCount <= 0) {
|
||||
|
||||
if (guildCommand.getArguments() != null) {
|
||||
if (x.startsWith(Argument.argumentPrefix)) {
|
||||
|
||||
String pre = x.substring(Argument.argumentPrefix.length());
|
||||
|
||||
argumentList.put(pre, guildCommand.getArguments().get(pre));
|
||||
|
||||
} else {
|
||||
if (guildCommand.getArguments().get(x).getPrefixRequirement()) {
|
||||
Tools.wrongUsage(guildMessage.getChannel(), guildCommand);
|
||||
remainsValid = false;
|
||||
} else {
|
||||
argumentList.put(x, guildCommand.getArguments().get(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// if (guildCommand.getArguments() != null) {
|
||||
//
|
||||
// String newArg = x;
|
||||
//
|
||||
// if (!newArg.startsWith(Argument.argumentPrefix)) {
|
||||
// if (guildCommand.getArguments().get(newArg)!=null) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (guildCommand.getArguments().containsKey(newArg)) {
|
||||
//
|
||||
// argumentList.put(guildCommand.getArguments().get(newArg).getArgName(),
|
||||
// guildCommand.getArguments().get(newArg));
|
||||
// } else
|
||||
//
|
||||
// argumentList.put(newArg, new Argument(newArg));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
commandBlob.setArgs(newArguments);
|
||||
|
||||
guildCommandMap.get(command).run(commandBlob, this);
|
||||
|
||||
if (remainsValid) {
|
||||
guildCommand.runCommand(commandBlob, this, argumentList);
|
||||
}
|
||||
|
||||
if (printTime) {
|
||||
guildMessage.getChannel()
|
||||
.sendMessage("Time to run: " + (commandStartTime - System.currentTimeMillis()) + "ms")
|
||||
.sendMessage("Time to run: " + (System.currentTimeMillis() - commandStartTime) + "ms")
|
||||
.queue();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (Boot.isProd) {
|
||||
guildMessage.getChannel().sendMessage("```\n" + e + "```").queue();
|
||||
guildMessage.getChannel().sendMessage("```yaml\n" + e + "```").queue();
|
||||
} else {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
guildMessage.getChannel().sendMessage("```\n" + sw.toString() + "```").queue();
|
||||
guildMessage.getChannel().sendMessage("```yaml\n" + sw.toString() + "```").queue();
|
||||
System.err.println("Exception caught in: " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
|
||||
if (Boot.isProd) {
|
||||
guildMessage.getChannel().sendMessage("```\n" + t + "```").queue();
|
||||
guildMessage.getChannel().sendMessage("```apache\n" + t + "```").queue();
|
||||
} else {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
t.printStackTrace(pw);
|
||||
guildMessage.getChannel().sendMessage("```\n" + sw.toString() + "```").queue();
|
||||
guildMessage.getChannel().sendMessage("```apache\n" + sw.toString() + "```").queue();
|
||||
System.err.println("Error caught in: " + t.toString());
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package pkg.deepCurse.simpleLoggingGarbage.core;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package services;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CTimer extends Object implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1861304556437295528L;
|
||||
|
||||
int delay = 1000; // milliseconds
|
||||
int timerResetCount;
|
||||
ActionListener taskPerformer = new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.print("timer: " + timerResetCount);
|
||||
timerResetCount += 1;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
package services;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConsoleOut {
|
||||
private ByteArrayOutputStream baos;
|
||||
private PrintStream previous;
|
||||
private boolean capturing;
|
||||
|
||||
public void start() {
|
||||
if (capturing) {
|
||||
return;
|
||||
}
|
||||
|
||||
capturing = true;
|
||||
previous = System.out;
|
||||
baos = new ByteArrayOutputStream();
|
||||
|
||||
OutputStream outputStreamCombiner = new OutputStreamCombiner(Arrays.asList(previous, baos));
|
||||
PrintStream custom = new PrintStream(outputStreamCombiner);
|
||||
|
||||
System.setOut(custom);
|
||||
}
|
||||
|
||||
public String stop() {
|
||||
if (!capturing) {
|
||||
return "";
|
||||
}
|
||||
|
||||
System.setOut(previous);
|
||||
|
||||
String capturedValue = baos.toString();
|
||||
|
||||
baos = null;
|
||||
previous = null;
|
||||
capturing = false;
|
||||
|
||||
return capturedValue;
|
||||
}
|
||||
|
||||
private static class OutputStreamCombiner extends OutputStream {
|
||||
private List<OutputStream> outputStreams;
|
||||
|
||||
public OutputStreamCombiner(List<OutputStream> outputStreams) {
|
||||
this.outputStreams = outputStreams;
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
for (OutputStream os : outputStreams) {
|
||||
os.write(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
for (OutputStream os : outputStreams) {
|
||||
os.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
for (OutputStream os : outputStreams) {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue