cuts out legacy command manager
fully joins both message and command handlers Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
parent
3cd8f3404c
commit
b64a3639f3
22 changed files with 275 additions and 1193 deletions
|
@ -10,5 +10,6 @@
|
||||||
<classpathentry kind="lib" path="/libs/discord/JDA-4.4.0_350-withDependencies.jar" sourcepath="/libs/discord/JDA-4.4.0_350-sources.jar"/>
|
<classpathentry kind="lib" path="/libs/discord/JDA-4.4.0_350-withDependencies.jar" sourcepath="/libs/discord/JDA-4.4.0_350-sources.jar"/>
|
||||||
<classpathentry kind="lib" path="/libs/logging/slf4j-api-1.7.9.jar" sourcepath="/libs/logging/slf4j-api-1.7.9-sources.jar"/>
|
<classpathentry kind="lib" path="/libs/logging/slf4j-api-1.7.9.jar" sourcepath="/libs/logging/slf4j-api-1.7.9-sources.jar"/>
|
||||||
<classpathentry kind="lib" path="/libs/logging/slf4j-simple-1.7.9.jar" sourcepath="/libs/logging/slf4j-simple-1.7.9-sources.jar"/>
|
<classpathentry kind="lib" path="/libs/logging/slf4j-simple-1.7.9.jar" sourcepath="/libs/logging/slf4j-simple-1.7.9-sources.jar"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/Phoenix"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -8,8 +8,6 @@ import net.dv8tion.jda.api.Permission;
|
||||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
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.GuildCommandBlob;
|
|
||||||
|
|
||||||
public interface CommandInterface { // TODO rewrite to implement type args?
|
public interface CommandInterface { // TODO rewrite to implement type args?
|
||||||
|
|
||||||
|
@ -60,29 +58,27 @@ public interface CommandInterface { // TODO rewrite to implement type args?
|
||||||
@Nullable
|
@Nullable
|
||||||
public HashMap<String, Argument> getArguments();
|
public HashMap<String, Argument> getArguments();
|
||||||
|
|
||||||
public interface DualCommandInterface extends DirectCommandInterface, GuildCommandInterface {
|
public interface DualCommandInterface extends PrivateCommandInterface, GuildCommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public default void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentMap)
|
public default void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||||
throws Exception {
|
runDualCommand(blob, argumentMap);
|
||||||
runDualCommand(new CommandBlob(blob), argumentMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentMap)
|
public default void runDirectCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||||
throws Exception {
|
runDualCommand(blob, argumentMap);
|
||||||
runDualCommand(new CommandBlob(blob), argumentMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception;
|
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DirectCommandInterface extends CommandInterface {
|
public interface PrivateCommandInterface extends CommandInterface {
|
||||||
public void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception;
|
public void runDirectCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface GuildCommandInterface extends CommandInterface {
|
public interface GuildCommandInterface extends CommandInterface {
|
||||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception;
|
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception;
|
||||||
|
|
||||||
public default Permission[] getRequiredPermissions() {
|
public default Permission[] getRequiredPermissions() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Guild;
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Guild;
|
||||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
|
||||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||||
|
|
||||||
public class Prefix implements GuildCommandInterface {
|
public class Prefix implements GuildCommandInterface {
|
||||||
|
|
||||||
|
@ -22,17 +22,19 @@ public class Prefix implements GuildCommandInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||||
|
|
||||||
if (argumentList.get("prefix") != null) {
|
if (argumentList.get("prefix") != null) {
|
||||||
Guild.Prefix.setPrefix(
|
Guild.Prefix.setPrefix(blob.getGuildID(), argumentList.get("prefix").getWildCardString());
|
||||||
blob.getEvent().getGuild().getIdLong(), argumentList.get("prefix").getWildCardString());
|
blob.getChannel().sendMessage("Set prefix to " + argumentList.get("prefix").getWildCardString()).queue();
|
||||||
blob.getEvent().getChannel().sendMessage("Set prefix to " + argumentList.get("prefix").getWildCardString()).queue();
|
if (!Users.isAdvancedUser(blob.getAuthorID()))
|
||||||
if (!Users.isAdvancedUser(blob.getUserID())) blob.getChannel().sendMessage("Remember: you can always ping me to use any command in case you forget the prefix").queue();
|
blob.getChannel()
|
||||||
|
.sendMessage(
|
||||||
|
"Remember: you can always ping me to use any command in case you forget the prefix")
|
||||||
|
.queue();
|
||||||
} else {
|
} else {
|
||||||
Guild.Prefix.setPrefix(
|
Guild.Prefix.setPrefix(blob.getGuildID(), Global.prefix);
|
||||||
blob.getEvent().getGuild().getIdLong(), Global.prefix);
|
blob.getChannel().sendMessage("Reset prefix to default").queue();
|
||||||
blob.getEvent().getChannel().sendMessage("Reset prefix to default").queue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||||
|
|
||||||
public class Test implements GuildCommandInterface {
|
public class Test implements GuildCommandInterface {
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ public class Test implements GuildCommandInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||||
blob.getEvent().getChannel().sendMessage("Tested").queue();
|
blob.getChannel().sendMessage("Tested").queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,9 @@ public class Git implements DualCommandInterface {
|
||||||
|
|
||||||
args.put("test", new Argument("test", (CommandBlob blob) -> {
|
args.put("test", new Argument("test", (CommandBlob blob) -> {
|
||||||
|
|
||||||
blob.getChannel().sendMessage("This is the automatically running argument inside of " + this.getCommandName()).queue();
|
blob.getChannel()
|
||||||
|
.sendMessage("This is the automatically running argument inside of " + this.getCommandName())
|
||||||
|
.queue();
|
||||||
|
|
||||||
}).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true));
|
}).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true));
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,13 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface;
|
import pkg.deepCurse.nopalmo.command.CommandInterface;
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
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.CommandManager;
|
import pkg.deepCurse.nopalmo.manager.CommandManager;
|
||||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
|
||||||
|
|
||||||
public class Help implements GuildCommandInterface {
|
public class Help implements GuildCommandInterface {
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ public class Help implements GuildCommandInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runGuildCommand(GuildCommandBlob 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 isDevEnabled = argumentMap.get("dev") != null;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class Help implements GuildCommandInterface {
|
||||||
|
|
||||||
HashMap<HelpPage, List<String>> commandHash = new HashMap<HelpPage, List<String>>();
|
HashMap<HelpPage, List<String>> commandHash = new HashMap<HelpPage, List<String>>();
|
||||||
|
|
||||||
for (GuildCommandInterface command : manager.getGuildCommands()) {
|
for (CommandInterface command : manager.getCommands()) {
|
||||||
List<String> commandNameList = commandHash.get(command.getHelpPage());
|
List<String> commandNameList = commandHash.get(command.getHelpPage());
|
||||||
if (commandNameList == null) {
|
if (commandNameList == null) {
|
||||||
commandNameList = new ArrayList<String>();
|
commandNameList = new ArrayList<String>();
|
||||||
|
@ -70,25 +71,24 @@ public class Help implements GuildCommandInterface {
|
||||||
|
|
||||||
StringBuilder sB = new StringBuilder();
|
StringBuilder sB = new StringBuilder();
|
||||||
|
|
||||||
CommandInterface ping = blob.getCommandManager().getDirectCommand("ping");
|
CommandInterface ping = blob.getCommandManager().getCommand("ping");
|
||||||
if (ping != null) {
|
if (ping != null) {
|
||||||
sB.append("`" + ping.getUsage(isDevEnabled) + "`\n");
|
sB.append("`" + ping.getUsage(isDevEnabled) + "`\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandInterface info = blob.getCommandManager().getDirectCommand("info");
|
CommandInterface info = blob.getCommandManager().getCommand("info");
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
sB.append("`" + info.getUsage(isDevEnabled) + "`\n");
|
sB.append("`" + info.getUsage(isDevEnabled) + "`\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandInterface prefix = blob.getCommandManager().getDirectCommand("prefix");
|
CommandInterface prefix = blob.getCommandManager().getCommand("prefix");
|
||||||
if (prefix != null) {
|
if (prefix != null) {
|
||||||
sB.append("`" + prefix.getUsage(isDevEnabled) + "`\n");
|
sB.append("`" + prefix.getUsage(isDevEnabled) + "`\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
embed.addField("Information:", "Commands to take note of:\n" + sB, false);
|
embed.addField("Information:", "Commands to take note of:\n" + sB, false);
|
||||||
|
|
||||||
embed.setFooter(blob.getEvent().getMember().getEffectiveName(),
|
embed.setFooter(blob.getMember().getEffectiveName(), blob.getAuthor().getEffectiveAvatarUrl());
|
||||||
blob.getEvent().getMember().getUser().getEffectiveAvatarUrl());
|
|
||||||
embed.setTimestamp(Instant.now());
|
embed.setTimestamp(Instant.now());
|
||||||
embed.setColor(Global.getEmbedColor());
|
embed.setColor(Global.getEmbedColor());
|
||||||
|
|
||||||
|
@ -97,11 +97,11 @@ public class Help implements GuildCommandInterface {
|
||||||
return;
|
return;
|
||||||
} else if (argumentMap.get("commandName") != null) {
|
} else if (argumentMap.get("commandName") != null) {
|
||||||
|
|
||||||
GuildCommandInterface command = manager.getGuildCommand(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()) && isDevEnabled)
|
||||||
|| !deniedPages.contains(command.getHelpPage()))) {
|
|| !deniedPages.contains(command.getHelpPage()))) {
|
||||||
if (!(command.isNSFW() && !blob.getChannel().isNSFW())) {
|
if (!blob.isFromGuild() ? true : !(command.isNSFW() && !((TextChannel) blob.getChannel()).isNSFW())) {
|
||||||
EmbedBuilder eB = new EmbedBuilder();
|
EmbedBuilder eB = new EmbedBuilder();
|
||||||
|
|
||||||
eB.setColor(Global.getEmbedColor());
|
eB.setColor(Global.getEmbedColor());
|
||||||
|
@ -118,8 +118,7 @@ public class Help implements GuildCommandInterface {
|
||||||
|
|
||||||
eB.addField("Page:", command.getHelpPage().toString(), true); // ("Page: " +
|
eB.addField("Page:", command.getHelpPage().toString(), true); // ("Page: " +
|
||||||
// command.getHelpPage().toString());
|
// command.getHelpPage().toString());
|
||||||
eB.setFooter(blob.getEvent().getMember().getEffectiveName(),
|
eB.setFooter(blob.getMember().getEffectiveName(), blob.getAuthor().getEffectiveAvatarUrl());
|
||||||
blob.getEvent().getMember().getUser().getEffectiveAvatarUrl());
|
|
||||||
eB.setTimestamp(Instant.now());
|
eB.setTimestamp(Instant.now());
|
||||||
|
|
||||||
if (command.getCommandCalls().length > 1) {
|
if (command.getCommandCalls().length > 1) {
|
||||||
|
@ -134,9 +133,9 @@ public class Help implements GuildCommandInterface {
|
||||||
sB.append("Is nsfw: " + command.isNSFW() + "\n");
|
sB.append("Is nsfw: " + command.isNSFW() + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.getRequiredPermission() != null) {
|
// if (command.getRequiredPermission() != null) {
|
||||||
sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
|
// sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (command.getTimeout() > 0) {
|
if (command.getTimeout() > 0) {
|
||||||
sB.append("Usage Timeout: " + command.getTimeout() + "\n");
|
sB.append("Usage Timeout: " + command.getTimeout() + "\n");
|
||||||
|
|
|
@ -4,15 +4,13 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface.DirectCommandInterface;
|
|
||||||
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.database.DatabaseTools.Tools.Users;
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
|
||||||
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.GuildCommandBlob;
|
|
||||||
|
|
||||||
public class Info implements GuildCommandInterface, DirectCommandInterface {
|
public class Info implements GuildCommandInterface, PrivateCommandInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getCommandCalls() {
|
public String[] getCommandCalls() {
|
||||||
|
@ -34,19 +32,18 @@ public class Info implements GuildCommandInterface, DirectCommandInterface {
|
||||||
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.getUserID())).queue();
|
blob.getChannel().sendMessage(Users.dump(blob.getAuthorID())).queue();
|
||||||
}).setPrefixRequirement(true).setAutoStartRunnable(true)
|
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true));
|
||||||
.setSkipOriginalTaskOnRunnable(true));
|
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
public void runDirectCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||||
blob.getChannel().sendMessage("EEE").queue();
|
blob.getChannel().sendMessage("EEE").queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,8 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||||
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.listener.DirectMessageReceivedListener;
|
import pkg.deepCurse.nopalmo.listener.MessageReceivedListener;
|
||||||
import pkg.deepCurse.nopalmo.listener.GuildMessageReceivedListener;
|
|
||||||
import pkg.deepCurse.nopalmo.manager.CommandManager;
|
import pkg.deepCurse.nopalmo.manager.CommandManager;
|
||||||
import pkg.deepCurse.nopalmo.manager.DirectCommandManager;
|
|
||||||
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
|
|
||||||
import pkg.deepCurse.nopalmo.manager.StatusManager;
|
import pkg.deepCurse.nopalmo.manager.StatusManager;
|
||||||
import pkg.deepCurse.nopalmo.utils.Locks;
|
import pkg.deepCurse.nopalmo.utils.Locks;
|
||||||
import pkg.deepCurse.nopalmo.utils.LogHelper;
|
import pkg.deepCurse.nopalmo.utils.LogHelper;
|
||||||
|
@ -116,8 +113,9 @@ public class Boot {
|
||||||
|
|
||||||
.setAutoReconnect(true)
|
.setAutoReconnect(true)
|
||||||
|
|
||||||
.addEventListeners(new GuildMessageReceivedListener())
|
// .addEventListeners(new GuildMessageReceivedListener())
|
||||||
.addEventListeners(new DirectMessageReceivedListener())
|
// .addEventListeners(new DirectMessageReceivedListener())
|
||||||
|
.addEventListeners(new MessageReceivedListener())
|
||||||
|
|
||||||
.setEnableShutdownHook(true)
|
.setEnableShutdownHook(true)
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,19 @@ import java.util.HashMap;
|
||||||
|
|
||||||
public class Reactions {
|
public class Reactions {
|
||||||
|
|
||||||
private static HashMap<String, Long> reactionMap = new HashMap<String, Long>();
|
private static final HashMap<String, Long> reactionMap = new HashMap<String, Long>();
|
||||||
|
private static final HashMap<String, String> internalReactionMap = new HashMap<String, String>();
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
insert("galaxyThumb", 801657838358495232L);
|
insert("galaxyThumb", 801657838358495232L);
|
||||||
insert("kirbo_wadafuq", 799633705068003338L);
|
insert("kirbo_wadafuq", 799633705068003338L);
|
||||||
|
|
||||||
|
insertInternal("flushed", "U+1F633");
|
||||||
|
insertInternal("eggplant", "U+1F346");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void insertInternal(String name, String emote) {
|
||||||
|
internalReactionMap.put(name, emote);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void insert(String input, long id) {
|
public static void insert(String input, long id) {
|
||||||
|
@ -17,11 +24,11 @@ public class Reactions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getReaction(String id) {
|
public static String getReaction(String id) {
|
||||||
return ":" + id + ":" + reactionMap.get(id);
|
return id.startsWith(":") ? internalReactionMap.get(id.substring(1)) : ":" + id + ":" + reactionMap.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEmote(String id) {
|
public static String getEmote(String id) {
|
||||||
return "<:" + id + ":" + reactionMap.get(id) + ">";
|
return id.startsWith(":") ? internalReactionMap.get(id.substring(1)) : "<:" + id + ":" + reactionMap.get(id) + ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ public class Tools {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void invalidPermissions(MessageChannel messageChannel, CommandInterface command) {
|
public static void invalidPermissions(MessageChannel messageChannel, CommandInterface command) {
|
||||||
messageChannel.sendMessage("Sorry, but you are not allowed to use that! Try this:\n" + command.getUsage(false)).queue();
|
messageChannel.sendMessage("Sorry, but you are not allowed to use that! Try this:\n" + command.getUsage(false))
|
||||||
|
.queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void wrongUsage(MessageChannel tc, DirectCommandInterface c) {
|
// public static void wrongUsage(MessageChannel tc, DirectCommandInterface c) {
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
package pkg.deepCurse.nopalmo.listener;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
|
||||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class DirectMessageReceivedListener extends ListenerAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReady(@Nonnull ReadyEvent event) {
|
|
||||||
System.out.println("DirectMessageReceivedListener is now ready. . .");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrivateMessageReceived(@Nonnull PrivateMessageReceivedEvent 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
|
|
||||||
|
|
||||||
event.getJDA().shutdown();
|
|
||||||
System.exit(7);
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] prefixArray = new String[] { Global.prefix, "<@! " + event.getJDA().getSelfUser().getIdLong() + ">" };
|
|
||||||
|
|
||||||
boolean shouldReturn = true;
|
|
||||||
for (String i : prefixArray) { // TODO switch to [] to skip for loop?
|
|
||||||
|
|
||||||
if (messageRaw.startsWith(i)) {
|
|
||||||
shouldReturn = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO add pre manager commands
|
|
||||||
|
|
||||||
if (shouldReturn) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event.getAuthor().isBot()) {
|
|
||||||
Boot.commandManager.startCommand(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -4,33 +4,31 @@ import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
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.Global;
|
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||||
|
import pkg.deepCurse.nopalmo.global.Reactions;
|
||||||
|
|
||||||
public class GuildMessageReceivedListener extends ListenerAdapter {
|
public class MessageReceivedListener extends ListenerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReady(@Nonnull ReadyEvent event) {
|
public void onReady(@Nonnull ReadyEvent event) {
|
||||||
System.out.println("GuildMessageReceivedListener is now ready\n" + event.getGuildAvailableCount() + "/"
|
System.out.println("MessageReceivedListener is now ready\n" + event.getGuildAvailableCount() + "/"
|
||||||
+ event.getGuildTotalCount() + " : " + event.getGuildUnavailableCount() + " <"
|
+ event.getGuildTotalCount() + " : " + event.getGuildUnavailableCount() + " <"
|
||||||
+ event.getResponseNumber() + ">");
|
+ event.getResponseNumber() + ">");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
|
||||||
Message message = event.getMessage();
|
Message message = event.getMessage();
|
||||||
String messageRaw = message.getContentRaw();
|
String messageRaw = message.getContentRaw();
|
||||||
|
|
||||||
if (messageRaw.contentEquals(Global.prefix + Global.prefix)
|
if (messageRaw.contentEquals(Global.prefix + Global.prefix)
|
||||||
&& DatabaseTools.Tools.Developers.canPowerOffBot(event.getAuthor().getIdLong())) {
|
&& DatabaseTools.Tools.Developers.canPowerOffBot(event.getAuthor().getIdLong())) {
|
||||||
|
|
||||||
// message.addReaction(Reactions.getReaction("galaxyThumb")).complete();
|
message.addReaction(Reactions.getReaction(":eggplant")).complete();
|
||||||
// TODO re enable
|
|
||||||
|
|
||||||
message.delete().complete();
|
|
||||||
|
|
||||||
event.getJDA().shutdown();
|
event.getJDA().shutdown();
|
||||||
System.exit(7);
|
System.exit(7);
|
|
@ -3,117 +3,164 @@ package pkg.deepCurse.nopalmo.manager;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.PrivateChannel;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
|
||||||
|
|
||||||
public class CommandBlob {
|
public class CommandBlob {
|
||||||
|
|
||||||
// CONTAINER/TRANSLATOR CLASS FOR COMMAND BLOBS
|
private CommandManager commandManager = null;
|
||||||
|
private ArrayList<Argument> args = null;
|
||||||
|
|
||||||
|
private long authorID = 0;
|
||||||
|
private long channelID = 0;
|
||||||
|
private long guildID = 0;
|
||||||
|
private long messageID = 0;
|
||||||
|
|
||||||
private Event event = null;
|
private Event event = null;
|
||||||
private CommandManager commandManager = null;
|
|
||||||
private ArrayList<String> args = null;
|
|
||||||
private JDA bot = null;
|
private JDA bot = null;
|
||||||
|
private MessageChannel channel = null;
|
||||||
|
private User author = null;
|
||||||
|
private Guild guild = null;
|
||||||
|
private Member member = null;
|
||||||
|
private Message message = null;
|
||||||
|
|
||||||
private long userID = 0;
|
private boolean isWebhookMessage = false;
|
||||||
private long channelID = 0;
|
private boolean isFromGuild = false;
|
||||||
|
|
||||||
public CommandBlob(GuildMessageReceivedEvent event) {
|
public CommandBlob(MessageReceivedEvent event, CommandManager commandManager) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
this.bot = event.getJDA();
|
this.bot = event.getJDA();
|
||||||
|
this.commandManager = commandManager;
|
||||||
|
|
||||||
|
this.author = event.getAuthor();
|
||||||
|
this.authorID = this.author.getIdLong();
|
||||||
|
this.channel = event.getChannel();
|
||||||
|
this.channelID = this.channel.getIdLong();
|
||||||
|
this.message = event.getMessage();
|
||||||
|
this.messageID = event.getMessageIdLong();
|
||||||
|
this.isFromGuild = event.isFromGuild();
|
||||||
|
if (this.isFromGuild) {
|
||||||
|
this.guild = event.getGuild();
|
||||||
|
this.guildID = this.guild.getIdLong();
|
||||||
|
this.member = event.getMember();
|
||||||
|
this.isWebhookMessage = event.isWebhookMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob(MessageReceivedEvent event) {
|
public CommandManager getCommandManager() {
|
||||||
this.event = event;
|
return commandManager;
|
||||||
this.bot = event.getJDA();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob(GuildCommandBlob blob) {
|
public void setCommandManager(CommandManager commandManager) {
|
||||||
this.args = blob.getArgs();
|
this.commandManager = commandManager;
|
||||||
this.channelID = blob.getChannelID();
|
|
||||||
this.commandManager = blob.getCommandManager();
|
|
||||||
this.event = blob.getEvent();
|
|
||||||
this.userID = blob.getUserID();
|
|
||||||
this.bot = blob.getEvent().getJDA();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob(DirectCommandBlob blob) {
|
public ArrayList<Argument> getArgs() {
|
||||||
this.args = blob.getArgs();
|
return args;
|
||||||
this.channelID = blob.getChannelID();
|
}
|
||||||
this.commandManager = blob.getCommandManager();
|
|
||||||
this.event = blob.getEvent();
|
public void setArgs(ArrayList<Argument> args) {
|
||||||
this.userID = blob.getUserID();
|
this.args = args;
|
||||||
this.bot = blob.getEvent().getJDA();
|
}
|
||||||
|
|
||||||
|
public long getAuthorID() {
|
||||||
|
return authorID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthorID(long authorID) {
|
||||||
|
this.authorID = authorID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getChannelID() {
|
public long getChannelID() {
|
||||||
return channelID;
|
return channelID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob setChannelID(long channelID) {
|
public void setChannelID(long channelID) {
|
||||||
this.channelID = channelID;
|
this.channelID = channelID;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageChannel getChannel() {
|
public long getGuildID() {
|
||||||
TextChannel textChannel = bot.getTextChannelById(channelID);
|
return guildID;
|
||||||
if (textChannel != null){
|
|
||||||
return textChannel;
|
|
||||||
}
|
|
||||||
PrivateChannel privateChannel = bot.getPrivateChannelById(channelID);
|
|
||||||
if (privateChannel != null){
|
|
||||||
return privateChannel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageChannel getMessageChannel(long channelID) {
|
public void setGuildID(long guildID) {
|
||||||
return bot.getTextChannelById(channelID);
|
this.guildID = guildID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUserID() {
|
public long getMessageID() {
|
||||||
return userID;
|
return messageID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageID(long messageID) {
|
||||||
|
this.messageID = messageID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Event getEvent() {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvent(Event event) {
|
||||||
|
this.event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JDA getJDA() {
|
public JDA getJDA() {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob setUserID(long userID) {
|
public void setBot(JDA bot) {
|
||||||
this.userID = userID;
|
this.bot = bot;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getArgs() {
|
public MessageChannel getChannel() {
|
||||||
return args;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob setArgs(ArrayList<String> args) {
|
public void setChannel(MessageChannel messageChannel) {
|
||||||
this.args = args;
|
this.channel = messageChannel;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandManager getCommandManager() {
|
public User getAuthor() {
|
||||||
return commandManager;
|
return author;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandBlob setCommandManager(CommandManager commandManager) {
|
public void setAuthor(User author) {
|
||||||
this.commandManager = commandManager;
|
this.author = author;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event getEvent() {
|
public Member getMember() {
|
||||||
if (event instanceof GuildMessageReceivedEvent) {
|
return member;
|
||||||
return (GuildMessageReceivedEvent) event;
|
|
||||||
} else if (event instanceof MessageReceivedEvent) {
|
|
||||||
return (MessageReceivedEvent) event;
|
|
||||||
} else
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMember(Member member) {
|
||||||
|
this.member = member;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(Message message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWebhookMessage() {
|
||||||
|
return isWebhookMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWebhookMessage(boolean isWebhookMessage) {
|
||||||
|
this.isWebhookMessage = isWebhookMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFromGuild() {
|
||||||
|
return isFromGuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFromGuild(boolean isFromGuild) {
|
||||||
|
this.isFromGuild = isFromGuild;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,13 @@ import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface;
|
import pkg.deepCurse.nopalmo.command.CommandInterface;
|
||||||
import pkg.deepCurse.nopalmo.command.CommandInterface.DirectCommandInterface;
|
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.commands.general.Example;
|
||||||
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;
|
||||||
|
@ -32,8 +33,9 @@ import pkg.deepCurse.nopalmo.global.Tools;
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
private final Map<String, GuildCommandInterface> guildCommandMap = new HashMap<>();
|
private final Map<String, CommandInterface> commandMap = new HashMap<>();
|
||||||
private final Map<String, DirectCommandInterface> directCommandMap = new HashMap<>();
|
// private final Map<String, DirectCommandInterface> directCommandMap = new
|
||||||
|
// HashMap<>();
|
||||||
private static Executor executor = null;
|
private static Executor executor = null;
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager() {
|
||||||
|
@ -42,75 +44,41 @@ public class CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
addCommand(new Help(this));
|
addCommand(new Help(this));// guild
|
||||||
addCommand(new Ping());
|
addCommand(new Ping()); // dual
|
||||||
addCommand(new Git());
|
addCommand(new Git()); // dual
|
||||||
addCommand(new Prefix());
|
addCommand(new Prefix()); // guild
|
||||||
addCommand(new Test());
|
addCommand(new Test()); // guild
|
||||||
addCommand(new Info());
|
addCommand(new Info()); // guild direct
|
||||||
|
addCommand(new Example()); // dual
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCommand(CommandInterface c) {
|
private void addCommand(CommandInterface c) {
|
||||||
if (c instanceof DirectCommandInterface) {
|
if (!commandMap.containsKey(c.getCommandName())) {
|
||||||
addDirectCommand((DirectCommandInterface) c);
|
commandMap.put(c.getCommandName(), c);
|
||||||
}
|
|
||||||
if (c instanceof GuildCommandInterface) {
|
|
||||||
addGuildCommand((GuildCommandInterface) c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDirectCommand(DirectCommandInterface c) {
|
|
||||||
if (!directCommandMap.containsKey(c.getCommandName())) {
|
|
||||||
directCommandMap.put(c.getCommandName(), c);
|
|
||||||
} else {
|
} else {
|
||||||
directCommandMap.remove(c.getCommandName());
|
commandMap.remove(c.getCommandName());
|
||||||
directCommandMap.put(c.getCommandName(), c);
|
commandMap.put(c.getCommandName(), c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<DirectCommandInterface> getDirectCommands() {
|
public CommandInterface getCommand(String commandName) {
|
||||||
return directCommandMap.values();
|
return commandMap.get(commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectCommandInterface getDirectCommand(String commandName) {
|
public Collection<CommandInterface> getCommands() {
|
||||||
if (commandName != null) {
|
return commandMap.values();
|
||||||
return directCommandMap.get(commandName);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGuildCommand(GuildCommandInterface c) {
|
public void startCommand(MessageReceivedEvent event) { // TODO split up more
|
||||||
if (!guildCommandMap.containsKey(c.getCommandName())) {
|
|
||||||
guildCommandMap.put(c.getCommandName(), c);
|
|
||||||
} else {
|
|
||||||
guildCommandMap.remove(c.getCommandName());
|
|
||||||
guildCommandMap.put(c.getCommandName(), c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<GuildCommandInterface> getGuildCommands() {
|
|
||||||
return guildCommandMap.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuildCommandInterface getGuildCommand(String commandName) {
|
|
||||||
if (commandName != null) {
|
|
||||||
return guildCommandMap.get(commandName);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startCommand(Event event) {
|
|
||||||
if (event instanceof GuildMessageReceivedEvent) {
|
|
||||||
startGuildCommand((GuildMessageReceivedEvent) event);
|
|
||||||
} else if (event instanceof PrivateMessageReceivedEvent) {
|
|
||||||
startDirectCommand((PrivateMessageReceivedEvent)event);
|
|
||||||
} else throw new IllegalArgumentException("Invalid type");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startDirectCommand(PrivateMessageReceivedEvent event){
|
|
||||||
|
|
||||||
final String message = event.getMessage().getContentRaw();
|
final String message = event.getMessage().getContentRaw();
|
||||||
String prefix = Global.prefix;
|
String prefix = null;
|
||||||
|
if (event.isFromGuild()) {
|
||||||
|
prefix = DatabaseTools.Tools.Guild.Prefix.getPrefix(event.getGuild().getIdLong());
|
||||||
|
} else {
|
||||||
|
prefix = Global.prefix;
|
||||||
|
}
|
||||||
String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
||||||
|
|
||||||
String splicer = null;
|
String splicer = null;
|
||||||
|
@ -127,18 +95,15 @@ public class CommandManager {
|
||||||
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();
|
||||||
|
|
||||||
if (guildCommandMap.containsKey(commandCall)) {
|
if (commandMap.containsKey(commandCall)) {
|
||||||
final List<String> args = Arrays.asList(split).subList(1, split.length);
|
final List<String> args = Arrays.asList(split).subList(1, split.length);
|
||||||
|
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
long commandStartTime = System.currentTimeMillis();
|
long commandStartTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ArrayList<String> newArguments = new ArrayList<String>();
|
CommandBlob commandBlob = new CommandBlob(event, this);
|
||||||
// ArrayList<String> commandFlags = new ArrayList<String>();
|
CommandInterface command = commandMap.get(commandCall);
|
||||||
|
|
||||||
DirectCommandBlob commandBlob = new DirectCommandBlob(event);
|
|
||||||
DirectCommandInterface command = directCommandMap.get(commandCall);
|
|
||||||
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
||||||
|
|
||||||
boolean printTime = false;
|
boolean printTime = false;
|
||||||
|
@ -166,7 +131,7 @@ public class CommandManager {
|
||||||
printTime = true;
|
printTime = true;
|
||||||
break;
|
break;
|
||||||
case "\\perm":
|
case "\\perm":
|
||||||
commandBlob.setUserID(380045419381784576L);
|
commandBlob.setAuthorID(380045419381784576L);
|
||||||
break;
|
break;
|
||||||
case "\\del":
|
case "\\del":
|
||||||
event.getMessage().delete().queue();
|
event.getMessage().delete().queue();
|
||||||
|
@ -190,7 +155,8 @@ public class CommandManager {
|
||||||
if (command.getArguments().keySet().contains(pre)) {
|
if (command.getArguments().keySet().contains(pre)) {
|
||||||
offset++;
|
offset++;
|
||||||
if (command.getArguments().get(pre).getPermission() == null
|
if (command.getArguments().get(pre).getPermission() == null
|
||||||
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|| DatabaseTools.Tools.Developers.hasPermission(
|
||||||
|
commandBlob.getAuthorID(),
|
||||||
command.getArguments().get(pre).getPermission())) {
|
command.getArguments().get(pre).getPermission())) {
|
||||||
if (command.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
|
if (command.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
|
@ -198,8 +164,7 @@ public class CommandManager {
|
||||||
argumentList.put(pre, command.getArguments().get(pre));
|
argumentList.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()
|
command.getArguments().get(pre).getRunnableArg().run(commandBlob);
|
||||||
.run(new CommandBlob(commandBlob));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Tools.invalidPermissions(event.getChannel(), command);
|
Tools.invalidPermissions(event.getChannel(), command);
|
||||||
|
@ -213,7 +178,8 @@ public class CommandManager {
|
||||||
} else {
|
} else {
|
||||||
if (command.getArguments().get(x) != null) {
|
if (command.getArguments().get(x) != null) {
|
||||||
if (command.getArguments().get(x).getPermission() == null
|
if (command.getArguments().get(x).getPermission() == null
|
||||||
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|| DatabaseTools.Tools.Developers.hasPermission(
|
||||||
|
commandBlob.getAuthorID(),
|
||||||
command.getArguments().get(x).getPermission())) {
|
command.getArguments().get(x).getPermission())) {
|
||||||
if (command.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
|
if (command.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
|
@ -222,8 +188,7 @@ public class CommandManager {
|
||||||
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) {
|
||||||
command.getArguments().get(x).getRunnableArg()
|
command.getArguments().get(x).getRunnableArg().run(commandBlob);
|
||||||
.run(new CommandBlob(commandBlob));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Tools.invalidPermissions(event.getChannel(), command);
|
Tools.invalidPermissions(event.getChannel(), command);
|
||||||
|
@ -233,7 +198,7 @@ public class CommandManager {
|
||||||
if (positionalArgs.get(i - offset) != null) {
|
if (positionalArgs.get(i - offset) != null) {
|
||||||
if (positionalArgs.get(i - offset).getPermission() == null
|
if (positionalArgs.get(i - offset).getPermission() == null
|
||||||
|| DatabaseTools.Tools.Developers.hasPermission(
|
|| DatabaseTools.Tools.Developers.hasPermission(
|
||||||
commandBlob.getUserID(),
|
commandBlob.getAuthorID(),
|
||||||
positionalArgs.get(i - offset).getPermission())) {
|
positionalArgs.get(i - offset).getPermission())) {
|
||||||
if (positionalArgs.get(i - offset).isSkipOriginalTaskOnRunnable()) {
|
if (positionalArgs.get(i - offset).isSkipOriginalTaskOnRunnable()) {
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
|
@ -247,8 +212,7 @@ public class CommandManager {
|
||||||
}
|
}
|
||||||
if (positionalArgs.get(i - offset).isAutoStartRunnable()
|
if (positionalArgs.get(i - offset).isAutoStartRunnable()
|
||||||
&& positionalArgs.get(i - offset).getRunnableArg() != null) {
|
&& positionalArgs.get(i - offset).getRunnableArg() != null) {
|
||||||
positionalArgs.get(i - offset).getRunnableArg()
|
positionalArgs.get(i - offset).getRunnableArg().run(commandBlob);
|
||||||
.run(new CommandBlob(commandBlob));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Tools.invalidPermissions(event.getChannel(), command);
|
Tools.invalidPermissions(event.getChannel(), command);
|
||||||
|
@ -267,14 +231,7 @@ public class CommandManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.isNSFW() && !commandBlob.getChannel().isNSFW()) {
|
if (command.getPremiumLevel() > Users.getPremiumLevel(commandBlob.getAuthorID())) {
|
||||||
commandBlob.getChannel().sendMessage(
|
|
||||||
"Sorry, but you cannot run this command here, maybe try somewhere more private?")
|
|
||||||
.queue();
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.getPremiumLevel() > Users.getPremiumLevel(commandBlob.getUserID())) {
|
|
||||||
commandBlob.getChannel().sendMessage(
|
commandBlob.getChannel().sendMessage(
|
||||||
"Sorry, but you cannot run this command, it is premium subs only, of at least tier "
|
"Sorry, but you cannot run this command, it is premium subs only, of at least tier "
|
||||||
+ command.getPremiumLevel())
|
+ command.getPremiumLevel())
|
||||||
|
@ -284,223 +241,23 @@ public class CommandManager {
|
||||||
|
|
||||||
commandBlob.setCommandManager(this);
|
commandBlob.setCommandManager(this);
|
||||||
|
|
||||||
if (remainsValid) {
|
if (event.isFromGuild()) {
|
||||||
command.runDirectCommand(commandBlob, argumentList);
|
if (command.isNSFW() && !((TextChannel) commandBlob.getChannel()).isNSFW()) {
|
||||||
}
|
|
||||||
|
|
||||||
if (printTime) {
|
|
||||||
event.getChannel()
|
|
||||||
.sendMessage("Time to run: " + (System.currentTimeMillis() - commandStartTime) + "ms")
|
|
||||||
.queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (Boot.isProd) {
|
|
||||||
event.getChannel().sendMessage("```properties\n" + e + "```").queue();
|
|
||||||
} else {
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
|
||||||
e.printStackTrace(pw);
|
|
||||||
event.getChannel().sendMessage("```properties\n" + sw.toString() + "```").queue();
|
|
||||||
System.err.println("Exception caught in: " + e.toString());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
|
|
||||||
if (Boot.isProd) {
|
|
||||||
event.getChannel().sendMessage("```mathematica\n" + t + "```").queue();
|
|
||||||
} else {
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
|
||||||
t.printStackTrace(pw);
|
|
||||||
event.getChannel().sendMessage("```mathematica\n" + sw.toString() + "```").queue();
|
|
||||||
System.err.println("Error caught in: " + t.toString());
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startGuildCommand(GuildMessageReceivedEvent event) {
|
|
||||||
|
|
||||||
final String message = event.getMessage().getContentRaw();
|
|
||||||
String prefix = DatabaseTools.Tools.Guild.Prefix.getPrefix(event.getGuild().getIdLong());
|
|
||||||
String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
if (guildCommandMap.containsKey(command)) {
|
|
||||||
final List<String> args = Arrays.asList(split).subList(1, split.length);
|
|
||||||
|
|
||||||
executor.execute(() -> {
|
|
||||||
long commandStartTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// ArrayList<String> newArguments = new ArrayList<String>();
|
|
||||||
// ArrayList<String> commandFlags = new ArrayList<String>();
|
|
||||||
|
|
||||||
GuildCommandBlob commandBlob = new GuildCommandBlob(event);
|
|
||||||
GuildCommandInterface guildCommand = guildCommandMap.get(command);
|
|
||||||
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
|
||||||
|
|
||||||
boolean printTime = false;
|
|
||||||
byte argSkipCount = 0;
|
|
||||||
boolean remainsValid = true;
|
|
||||||
|
|
||||||
HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
|
|
||||||
|
|
||||||
if (guildCommand.getArguments() != null) {
|
|
||||||
for (Argument i : guildCommand.getArguments().values()) {
|
|
||||||
if (i.getPosition() >= 0) {
|
|
||||||
positionalArgs.put(i.getPosition(), i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> newArgs = new ArrayList<String>();
|
|
||||||
|
|
||||||
int offset = 0;
|
|
||||||
for (int i = 0; i < args.size(); i++) {
|
|
||||||
String x = args.get(i);
|
|
||||||
x = x.toLowerCase();
|
|
||||||
switch (x) {
|
|
||||||
case "\\time":
|
|
||||||
printTime = true;
|
|
||||||
break;
|
|
||||||
case "\\perm":
|
|
||||||
commandBlob.setUserID(380045419381784576L);
|
|
||||||
break;
|
|
||||||
case "\\del":
|
|
||||||
event.getMessage().delete().queue();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
newArgs.add(x);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// split up so global commands are actually global, and will not be affected by
|
|
||||||
// neighboring local args
|
|
||||||
for (int i = 0; i < newArgs.size(); i++) {
|
|
||||||
String x = newArgs.get(i);
|
|
||||||
x = x.toLowerCase();
|
|
||||||
if (argSkipCount <= 0) {
|
|
||||||
if (guildCommand.getArguments() != null) {
|
|
||||||
|
|
||||||
if (x.startsWith(Argument.argumentPrefix)) {
|
|
||||||
|
|
||||||
String pre = x.substring(Argument.argumentPrefix.length());
|
|
||||||
if (guildCommand.getArguments().keySet().contains(pre)) {
|
|
||||||
offset++;
|
|
||||||
if (guildCommand.getArguments().get(pre).getPermission() == null
|
|
||||||
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|
||||||
guildCommand.getArguments().get(pre).getPermission())) {
|
|
||||||
if (guildCommand.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
argumentList.put(pre, guildCommand.getArguments().get(pre));
|
|
||||||
if (guildCommand.getArguments().get(pre).isAutoStartRunnable()
|
|
||||||
&& guildCommand.getArguments().get(pre).getRunnableArg() != null) {
|
|
||||||
guildCommand.getArguments().get(pre).getRunnableArg()
|
|
||||||
.run(new CommandBlob(commandBlob));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Tools.invalidPermissions(event.getChannel(), guildCommand);
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Tools.wrongUsage(event.getChannel(), guildCommand);
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guildCommand.getArguments().get(x) != null) {
|
|
||||||
if (guildCommand.getArguments().get(x).getPermission() == null
|
|
||||||
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|
||||||
guildCommand.getArguments().get(x).getPermission())) {
|
|
||||||
if (guildCommand.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
argumentList.put(x, guildCommand.getArguments().get(x));
|
|
||||||
offset++;
|
|
||||||
if (guildCommand.getArguments().get(x).isAutoStartRunnable()
|
|
||||||
&& guildCommand.getArguments().get(x).getRunnableArg() != null) {
|
|
||||||
guildCommand.getArguments().get(x).getRunnableArg()
|
|
||||||
.run(new CommandBlob(commandBlob));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Tools.invalidPermissions(event.getChannel(), guildCommand);
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (positionalArgs.get(i - offset) != null) {
|
|
||||||
if (positionalArgs.get(i - offset).getPermission() == null
|
|
||||||
|| DatabaseTools.Tools.Developers.hasPermission(
|
|
||||||
commandBlob.getUserID(),
|
|
||||||
positionalArgs.get(i - offset).getPermission())) {
|
|
||||||
if (positionalArgs.get(i - offset).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
if (positionalArgs.get(i - offset).getIsWildcard()) {
|
|
||||||
argumentList.put(positionalArgs.get(i - offset).getArgName(),
|
|
||||||
positionalArgs.get(i - offset).setWildCardString(x));
|
|
||||||
} else {
|
|
||||||
Tools.wrongUsage(event.getChannel(), guildCommand);
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
if (positionalArgs.get(i - offset).isAutoStartRunnable()
|
|
||||||
&& positionalArgs.get(i - offset).getRunnableArg() != null) {
|
|
||||||
positionalArgs.get(i - offset).getRunnableArg()
|
|
||||||
.run(new CommandBlob(commandBlob));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Tools.invalidPermissions(event.getChannel(), guildCommand);
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
event.getChannel().sendMessage("pos is null").queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Tools.wrongUsage(event.getChannel(), guildCommand);
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (guildCommand.isNSFW() && !commandBlob.getChannel().isNSFW()) {
|
|
||||||
commandBlob.getChannel().sendMessage(
|
commandBlob.getChannel().sendMessage(
|
||||||
"Sorry, but you cannot run this command here, maybe try somewhere more private?")
|
"Sorry, but you cannot run this command here, maybe try somewhere more private?")
|
||||||
.queue();
|
.queue();
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guildCommand.getPremiumLevel() > Users.getPremiumLevel(commandBlob.getUserID())) {
|
|
||||||
commandBlob.getChannel().sendMessage(
|
|
||||||
"Sorry, but you cannot run this command, it is premium subs only, of at least tier "
|
|
||||||
+ guildCommand.getPremiumLevel())
|
|
||||||
.queue();
|
|
||||||
remainsValid = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commandBlob.setCommandManager(this);
|
|
||||||
|
|
||||||
if (remainsValid) {
|
if (remainsValid) {
|
||||||
guildCommand.runGuildCommand(commandBlob, argumentList);
|
if (command instanceof DualCommandInterface) {
|
||||||
|
((DualCommandInterface) command).runDualCommand(commandBlob, argumentList);
|
||||||
|
} else if (command instanceof GuildCommandInterface && event.isFromGuild()) {
|
||||||
|
((GuildCommandInterface) command).runGuildCommand(commandBlob, argumentList);
|
||||||
|
} else if (command instanceof PrivateCommandInterface && !event.isFromGuild()) {
|
||||||
|
((PrivateCommandInterface) command).runDirectCommand(commandBlob, argumentList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printTime) {
|
if (printTime) {
|
||||||
|
@ -536,5 +293,4 @@ public class CommandManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
package pkg.deepCurse.nopalmo.manager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
|
||||||
|
|
||||||
public class DirectCommandBlob {
|
|
||||||
|
|
||||||
private CommandManager commandManager = null;
|
|
||||||
private ArrayList<String> args = null;
|
|
||||||
private PrivateMessageReceivedEvent event = null;
|
|
||||||
private JDA bot = null;
|
|
||||||
|
|
||||||
private long userID = 0;
|
|
||||||
private long channelID = 0;
|
|
||||||
|
|
||||||
public DirectCommandBlob(PrivateMessageReceivedEvent event) {
|
|
||||||
setUserID(event.getAuthor().getIdLong());
|
|
||||||
setChannelID(event.getChannel().getIdLong());
|
|
||||||
this.event = event;
|
|
||||||
this.bot = event.getJDA();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getArgs() {
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextChannel getChannel() {
|
|
||||||
TextChannel textChannel = bot.getTextChannelById(channelID);
|
|
||||||
if (textChannel != null) {
|
|
||||||
return textChannel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirectCommandBlob setArgs(ArrayList<String> newArguments) {
|
|
||||||
this.args = newArguments;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirectCommandBlob setUserID(long userID) {
|
|
||||||
this.userID = userID;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getUserID() {
|
|
||||||
return this.userID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandManager getCommandManager() {
|
|
||||||
return commandManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommandManager(CommandManager commandManager) {
|
|
||||||
this.commandManager = commandManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getChannelID() {
|
|
||||||
return channelID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChannelID(long channelID) {
|
|
||||||
this.channelID = channelID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrivateMessageReceivedEvent getEvent() {
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEvent(PrivateMessageReceivedEvent event) {
|
|
||||||
this.event = event;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,261 +0,0 @@
|
||||||
package pkg.deepCurse.nopalmo.manager;
|
|
||||||
|
|
||||||
public class DirectCommandManager {
|
|
||||||
//
|
|
||||||
// private final Map<String, DirectCommandInterface> directCommandMap = new HashMap<>();
|
|
||||||
// private static Executor executor = null;
|
|
||||||
//
|
|
||||||
// public DirectCommandManager() {
|
|
||||||
// init();
|
|
||||||
// executor = Executors.newCachedThreadPool();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void init() {
|
|
||||||
//
|
|
||||||
// for (CommandInterface i : Boot.guildCommandManager.getGuildCommands()) {
|
|
||||||
//
|
|
||||||
// if (i instanceof DualCommandInterface) {
|
|
||||||
// addDirectCommand((DualCommandInterface) i);
|
|
||||||
// } else if (i instanceof DirectCommandInterface) {
|
|
||||||
// addDirectCommand((DirectCommandInterface) i);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void addDirectCommand(DirectCommandInterface c) {
|
|
||||||
// if (!directCommandMap.containsKey(c.getCommandName())) {
|
|
||||||
// directCommandMap.put(c.getCommandName(), c);
|
|
||||||
// } else {
|
|
||||||
// directCommandMap.remove(c.getCommandName());
|
|
||||||
// directCommandMap.put(c.getCommandName(), c);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Collection<DirectCommandInterface> getDirectCommands() {
|
|
||||||
// return directCommandMap.values();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public DirectCommandInterface getDirectCommand(String commandName) {
|
|
||||||
// if (commandName != null) {
|
|
||||||
// return directCommandMap.get(commandName);
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void startCommand(MessageReceivedEvent directMessageEvent) {
|
|
||||||
//
|
|
||||||
// final String message = directMessageEvent.getMessage().getContentRaw();
|
|
||||||
// String prefix = Global.prefix;
|
|
||||||
// String pingPrefix = "<@!" + directMessageEvent.getJDA().getSelfUser().getIdLong() + ">";
|
|
||||||
//
|
|
||||||
// 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();
|
|
||||||
//
|
|
||||||
// if (directCommandMap.containsKey(command)) {
|
|
||||||
// final List<String> args = Arrays.asList(split).subList(1, split.length);
|
|
||||||
//
|
|
||||||
// executor.execute(() -> {
|
|
||||||
// long commandStartTime = System.currentTimeMillis();
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// // ArrayList<String> newArguments = new ArrayList<String>();
|
|
||||||
// // ArrayList<String> commandFlags = new ArrayList<String>();
|
|
||||||
//
|
|
||||||
// DirectCommandBlob commandBlob = new DirectCommandBlob(directMessageEvent);
|
|
||||||
// DirectCommandInterface guildCommand = directCommandMap.get(command);
|
|
||||||
// HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
|
||||||
//
|
|
||||||
// boolean printTime = false;
|
|
||||||
// byte argSkipCount = 0;
|
|
||||||
// boolean remainsValid = true;
|
|
||||||
//
|
|
||||||
// HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
|
|
||||||
//
|
|
||||||
// if (guildCommand.getArguments() != null) {
|
|
||||||
// for (Argument i : guildCommand.getArguments().values()) {
|
|
||||||
// if (i.getPosition() >= 0) {
|
|
||||||
// positionalArgs.put(i.getPosition(), i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// List<String> newArgs = new ArrayList<String>();
|
|
||||||
//
|
|
||||||
// int offset = 0;
|
|
||||||
// for (int i = 0; i < args.size(); i++) {
|
|
||||||
// String x = args.get(i);
|
|
||||||
// x = x.toLowerCase();
|
|
||||||
// switch (x) {
|
|
||||||
// case "\\time":
|
|
||||||
// printTime = true;
|
|
||||||
// break;
|
|
||||||
// case "\\perm":
|
|
||||||
// commandBlob.setUserID(380045419381784576L);
|
|
||||||
// break;
|
|
||||||
// case "\\del":
|
|
||||||
// directMessageEvent.getMessage().delete().queue();
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// newArgs.add(x);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // split up so global commands are actually global, and will not be affected by
|
|
||||||
// // neighboring local args
|
|
||||||
// for (int i = 0; i < newArgs.size(); i++) {
|
|
||||||
// String x = newArgs.get(i);
|
|
||||||
// x = x.toLowerCase();
|
|
||||||
// if (argSkipCount <= 0) {
|
|
||||||
// if (guildCommand.getArguments() != null) {
|
|
||||||
//
|
|
||||||
// if (x.startsWith(Argument.argumentPrefix)) {
|
|
||||||
//
|
|
||||||
// String pre = x.substring(Argument.argumentPrefix.length());
|
|
||||||
// if (guildCommand.getArguments().keySet().contains(pre)) {
|
|
||||||
// offset++;
|
|
||||||
// if (guildCommand.getArguments().get(pre).getPermission() == null
|
|
||||||
// || DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|
||||||
// guildCommand.getArguments().get(pre).getPermission())) {
|
|
||||||
// if (guildCommand.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// argumentList.put(pre, guildCommand.getArguments().get(pre));
|
|
||||||
// if (guildCommand.getArguments().get(pre).isAutoStartRunnable()
|
|
||||||
// && guildCommand.getArguments().get(pre).getRunnableArg() != null) {
|
|
||||||
// guildCommand.getArguments().get(pre).getRunnableArg()
|
|
||||||
// .run(new CommandBlob(commandBlob));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Tools.invalidPermissions(directMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// Tools.wrongUsage(directMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (guildCommand.getArguments().get(x) != null) {
|
|
||||||
// if (guildCommand.getArguments().get(x).getPermission() == null
|
|
||||||
// || DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|
||||||
// guildCommand.getArguments().get(x).getPermission())) {
|
|
||||||
// if (guildCommand.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// argumentList.put(x, guildCommand.getArguments().get(x));
|
|
||||||
// offset++;
|
|
||||||
// if (guildCommand.getArguments().get(x).isAutoStartRunnable()
|
|
||||||
// && guildCommand.getArguments().get(x).getRunnableArg() != null) {
|
|
||||||
// guildCommand.getArguments().get(x).getRunnableArg()
|
|
||||||
// .run(new CommandBlob(commandBlob));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Tools.invalidPermissions(directMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (positionalArgs.get(i - offset) != null) {
|
|
||||||
// if (positionalArgs.get(i - offset).getPermission() == null
|
|
||||||
// || DatabaseTools.Tools.Developers.hasPermission(
|
|
||||||
// commandBlob.getUserID(),
|
|
||||||
// positionalArgs.get(i - offset).getPermission())) {
|
|
||||||
// if (positionalArgs.get(i - offset).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// if (positionalArgs.get(i - offset).getIsWildcard()) {
|
|
||||||
// argumentList.put(positionalArgs.get(i - offset).getArgName(),
|
|
||||||
// positionalArgs.get(i - offset).setWildCardString(x));
|
|
||||||
// } else {
|
|
||||||
// Tools.wrongUsage(directMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// if (positionalArgs.get(i - offset).isAutoStartRunnable()
|
|
||||||
// && positionalArgs.get(i - offset).getRunnableArg() != null) {
|
|
||||||
// positionalArgs.get(i - offset).getRunnableArg()
|
|
||||||
// .run(new CommandBlob(commandBlob));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Tools.invalidPermissions(directMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// } else
|
|
||||||
// directMessageEvent.getChannel().sendMessage("pos is null").queue();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// Tools.wrongUsage(directMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (guildCommand.isNSFW() && !commandBlob.getChannel().isNSFW()) {
|
|
||||||
// commandBlob.getChannel().sendMessage(
|
|
||||||
// "Sorry, but you cannot run this command here, maybe try somewhere more private?")
|
|
||||||
// .queue();
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (guildCommand.getPremiumLevel() > Users.getPremiumLevel(commandBlob.getUserID())) {
|
|
||||||
// commandBlob.getChannel().sendMessage(
|
|
||||||
// "Sorry, but you cannot run this command, it is premium subs only, of at least tier "
|
|
||||||
// + guildCommand.getPremiumLevel())
|
|
||||||
// .queue();
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// commandBlob.setCommandManager(this);
|
|
||||||
//
|
|
||||||
// if (remainsValid) {
|
|
||||||
// guildCommand.runDirectCommand(commandBlob, argumentList);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (printTime) {
|
|
||||||
// directMessageEvent.getChannel()
|
|
||||||
// .sendMessage("Time to run: " + (System.currentTimeMillis() - commandStartTime) + "ms")
|
|
||||||
// .queue();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// if (Boot.isProd) {
|
|
||||||
// directMessageEvent.getChannel().sendMessage("```properties\n" + e + "```").queue();
|
|
||||||
// } else {
|
|
||||||
// StringWriter sw = new StringWriter();
|
|
||||||
// PrintWriter pw = new PrintWriter(sw);
|
|
||||||
// e.printStackTrace(pw);
|
|
||||||
// directMessageEvent.getChannel().sendMessage("```properties\n" + sw.toString() + "```").queue();
|
|
||||||
// System.err.println("Exception caught in: " + e.toString());
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// } catch (Throwable t) {
|
|
||||||
//
|
|
||||||
// if (Boot.isProd) {
|
|
||||||
// directMessageEvent.getChannel().sendMessage("```mathematica\n" + t + "```").queue();
|
|
||||||
// } else {
|
|
||||||
// StringWriter sw = new StringWriter();
|
|
||||||
// PrintWriter pw = new PrintWriter(sw);
|
|
||||||
// t.printStackTrace(pw);
|
|
||||||
// directMessageEvent.getChannel().sendMessage("```mathematica\n" + sw.toString() + "```").queue();
|
|
||||||
// System.err.println("Error caught in: " + t.toString());
|
|
||||||
// t.printStackTrace();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
package pkg.deepCurse.nopalmo.manager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
|
||||||
|
|
||||||
public class GuildCommandBlob {
|
|
||||||
|
|
||||||
private CommandManager commandManager = null;
|
|
||||||
private ArrayList<String> args = null;
|
|
||||||
private JDA bot = null;
|
|
||||||
|
|
||||||
private long userID = 0;
|
|
||||||
private long channelID = 0;
|
|
||||||
|
|
||||||
private GuildMessageReceivedEvent event = null;
|
|
||||||
|
|
||||||
public GuildCommandBlob(GuildMessageReceivedEvent event) {
|
|
||||||
this.event = event;
|
|
||||||
setUserID(event.getAuthor().getIdLong());
|
|
||||||
setChannelID(event.getChannel().getIdLong());
|
|
||||||
this.bot = event.getJDA();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getArgs() {
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuildCommandBlob setArgs(ArrayList<String> newArguments) {
|
|
||||||
this.args = newArguments;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextChannel getChannel() {
|
|
||||||
TextChannel textChannel = bot.getTextChannelById(channelID);
|
|
||||||
if (textChannel != null){
|
|
||||||
return textChannel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuildCommandBlob setUserID(long userID) {
|
|
||||||
this.userID = userID;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getUserID() {
|
|
||||||
return this.userID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandManager getCommandManager() {
|
|
||||||
return commandManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommandManager(CommandManager commandManager) {
|
|
||||||
this.commandManager = commandManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getChannelID() {
|
|
||||||
return channelID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChannelID(long channelID) {
|
|
||||||
this.channelID = channelID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuildMessageReceivedEvent getEvent() {
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,256 +0,0 @@
|
||||||
package pkg.deepCurse.nopalmo.manager;
|
|
||||||
|
|
||||||
public class GuildCommandManager extends CommandManager {
|
|
||||||
//
|
|
||||||
// private final Map<String, GuildCommandInterface> guildCommandMap = new HashMap<>();
|
|
||||||
// private static Executor executor = null;
|
|
||||||
//
|
|
||||||
// public GuildCommandManager() {
|
|
||||||
// init();
|
|
||||||
// executor = Executors.newWorkStealingPool();// newCachedThreadPool();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void init() {
|
|
||||||
// addCommand(new Help(this));
|
|
||||||
// addCommand(new Ping());
|
|
||||||
// addCommand(new Git());
|
|
||||||
// addCommand(new Prefix());
|
|
||||||
// addCommand(new Test());
|
|
||||||
// addCommand(new Info());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void addCommand(GuildCommandInterface c) {
|
|
||||||
// if (!guildCommandMap.containsKey(c.getCommandName())) {
|
|
||||||
// guildCommandMap.put(c.getCommandName(), c);
|
|
||||||
// } else {
|
|
||||||
// guildCommandMap.remove(c.getCommandName());
|
|
||||||
// guildCommandMap.put(c.getCommandName(), c);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Collection<GuildCommandInterface> getGuildCommands() {
|
|
||||||
// return guildCommandMap.values();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public GuildCommandInterface getDirectCommand(String commandName) {
|
|
||||||
// if (commandName != null) {
|
|
||||||
// return guildCommandMap.get(commandName);
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void startCommand(GuildMessageReceivedEvent guildMessageEvent) {
|
|
||||||
//
|
|
||||||
// final String message = guildMessageEvent.getMessage().getContentRaw();
|
|
||||||
// String prefix = DatabaseTools.Tools.Guild.Prefix.getPrefix(guildMessageEvent.getGuild().getIdLong());
|
|
||||||
// String pingPrefix = "<@!" + guildMessageEvent.getJDA().getSelfUser().getIdLong() + ">";
|
|
||||||
//
|
|
||||||
// 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();
|
|
||||||
//
|
|
||||||
// if (guildCommandMap.containsKey(command)) {
|
|
||||||
// final List<String> args = Arrays.asList(split).subList(1, split.length);
|
|
||||||
//
|
|
||||||
// executor.execute(() -> {
|
|
||||||
// long commandStartTime = System.currentTimeMillis();
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// // ArrayList<String> newArguments = new ArrayList<String>();
|
|
||||||
// // ArrayList<String> commandFlags = new ArrayList<String>();
|
|
||||||
//
|
|
||||||
// GuildCommandBlob commandBlob = new GuildCommandBlob(guildMessageEvent);
|
|
||||||
// GuildCommandInterface guildCommand = guildCommandMap.get(command);
|
|
||||||
// HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
|
||||||
//
|
|
||||||
// boolean printTime = false;
|
|
||||||
// byte argSkipCount = 0;
|
|
||||||
// boolean remainsValid = true;
|
|
||||||
//
|
|
||||||
// HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
|
|
||||||
//
|
|
||||||
// if (guildCommand.getArguments() != null) {
|
|
||||||
// for (Argument i : guildCommand.getArguments().values()) {
|
|
||||||
// if (i.getPosition() >= 0) {
|
|
||||||
// positionalArgs.put(i.getPosition(), i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// List<String> newArgs = new ArrayList<String>();
|
|
||||||
//
|
|
||||||
// int offset = 0;
|
|
||||||
// for (int i = 0; i < args.size(); i++) {
|
|
||||||
// String x = args.get(i);
|
|
||||||
// x = x.toLowerCase();
|
|
||||||
// switch (x) {
|
|
||||||
// case "\\time":
|
|
||||||
// printTime = true;
|
|
||||||
// break;
|
|
||||||
// case "\\perm":
|
|
||||||
// commandBlob.setUserID(380045419381784576L);
|
|
||||||
// break;
|
|
||||||
// case "\\del":
|
|
||||||
// guildMessageEvent.getMessage().delete().queue();
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// newArgs.add(x);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // split up so global commands are actually global, and will not be affected by
|
|
||||||
// // neighboring local args
|
|
||||||
// for (int i = 0; i < newArgs.size(); i++) {
|
|
||||||
// String x = newArgs.get(i);
|
|
||||||
// x = x.toLowerCase();
|
|
||||||
// if (argSkipCount <= 0) {
|
|
||||||
// if (guildCommand.getArguments() != null) {
|
|
||||||
//
|
|
||||||
// if (x.startsWith(Argument.argumentPrefix)) {
|
|
||||||
//
|
|
||||||
// String pre = x.substring(Argument.argumentPrefix.length());
|
|
||||||
// if (guildCommand.getArguments().keySet().contains(pre)) {
|
|
||||||
// offset++;
|
|
||||||
// if (guildCommand.getArguments().get(pre).getPermission() == null
|
|
||||||
// || DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|
||||||
// guildCommand.getArguments().get(pre).getPermission())) {
|
|
||||||
// if (guildCommand.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// argumentList.put(pre, guildCommand.getArguments().get(pre));
|
|
||||||
// if (guildCommand.getArguments().get(pre).isAutoStartRunnable()
|
|
||||||
// && guildCommand.getArguments().get(pre).getRunnableArg() != null) {
|
|
||||||
// guildCommand.getArguments().get(pre).getRunnableArg()
|
|
||||||
// .run(new CommandBlob(commandBlob));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Tools.invalidPermissions(guildMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (guildCommand.getArguments().get(x) != null) {
|
|
||||||
// if (guildCommand.getArguments().get(x).getPermission() == null
|
|
||||||
// || DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
|
||||||
// guildCommand.getArguments().get(x).getPermission())) {
|
|
||||||
// if (guildCommand.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// argumentList.put(x, guildCommand.getArguments().get(x));
|
|
||||||
// offset++;
|
|
||||||
// if (guildCommand.getArguments().get(x).isAutoStartRunnable()
|
|
||||||
// && guildCommand.getArguments().get(x).getRunnableArg() != null) {
|
|
||||||
// guildCommand.getArguments().get(x).getRunnableArg()
|
|
||||||
// .run(new CommandBlob(commandBlob));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Tools.invalidPermissions(guildMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (positionalArgs.get(i - offset) != null) {
|
|
||||||
// if (positionalArgs.get(i - offset).getPermission() == null
|
|
||||||
// || DatabaseTools.Tools.Developers.hasPermission(
|
|
||||||
// commandBlob.getUserID(),
|
|
||||||
// positionalArgs.get(i - offset).getPermission())) {
|
|
||||||
// if (positionalArgs.get(i - offset).isSkipOriginalTaskOnRunnable()) {
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// if (positionalArgs.get(i - offset).getIsWildcard()) {
|
|
||||||
// argumentList.put(positionalArgs.get(i - offset).getArgName(),
|
|
||||||
// positionalArgs.get(i - offset).setWildCardString(x));
|
|
||||||
// } else {
|
|
||||||
// Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// if (positionalArgs.get(i - offset).isAutoStartRunnable()
|
|
||||||
// && positionalArgs.get(i - offset).getRunnableArg() != null) {
|
|
||||||
// positionalArgs.get(i - offset).getRunnableArg()
|
|
||||||
// .run(new CommandBlob(commandBlob));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Tools.invalidPermissions(guildMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// } else
|
|
||||||
// guildMessageEvent.getChannel().sendMessage("pos is null").queue();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// Tools.wrongUsage(guildMessageEvent.getChannel(), guildCommand);
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (guildCommand.isNSFW() && !commandBlob.getChannel().isNSFW()) {
|
|
||||||
// commandBlob.getChannel().sendMessage(
|
|
||||||
// "Sorry, but you cannot run this command here, maybe try somewhere more private?")
|
|
||||||
// .queue();
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (guildCommand.getPremiumLevel() > Users.getPremiumLevel(commandBlob.getUserID())) {
|
|
||||||
// commandBlob.getChannel().sendMessage(
|
|
||||||
// "Sorry, but you cannot run this command, it is premium subs only, of at least tier "
|
|
||||||
// + guildCommand.getPremiumLevel())
|
|
||||||
// .queue();
|
|
||||||
// remainsValid = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// commandBlob.setCommandManager(this);
|
|
||||||
//
|
|
||||||
// if (remainsValid) {
|
|
||||||
// guildCommand.runGuildCommand(commandBlob, argumentList);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (printTime) {
|
|
||||||
// guildMessageEvent.getChannel()
|
|
||||||
// .sendMessage("Time to run: " + (System.currentTimeMillis() - commandStartTime) + "ms")
|
|
||||||
// .queue();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// if (Boot.isProd) {
|
|
||||||
// guildMessageEvent.getChannel().sendMessage("```properties\n" + e + "```").queue();
|
|
||||||
// } else {
|
|
||||||
// StringWriter sw = new StringWriter();
|
|
||||||
// PrintWriter pw = new PrintWriter(sw);
|
|
||||||
// e.printStackTrace(pw);
|
|
||||||
// guildMessageEvent.getChannel().sendMessage("```properties\n" + sw.toString() + "```").queue();
|
|
||||||
// System.err.println("Exception caught in: " + e.toString());
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// } catch (Throwable t) {
|
|
||||||
//
|
|
||||||
// if (Boot.isProd) {
|
|
||||||
// guildMessageEvent.getChannel().sendMessage("```mathematica\n" + t + "```").queue();
|
|
||||||
// } else {
|
|
||||||
// StringWriter sw = new StringWriter();
|
|
||||||
// PrintWriter pw = new PrintWriter(sw);
|
|
||||||
// t.printStackTrace(pw);
|
|
||||||
// guildMessageEvent.getChannel().sendMessage("```mathematica\n" + sw.toString() + "```").queue();
|
|
||||||
// System.err.println("Error caught in: " + t.toString());
|
|
||||||
// t.printStackTrace();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue