some shit to do with the command manager, again
Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
parent
22837cf438
commit
cda31cfaa0
9 changed files with 237 additions and 108 deletions
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||||
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.DirectCommandBlob;
|
import pkg.deepCurse.nopalmo.manager.DirectCommandBlob;
|
||||||
|
@ -33,14 +34,11 @@ public interface CommandInterface { // TODO rewrite to implement type args?
|
||||||
General, Moderation, Fun, Info, Extra, TESTING, DEV, EGG
|
General, Moderation, Fun, Info, Extra, TESTING, DEV, EGG
|
||||||
}
|
}
|
||||||
|
|
||||||
public default String getHelp() {
|
public String getHelp();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public default String getUsage() {
|
public default String getUsage() {
|
||||||
return null;
|
return Global.prefix + getCommandName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public default int getTimeout() {
|
public default int getTimeout() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package pkg.deepCurse.nopalmo.command.commands.general;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||||
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||||
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Guild;
|
||||||
|
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||||
|
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||||
|
|
||||||
|
public class Prefix implements GuildCommandInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getCommandCalls() {
|
||||||
|
return new String[] { "prefix", };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HelpPage getHelpPage() {
|
||||||
|
return HelpPage.General;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||||
|
|
||||||
|
if (argumentList.get("prefix") != null) {
|
||||||
|
// System.out.println(argumentList.get("prefix").getWildCardString());
|
||||||
|
Guild.Prefix.setPrefix(
|
||||||
|
blob.getEvent().getGuild().getIdLong(), argumentList.get("prefix").getWildCardString());
|
||||||
|
blob.getEvent().getChannel().sendMessage("Set prefix to " + argumentList.get("prefix").getWildCardString()).queue();
|
||||||
|
} else {
|
||||||
|
Guild.Prefix.setPrefix(
|
||||||
|
blob.getEvent().getGuild().getIdLong(), Global.prefix);
|
||||||
|
blob.getEvent().getChannel().sendMessage("Reset prefix to default").queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Argument> getArguments() {
|
||||||
|
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||||
|
|
||||||
|
args.put("prefix", new Argument("prefix").setPosition(0).setIsWildcard(true));
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsage() {
|
||||||
|
return Global.prefix + getCommandName() + " <prefix>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Sets a prefix for your guild";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -23,4 +23,21 @@ public class Git implements DualCommandInterface {
|
||||||
return HelpPage.Info;
|
return HelpPage.Info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Argument> getArguments() {
|
||||||
|
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||||
|
|
||||||
|
args.put("test", new Argument("test", (CommandBlob blob) -> {
|
||||||
|
|
||||||
|
blob.getChannel().sendMessage("This is the automatically running argument inside of " + this.getCommandName()).queue();
|
||||||
|
|
||||||
|
}).setPrefixRequirement(true).setAutoStartRunnable(true));
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Posts my github link";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class Ping implements DualCommandInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsage() {
|
public String getUsage() {
|
||||||
return Global.prefix + "ping [" + Argument.argumentPrefix + "all]";
|
return Global.prefix + getCommandName()+" [" + Argument.argumentPrefix + "all]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,4 +76,9 @@ public class Ping implements DualCommandInterface {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Returns the jda heartbeat ping";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package pkg.deepCurse.nopalmo.command.commands.info;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
|
||||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
|
||||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
|
||||||
|
|
||||||
public class Prefix implements GuildCommandInterface {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getCommandCalls() {
|
|
||||||
return new String[] { "prefix", };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HelpPage getHelpPage() {
|
|
||||||
return HelpPage.General;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<String, Argument> getArguments() {
|
|
||||||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
|
||||||
|
|
||||||
args.put("prefix", new Argument("prefix").setIsWildcard(true));
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -92,7 +92,7 @@ public class DatabaseTools {
|
||||||
|
|
||||||
if (prefix == null || prefix.isEmpty()) {
|
if (prefix == null || prefix.isEmpty()) {
|
||||||
// throw new IllegalArgumentException("Input cannot be empty");
|
// throw new IllegalArgumentException("Input cannot be empty");
|
||||||
prefix = ";";
|
prefix = Global.prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
@ -114,7 +114,7 @@ public class DatabaseTools {
|
||||||
SQLCode.sqlTranslate(pstmt, e);
|
SQLCode.sqlTranslate(pstmt, e);
|
||||||
for (int i : new int[] { 1062 }) {
|
for (int i : new int[] { 1062 }) {
|
||||||
if (i == e.getErrorCode()) {
|
if (i == e.getErrorCode()) {
|
||||||
return setPrefix(connection, guildID, prefix);
|
return setPrefix(guildID, prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -126,7 +126,7 @@ public class DatabaseTools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String setPrefix(Connection conn, long guildID, String prefix)
|
public static String setPrefix(long guildID, String prefix)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
if (prefix.isEmpty()) {
|
if (prefix.isEmpty()) {
|
||||||
|
@ -137,7 +137,7 @@ public class DatabaseTools {
|
||||||
|
|
||||||
String query = "update guilds set prefix = ? where guildid = ?;";
|
String query = "update guilds set prefix = ? where guildid = ?;";
|
||||||
try {
|
try {
|
||||||
pstmt = conn.prepareStatement(query);
|
pstmt = connection.prepareStatement(query);
|
||||||
|
|
||||||
pstmt.setLong(2, guildID);
|
pstmt.setLong(2, guildID);
|
||||||
pstmt.setString(1, prefix);
|
pstmt.setString(1, prefix);
|
||||||
|
@ -146,12 +146,12 @@ public class DatabaseTools {
|
||||||
int[] updateCounts = pstmt.executeBatch();
|
int[] updateCounts = pstmt.executeBatch();
|
||||||
checkUpdateCounts(pstmt, updateCounts);
|
checkUpdateCounts(pstmt, updateCounts);
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
conn.commit();
|
// conn.commit();
|
||||||
return prefix;
|
return prefix;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
SQLCode.sqlTranslate(pstmt, e);
|
SQLCode.sqlTranslate(pstmt, e);
|
||||||
try {
|
try {
|
||||||
conn.rollback();
|
connection.rollback();
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,30 +36,8 @@ public class GuildMessageReceivedListener extends ListenerAdapter {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] prefixArray = new String[] { DatabaseTools.Tools.Guild.Prefix.getPrefix(event.getGuild().getIdLong()),
|
|
||||||
"<@!" + event.getJDA().getSelfUser().getIdLong() + ">" }; // FIXME BROKEN PING PREFIX
|
|
||||||
|
|
||||||
boolean shouldReturn = true;
|
|
||||||
for (String i : prefixArray) { // TODO switch to [] to skip for loop?
|
|
||||||
|
|
||||||
if (messageRaw.startsWith(i)) {
|
|
||||||
shouldReturn = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO add pre manager commands
|
|
||||||
|
|
||||||
if (shouldReturn) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event.getAuthor().isBot()) {
|
if (!event.getAuthor().isBot()) {
|
||||||
|
|
||||||
Boot.guildCommandManager.startCommand(event);
|
Boot.guildCommandManager.startCommand(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pkg.deepCurse.nopalmo.manager;
|
package pkg.deepCurse.nopalmo.manager;
|
||||||
|
|
||||||
|
import pkg.deepCurse.nopalmo.command.CommandInterface;
|
||||||
|
|
||||||
public class Argument {
|
public class Argument {
|
||||||
|
|
||||||
// README
|
// README
|
||||||
|
@ -22,6 +24,11 @@ public class Argument {
|
||||||
private Argument[] subArgs = null;
|
private Argument[] subArgs = null;
|
||||||
private boolean requiresPrefix = false;
|
private boolean requiresPrefix = false;
|
||||||
private Boolean isWildcard;
|
private Boolean isWildcard;
|
||||||
|
private int position = -1;
|
||||||
|
private String wildCardString = null;
|
||||||
|
private boolean autoStartRunnable = false;
|
||||||
|
private boolean skipOriginalTaskOnRunnable = false;
|
||||||
|
private RunnableArg runnableArg = null;
|
||||||
|
|
||||||
public static final String argumentPrefix = "-"; // This exists for the sole reason of customization and will
|
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
|
// generally not change, ever, its recommended you keep it to
|
||||||
|
@ -54,6 +61,7 @@ public class Argument {
|
||||||
this.requiredArgs = requiredArgs;
|
this.requiredArgs = requiredArgs;
|
||||||
this.argName = argName;
|
this.argName = argName;
|
||||||
this.subArgs = subArgs;
|
this.subArgs = subArgs;
|
||||||
|
this.runnableArg = runnableArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +86,7 @@ public class Argument {
|
||||||
*/
|
*/
|
||||||
public Argument(String argName, RunnableArg runnableArg) {
|
public Argument(String argName, RunnableArg runnableArg) {
|
||||||
this.argName = argName;
|
this.argName = argName;
|
||||||
|
this.runnableArg = runnableArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRequiredArgs() {
|
public int getRequiredArgs() {
|
||||||
|
@ -113,6 +122,11 @@ public class Argument {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Argument setIsWildcard(Boolean bool) {
|
public Argument setIsWildcard(Boolean bool) {
|
||||||
|
|
||||||
|
if (this.position<=-1) {
|
||||||
|
throw new IllegalArgumentException("Cannot create a wildcard without a position; set a position first");
|
||||||
|
}
|
||||||
|
|
||||||
this.isWildcard = bool;
|
this.isWildcard = bool;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -125,10 +139,50 @@ public class Argument {
|
||||||
return this.requiresPrefix;
|
return this.requiresPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Argument setPosition(int position) {
|
||||||
|
this.position = position;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public interface RunnableArg {
|
public interface RunnableArg {
|
||||||
|
|
||||||
public void run(Argument[] argArray);
|
public void run(CommandBlob blob);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Argument setWildCardString(String wildCardString) {
|
||||||
|
this.wildCardString = wildCardString;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWildCardString() {
|
||||||
|
return wildCardString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Argument setAutoStartRunnable(boolean bool) {
|
||||||
|
this.autoStartRunnable = bool;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAutoStartRunnable() {
|
||||||
|
return autoStartRunnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSkipOriginalTaskOnRunnable() {
|
||||||
|
return skipOriginalTaskOnRunnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Argument setSkipOriginalTaskOnRunnable(boolean skipOriginalTaskOnRunnable) {
|
||||||
|
this.skipOriginalTaskOnRunnable = skipOriginalTaskOnRunnable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RunnableArg getRunnableArg() {
|
||||||
|
return runnableArg;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||||
|
import pkg.deepCurse.nopalmo.command.commands.general.Prefix;
|
||||||
import pkg.deepCurse.nopalmo.command.commands.info.Git;
|
import pkg.deepCurse.nopalmo.command.commands.info.Git;
|
||||||
import pkg.deepCurse.nopalmo.command.commands.info.Help;
|
import pkg.deepCurse.nopalmo.command.commands.info.Help;
|
||||||
import pkg.deepCurse.nopalmo.command.commands.info.Ping;
|
import pkg.deepCurse.nopalmo.command.commands.info.Ping;
|
||||||
import pkg.deepCurse.nopalmo.command.commands.info.Prefix;
|
|
||||||
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.global.Tools;
|
import pkg.deepCurse.nopalmo.global.Tools;
|
||||||
|
@ -58,12 +58,31 @@ public class GuildCommandManager extends CommandManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startCommand(GuildMessageReceivedEvent guildMessage) {
|
public void startCommand(GuildMessageReceivedEvent guildMessageEvent) { // TODO SPLIT UP AND INHERIT
|
||||||
|
|
||||||
final String message = guildMessage.getMessage().getContentRaw();
|
final String message = guildMessageEvent.getMessage().getContentRaw();
|
||||||
|
String prefix = DatabaseTools.Tools.Guild.Prefix.getPrefix(guildMessageEvent.getGuild().getIdLong());
|
||||||
|
String pingPrefix = "<@!" + guildMessageEvent.getJDA().getSelfUser().getIdLong() + ">";
|
||||||
|
|
||||||
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(DatabaseTools.Tools.Global.prefix), "")
|
// String splicer = null;
|
||||||
.split("\\s+");
|
// String[] prefixArray = new String[] { DatabaseTools.Tools.Guild.Prefix.getPrefix(guildMessageEvent.getGuild().getIdLong()),
|
||||||
|
// "<@!" + guildMessageEvent.getJDA().getSelfUser().getIdLong() + ">" }; // FIXME BROKEN PING PREFIX
|
||||||
|
// for () {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
String splicer = null;
|
||||||
|
if (message.startsWith(pingPrefix + " ")) {
|
||||||
|
splicer = pingPrefix + " ";
|
||||||
|
} else if (message.startsWith(prefix)) {
|
||||||
|
splicer = prefix;
|
||||||
|
} else if (message.startsWith(pingPrefix)) {
|
||||||
|
splicer = pingPrefix;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
|
||||||
final String command = split[0].toLowerCase();
|
final String command = split[0].toLowerCase();
|
||||||
|
|
||||||
if (guildCommandMap.containsKey(command)) {
|
if (guildCommandMap.containsKey(command)) {
|
||||||
|
@ -76,55 +95,90 @@ public class GuildCommandManager extends CommandManager {
|
||||||
// ArrayList<String> newArguments = new ArrayList<String>();
|
// ArrayList<String> newArguments = new ArrayList<String>();
|
||||||
// ArrayList<String> commandFlags = new ArrayList<String>();
|
// ArrayList<String> commandFlags = new ArrayList<String>();
|
||||||
|
|
||||||
GuildCommandBlob commandBlob = new GuildCommandBlob(guildMessage);
|
GuildCommandBlob commandBlob = new GuildCommandBlob(guildMessageEvent);
|
||||||
GuildCommandInterface guildCommand = guildCommandMap.get(command);
|
GuildCommandInterface guildCommand = guildCommandMap.get(command);
|
||||||
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
||||||
|
|
||||||
boolean printTime = false;
|
boolean printTime = false;
|
||||||
byte argSkipCount = 0;
|
byte argSkipCount = 0;
|
||||||
boolean remainsValid = true;
|
boolean remainsValid = true;
|
||||||
boolean isWildCard = false;
|
// int id = 0;
|
||||||
|
|
||||||
for (String x : args) {
|
HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
|
||||||
boolean taken = false;
|
|
||||||
|
for (Argument i : guildCommand.getArguments().values()) {
|
||||||
|
if (i.getPosition() >= 0) {
|
||||||
|
positionalArgs.put(i.getPosition(), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i.isSkipOriginalTaskOnRunnable()) {
|
||||||
|
remainsValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < args.size(); i++) {
|
||||||
|
String x = args.get(i);
|
||||||
x = x.toLowerCase();
|
x = x.toLowerCase();
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case "\\time":
|
case "\\time":
|
||||||
printTime = true;
|
printTime = true;
|
||||||
break;
|
break;
|
||||||
case "\\perm":
|
case "\\perm":
|
||||||
// commandFlags.add("user:380045419381784576");
|
|
||||||
commandBlob.setUserID(380045419381784576L);
|
commandBlob.setUserID(380045419381784576L);
|
||||||
break;
|
break;
|
||||||
case "\\del":
|
case "\\del":
|
||||||
guildMessage.getMessage().delete().queue();
|
guildMessageEvent.getMessage().delete().queue();
|
||||||
break;
|
break;
|
||||||
default: // in the rewrite process
|
default:
|
||||||
if (argSkipCount <= 0) {
|
if (argSkipCount <= 0) {
|
||||||
|
|
||||||
if (guildCommand.getArguments() != null) {
|
if (guildCommand.getArguments() != null) {
|
||||||
|
|
||||||
|
if (positionalArgs.get(i) == null) {
|
||||||
|
|
||||||
if (x.startsWith(Argument.argumentPrefix)) {
|
if (x.startsWith(Argument.argumentPrefix)) {
|
||||||
|
|
||||||
String pre = x.substring(Argument.argumentPrefix.length());
|
String pre = x.substring(Argument.argumentPrefix.length());
|
||||||
if (guildCommand.getArguments().keySet().contains(pre)) {
|
if (guildCommand.getArguments().keySet().contains(pre)) {
|
||||||
argumentList.put(pre, guildCommand.getArguments().get(pre));
|
argumentList.put(pre, guildCommand.getArguments().get(pre));
|
||||||
taken = true;
|
if (guildCommand.getArguments().get(pre).isAutoStartRunnable()
|
||||||
|
&& guildCommand.getArguments().get(pre)
|
||||||
|
.getRunnableArg() != null) {
|
||||||
|
guildCommand.getArguments().get(pre).getRunnableArg()
|
||||||
|
.run(new CommandBlob(commandBlob));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Tools.wrongUsage(guildMessage.getChannel(), guildCommand);
|
Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if (!guildCommand.getArguments().get(x).getIsWildcard()) {
|
if (guildCommand.getArguments().get(x) != null) {
|
||||||
if (guildCommand.getArguments().get(x).getPrefixRequirement()) {
|
if (guildCommand.getArguments().get(x).getPrefixRequirement()) {
|
||||||
Tools.wrongUsage(guildMessage.getChannel(), guildCommand);
|
Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
} else {
|
} else {
|
||||||
argumentList.put(x, guildCommand.getArguments().get(x));
|
argumentList.put(x, guildCommand.getArguments().get(x));
|
||||||
taken = true;
|
if (guildCommand.getArguments().get(x).isAutoStartRunnable()
|
||||||
|
&& guildCommand.getArguments().get(x)
|
||||||
|
.getRunnableArg() != null) {
|
||||||
|
guildCommand.getArguments().get(x).getRunnableArg()
|
||||||
|
.run(new CommandBlob(commandBlob));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
|
||||||
|
remainsValid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,31 +192,31 @@ public class GuildCommandManager extends CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printTime) {
|
if (printTime) {
|
||||||
guildMessage.getChannel()
|
guildMessageEvent.getChannel()
|
||||||
.sendMessage("Time to run: " + (System.currentTimeMillis() - commandStartTime) + "ms")
|
.sendMessage("Time to run: " + (System.currentTimeMillis() - commandStartTime) + "ms")
|
||||||
.queue();
|
.queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (Boot.isProd) {
|
if (Boot.isProd) {
|
||||||
guildMessage.getChannel().sendMessage("```properties\n" + e + "```").queue();
|
guildMessageEvent.getChannel().sendMessage("```properties\n" + e + "```").queue();
|
||||||
} else {
|
} else {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
e.printStackTrace(pw);
|
e.printStackTrace(pw);
|
||||||
guildMessage.getChannel().sendMessage("```properties\n" + sw.toString() + "```").queue();
|
guildMessageEvent.getChannel().sendMessage("```properties\n" + sw.toString() + "```").queue();
|
||||||
System.err.println("Exception caught in: " + e.toString());
|
System.err.println("Exception caught in: " + e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
|
||||||
if (Boot.isProd) {
|
if (Boot.isProd) {
|
||||||
guildMessage.getChannel().sendMessage("```mathematica\n" + t + "```").queue();
|
guildMessageEvent.getChannel().sendMessage("```mathematica\n" + t + "```").queue();
|
||||||
} else {
|
} else {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
t.printStackTrace(pw);
|
t.printStackTrace(pw);
|
||||||
guildMessage.getChannel().sendMessage("```mathematica\n" + sw.toString() + "```").queue();
|
guildMessageEvent.getChannel().sendMessage("```mathematica\n" + sw.toString() + "```").queue();
|
||||||
System.err.println("Error caught in: " + t.toString());
|
System.err.println("Error caught in: " + t.toString());
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue