Compare commits
10 commits
3cd8f3404c
...
c26e74066b
Author | SHA1 | Date | |
---|---|---|---|
c26e74066b | |||
4d3c17e054 | |||
35e9b0082f | |||
3669fc617e | |||
|
4be32e2d91 | ||
1f32a0fa23 | |||
bf1d67fb48 | |||
2b59133f15 | |||
749bd590bc | |||
b64a3639f3 |
48 changed files with 2173 additions and 2048 deletions
11
.classpath
11
.classpath
|
@ -6,9 +6,12 @@
|
|||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/libs/db/mysql-connector-java-8.0.27.jar" sourcepath="/libs/db/mysql-connector-java-8.0.27-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-simple-1.7.9.jar" sourcepath="/libs/logging/slf4j-simple-1.7.9-sources.jar"/>
|
||||
<classpathentry kind="lib" path="/libs-java/db/mysql-connector-java-8.0.27.jar"/>
|
||||
<classpathentry kind="lib" path="/libs-java/db/fluent-jdbc-0.2.3.jar"/>
|
||||
<classpathentry kind="lib" path="/libs-java/discord/JDA-4.4.0_350-withDependencies.jar"/>
|
||||
<classpathentry kind="lib" path="/libs-java/logging/slf4j-api-1.7.9.jar"/>
|
||||
<classpathentry kind="lib" path="/libs-java/logging/slf4j-simple-1.7.9.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/libs-java"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/classreloading"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
/bin/
|
||||
/nopalmo.lock
|
||||
/.classpath
|
||||
/.project
|
||||
/chaos.lock
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# nopalmo
|
||||
|
||||
A reboot of a private project of mine
|
||||
|
||||
[discord server](discord.gg/Zvxg9gsx3Y)
|
||||
|
|
12
TODO.txt
12
TODO.txt
|
@ -1,4 +1,10 @@
|
|||
mix command managers
|
||||
// DONE mix command managers
|
||||
finish loop
|
||||
add socket server for better management / integration
|
||||
implement pheonix in a smarter way than last time
|
||||
// DONE add socket server for better management / integration
|
||||
// DONE implement pheonix in a smarter way than last time
|
||||
add better security to the socket server
|
||||
add argument alias usage support
|
||||
add on join actions and configs
|
||||
// DONE clean up database accessor for a more modular setup
|
||||
|
||||
|
||||
|
|
1
compile-external-sources.sh
Executable file
1
compile-external-sources.sh
Executable file
|
@ -0,0 +1 @@
|
|||
javac $(find ./* | grep .java); echo Done!
|
|
@ -1,4 +1,8 @@
|
|||
3 : Failed to lock
|
||||
4 : Failed to connect to maria
|
||||
7 : Shut down by developer
|
||||
8 : LoggerHelper.crash(Exception e);
|
||||
|
||||
|
||||
Failed to lock
|
||||
Failed to connect to maria
|
||||
|
||||
|
||||
Shut down by developer
|
||||
LoggerHelper.crash(Exception e);
|
BIN
external-src/testing/Testing.class
Normal file
BIN
external-src/testing/Testing.class
Normal file
Binary file not shown.
7
external-src/testing/Testing.java
Normal file
7
external-src/testing/Testing.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package testing;
|
||||
|
||||
public class Testing {
|
||||
|
||||
public static String string = "deawuidhaw";
|
||||
|
||||
}
|
|
@ -5,11 +5,9 @@ import java.util.HashMap;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
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?
|
||||
|
||||
|
@ -38,19 +36,35 @@ public interface CommandInterface { // TODO rewrite to implement type args?
|
|||
public String getHelp();
|
||||
|
||||
public default String getUsage(boolean hasPermissionInfo) {
|
||||
|
||||
StringBuilder sB = new StringBuilder();
|
||||
for (Argument i : getArguments().values()) {
|
||||
if (!i.isDeveloper() || (hasPermissionInfo && i.isDeveloper())) {
|
||||
sB.append(i.isRequired() ? "<" : "[");
|
||||
if (i.getPrefixRequirement()) {
|
||||
sB.append(Argument.argumentPrefix);
|
||||
}
|
||||
sB.append(i.getArgName() + (i.isRequired() ? "> " : "] "));
|
||||
if (getArguments() != null) {
|
||||
for (Argument i : getArguments().values()) {
|
||||
if ((i.isDeveloper() && hasPermissionInfo) || !i.isDeveloper()) {
|
||||
if (i.isRequired()) {
|
||||
sB.append("<");
|
||||
} else {
|
||||
sB.append("[");
|
||||
}
|
||||
|
||||
sB.append((i.isPrefixRequired() ? Argument.argumentPrefix : "") + i.getArgName());
|
||||
|
||||
if (i.getAliases() != null) {
|
||||
for (String j : i.getAliases()) {
|
||||
sB.append(" | " + (i.isPrefixRequired() ? Argument.argumentPrefix : "") + j);
|
||||
}
|
||||
}
|
||||
|
||||
if (i.isRequired()) {
|
||||
sB.append("> ");
|
||||
} else {
|
||||
sB.append("] ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return GlobalDB.prefix + getCommandName() + " " + sB.toString().trim();
|
||||
}
|
||||
|
||||
return (Global.prefix + getCommandName() + " " + sB.toString()).strip();
|
||||
return GlobalDB.prefix + getCommandName();
|
||||
}
|
||||
|
||||
public default int getTimeout() {
|
||||
|
@ -60,29 +74,28 @@ public interface CommandInterface { // TODO rewrite to implement type args?
|
|||
@Nullable
|
||||
public HashMap<String, Argument> getArguments();
|
||||
|
||||
public interface DualCommandInterface extends DirectCommandInterface, GuildCommandInterface {
|
||||
public interface DualCommandInterface extends PrivateCommandInterface, GuildCommandInterface {
|
||||
@Override
|
||||
public default void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentMap)
|
||||
throws Exception {
|
||||
runDualCommand(new CommandBlob(blob), argumentMap);
|
||||
public default void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
runDualCommand(blob, argumentMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentMap)
|
||||
public default void runPrivateCommand(CommandBlob blob, HashMap<String, Argument> argumentMap)
|
||||
throws Exception {
|
||||
runDualCommand(new CommandBlob(blob), argumentMap);
|
||||
runDualCommand(blob, argumentMap);
|
||||
}
|
||||
|
||||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
public interface DirectCommandInterface extends CommandInterface {
|
||||
public void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception;
|
||||
public interface PrivateCommandInterface extends CommandInterface {
|
||||
public void runPrivateCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception;
|
||||
}
|
||||
|
||||
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() {
|
||||
return null;
|
||||
|
@ -93,4 +106,4 @@ public interface CommandInterface { // TODO rewrite to implement type args?
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
45
src/pkg/deepCurse/nopalmo/command/commands/fun/Stupid.java
Normal file
45
src/pkg/deepCurse/nopalmo/command/commands/fun/Stupid.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package pkg.deepCurse.nopalmo.command.commands.fun;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class Stupid implements GuildCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] { "stupid", "dumb" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.Fun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "This calls someone stupid, stupid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HashMap<String, Argument> getArguments() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
StringBuilder sB = new StringBuilder();
|
||||
for (Member i : blob.getMessage().getMentionedMembers()) {
|
||||
sB.append(i.getAsMention() + " ");
|
||||
}
|
||||
blob.getMessage().delete().queue();
|
||||
blob.getChannel().sendMessage(blob.getAuthor().getName() + " calls you stupid! " + sB.toString()).queue();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package pkg.deepCurse.nopalmo.command.commands.general;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class Example implements DualCommandInterface{
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] {"owo"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.General;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "an example command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
blob.getChannel().sendMessage("owo").queue();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Argument> getArguments() {
|
||||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
|
||||
args.put("k", new Argument("k", (CommandBlob blob) -> {
|
||||
blob.getChannel().sendMessage("Dr. K").queue();
|
||||
}).setPrefixRequirement(true).setAutoStartRunnable(true));
|
||||
|
||||
return args;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,11 +3,11 @@ 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.database.DatabaseTools.Tools.Users;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GuildDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.UserDB;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class Prefix implements GuildCommandInterface {
|
||||
|
||||
|
@ -22,17 +22,24 @@ public class Prefix implements GuildCommandInterface {
|
|||
}
|
||||
|
||||
@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) {
|
||||
Guild.Prefix.setPrefix(
|
||||
blob.getEvent().getGuild().getIdLong(), argumentList.get("prefix").getWildCardString());
|
||||
blob.getEvent().getChannel().sendMessage("Set prefix to " + argumentList.get("prefix").getWildCardString()).queue();
|
||||
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();
|
||||
GuildDB.setPrefix(blob.getGuildID(), argumentList.get("prefix").getWildCardString());
|
||||
blob.getChannel().sendMessage("Set prefix to " + argumentList.get("prefix").getWildCardString()).queue();
|
||||
if (!UserDB.isAdvancedUser(blob.getAuthorID()))
|
||||
blob.getChannel()
|
||||
.sendMessage(
|
||||
"Remember: you can always ping me to use any command in case you forget the prefix")
|
||||
.queue();
|
||||
|
||||
// if () {
|
||||
//
|
||||
// }
|
||||
|
||||
} else {
|
||||
Guild.Prefix.setPrefix(
|
||||
blob.getEvent().getGuild().getIdLong(), Global.prefix);
|
||||
blob.getEvent().getChannel().sendMessage("Reset prefix to default").queue();
|
||||
GuildDB.setPrefix(blob.getGuildID(), GlobalDB.prefix);
|
||||
blob.getChannel().sendMessage("Reset prefix to default").queue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class Test implements GuildCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] {"test"};
|
||||
return new String[] { "test" };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,20 +24,20 @@ public class Test implements GuildCommandInterface {
|
|||
public String getHelp() {
|
||||
return "A command used to test various things";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getPremiumLevel() {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
blob.getEvent().getChannel().sendMessage("Tested").queue();
|
||||
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
blob.getChannel().sendMessage("Tested").queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,9 +28,12 @@ public class Git implements DualCommandInterface {
|
|||
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();
|
||||
|
||||
|
||||
blob.getChannel()
|
||||
.sendMessage("This is the automatically running argument inside of " + this.getCommandName())
|
||||
.queue();
|
||||
// blob.getCommandManager().init();
|
||||
|
||||
}).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true));
|
||||
|
||||
return args;
|
||||
|
@ -40,5 +43,5 @@ public class Git implements DualCommandInterface {
|
|||
public String getHelp() {
|
||||
return "Posts my github link";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,105 +6,141 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
|
||||
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.GuildCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandManager;
|
||||
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
|
||||
|
||||
public class Help implements GuildCommandInterface {
|
||||
|
||||
public final CommandManager manager;
|
||||
|
||||
public static final List<HelpPage> deniedPages = new ArrayList<HelpPage>();
|
||||
|
||||
public Help(CommandManager m) {
|
||||
this.manager = m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
boolean isDevEnabled = argumentMap.get("dev") != null;
|
||||
|
||||
final List<HelpPage> deniedPages = new ArrayList<HelpPage>();
|
||||
deniedPages.add(HelpPage.DEV);
|
||||
deniedPages.add(HelpPage.EGG);
|
||||
deniedPages.add(HelpPage.TESTING);
|
||||
}
|
||||
|
||||
if (argumentMap.isEmpty() || (isDevEnabled && argumentMap.size() == 1)) {
|
||||
EmbedBuilder embed = new EmbedBuilder().setTitle(isDevEnabled ? "^Commands:" : "Commands:");
|
||||
@Override
|
||||
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
HashMap<HelpPage, List<String>> commandHash = new HashMap<HelpPage, List<String>>();
|
||||
// boolean blob.isDeveloper() = argumentMap.get("dev") != null;
|
||||
|
||||
for (GuildCommandInterface command : manager.getGuildCommands()) {
|
||||
List<String> commandNameList = commandHash.get(command.getHelpPage());
|
||||
if (commandNameList == null) {
|
||||
commandNameList = new ArrayList<String>();
|
||||
if (argumentMap.get("commandName") == null) {
|
||||
EmbedBuilder embed = new EmbedBuilder().setTitle(blob.isDeveloper() ? "^Commands:" : "Commands:");
|
||||
|
||||
}
|
||||
commandNameList.add(command.getCommandName());
|
||||
commandHash.put(command.getHelpPage(), commandNameList);
|
||||
}
|
||||
HashMap<HelpPage, ArrayList<String>> commandHash = new HashMap<HelpPage, ArrayList<String>>();
|
||||
|
||||
// TODO add command to log a string
|
||||
|
||||
for (HelpPage i : HelpPage.values()) {
|
||||
if (deniedPages.contains(i) && argumentMap.get("dev") == null) {
|
||||
ArrayList<String> commandNameList = commandHash.get(i);
|
||||
for (CommandInterface command : manager.getCommands()) {
|
||||
if (!(deniedPages.contains(i) && !blob.isDeveloper())) {
|
||||
if (command.getHelpPage() == i) {
|
||||
if (commandNameList == null) {
|
||||
commandNameList = new ArrayList<String>();
|
||||
}
|
||||
|
||||
} else if (commandHash.get(i) != null) {
|
||||
if (!commandNameList.contains(command.getCommandName())) {
|
||||
commandNameList.add(command.getCommandName());
|
||||
|
||||
commandHash.put(command.getHelpPage(), commandNameList);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
commandNameList = null;
|
||||
}
|
||||
|
||||
blob.getChannel().sendMessage(commandHash.toString()).queue();
|
||||
|
||||
for (HelpPage i : HelpPage.values()) {
|
||||
if (commandHash.get(i) != null) {
|
||||
StringBuilder sB = new StringBuilder();
|
||||
|
||||
int count = 0;
|
||||
for (String j : commandHash.get(i)) {
|
||||
if (++count > 3) {
|
||||
sB.append("\n");
|
||||
if (count >= 3) {
|
||||
count = 0;
|
||||
sB.append("\n");
|
||||
}
|
||||
count++;
|
||||
sB.append("`" + j + "` ");
|
||||
}
|
||||
|
||||
embed.addField(i.toString(), sB.toString(), true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// for () {
|
||||
//
|
||||
// }
|
||||
|
||||
// for (HelpPage i : HelpPage.values()) {
|
||||
// if (deniedPages.contains(i) && argumentMap.get("dev") == null) {
|
||||
//
|
||||
// } else if (commandHash.get(i) != null) {
|
||||
//
|
||||
// StringBuilder sB = new StringBuilder();
|
||||
//
|
||||
// int count = 0;
|
||||
// for (String j : commandHash.get(i)) {
|
||||
// if (++count > 3) {
|
||||
// count = 0;
|
||||
// sB.append("\n");
|
||||
// }
|
||||
// sB.append("`" + j + "` ");
|
||||
// }
|
||||
//
|
||||
// embed.addField(i.toString(), sB.toString(), true);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
StringBuilder sB = new StringBuilder();
|
||||
|
||||
CommandInterface ping = blob.getCommandManager().getDirectCommand("ping");
|
||||
CommandInterface ping = blob.getCommandManager().getCommand("ping");
|
||||
if (ping != null) {
|
||||
sB.append("`" + ping.getUsage(isDevEnabled) + "`\n");
|
||||
sB.append("`" + ping.getUsage(blob.isDeveloper()) + "`\n");
|
||||
}
|
||||
|
||||
CommandInterface info = blob.getCommandManager().getDirectCommand("info");
|
||||
CommandInterface info = blob.getCommandManager().getCommand("info");
|
||||
if (info != null) {
|
||||
sB.append("`" + info.getUsage(isDevEnabled) + "`\n");
|
||||
sB.append("`" + info.getUsage(blob.isDeveloper()) + "`\n");
|
||||
}
|
||||
|
||||
CommandInterface prefix = blob.getCommandManager().getDirectCommand("prefix");
|
||||
CommandInterface prefix = blob.getCommandManager().getCommand("prefix");
|
||||
if (prefix != null) {
|
||||
sB.append("`" + prefix.getUsage(isDevEnabled) + "`\n");
|
||||
sB.append("`" + prefix.getUsage(blob.isDeveloper()) + "`\n");
|
||||
}
|
||||
|
||||
embed.addField("Information:", "Commands to take note of:\n" + sB, false);
|
||||
|
||||
embed.setFooter(blob.getEvent().getMember().getEffectiveName(),
|
||||
blob.getEvent().getMember().getUser().getEffectiveAvatarUrl());
|
||||
embed.setFooter(blob.getMember().getEffectiveName(), blob.getAuthor().getEffectiveAvatarUrl());
|
||||
embed.setTimestamp(Instant.now());
|
||||
embed.setColor(Global.getEmbedColor());
|
||||
embed.setColor(Integer.parseInt(GlobalDB.getGlobalValue("embedcolor")));
|
||||
|
||||
blob.getChannel().sendMessageEmbeds(embed.build()).queue();
|
||||
|
||||
return;
|
||||
} 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()) && blob.isDeveloper())
|
||||
|| !deniedPages.contains(command.getHelpPage()))) {
|
||||
if (!(command.isNSFW() && !blob.getChannel().isNSFW())) {
|
||||
if (!blob.isFromGuild() ? true : !(command.isNSFW() && !((TextChannel) blob.getChannel()).isNSFW())) {
|
||||
EmbedBuilder eB = new EmbedBuilder();
|
||||
|
||||
eB.setColor(Global.getEmbedColor());
|
||||
eB.setColor(Integer.parseInt(GlobalDB.getGlobalValue("embedcolor")));
|
||||
StringBuilder sB = new StringBuilder();
|
||||
|
||||
eB.setTitle("Help results for: " + command.getCommandName());
|
||||
|
@ -114,14 +150,13 @@ public class Help implements GuildCommandInterface {
|
|||
eB.addField("Help info:", "This command does not contain help information", false);
|
||||
}
|
||||
|
||||
eB.addField("Usage:", "`" + command.getUsage(isDevEnabled) + "`", false);
|
||||
eB.addField("Usage:", "`" + command.getUsage(blob.isDeveloper()) + "`", false);
|
||||
|
||||
eB.addField("Page:", command.getHelpPage().toString(), true); // ("Page: " +
|
||||
// command.getHelpPage().toString());
|
||||
eB.setFooter(blob.getEvent().getMember().getEffectiveName(),
|
||||
blob.getEvent().getMember().getUser().getEffectiveAvatarUrl());
|
||||
eB.setFooter(blob.getMember().getEffectiveName(), blob.getAuthor().getEffectiveAvatarUrl());
|
||||
eB.setTimestamp(Instant.now());
|
||||
|
||||
|
||||
if (command.getCommandCalls().length > 1) {
|
||||
sB.append("Aliases: ");
|
||||
for (int i = 1; i < command.getCommandCalls().length; i++) {
|
||||
|
@ -134,9 +169,9 @@ public class Help implements GuildCommandInterface {
|
|||
sB.append("Is nsfw: " + command.isNSFW() + "\n");
|
||||
}
|
||||
|
||||
if (command.getRequiredPermission() != null) {
|
||||
sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
|
||||
}
|
||||
// if (command.getRequiredPermission() != null) {
|
||||
// sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
|
||||
// }
|
||||
|
||||
if (command.getTimeout() > 0) {
|
||||
sB.append("Usage Timeout: " + command.getTimeout() + "\n");
|
||||
|
@ -185,7 +220,8 @@ public class Help implements GuildCommandInterface {
|
|||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
|
||||
args.put("commandName", new Argument("commandName").setPosition(0).setIsWildcard(true));
|
||||
args.put("dev", new Argument("dev").setPrefixRequirement(true).setPermissionLevel("infopermission"));
|
||||
// args.put("dev", new Argument("dev").setPrefixRequirement(true).setPermissionLevel("infopermission")
|
||||
// .addAliases("d", "developer", "extra", "shit", "to", "test"));
|
||||
|
||||
return args;
|
||||
}
|
||||
|
|
|
@ -4,15 +4,13 @@ import java.util.HashMap;
|
|||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.DirectCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.PrivateCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.UserDB;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
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
|
||||
public String[] getCommandCalls() {
|
||||
|
@ -34,19 +32,25 @@ public class Info implements GuildCommandInterface, DirectCommandInterface {
|
|||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
|
||||
args.put("userdump", new Argument("userdump", (CommandBlob blob) -> {
|
||||
blob.getChannel().sendMessage(Users.dump(blob.getUserID())).queue();
|
||||
}).setPrefixRequirement(true).setAutoStartRunnable(true)
|
||||
.setSkipOriginalTaskOnRunnable(true));
|
||||
blob.getChannel()
|
||||
.sendMessage(
|
||||
!UserDB.generateDump(blob.getAuthorID()).isEmpty() ? UserDB.generateDump(blob.getAuthorID())
|
||||
: "Sorry, but this user does not exist in the database")
|
||||
.queue();
|
||||
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true).addAliases("u"));
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
public void runPrivateCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
blob.getChannel().sendMessage("EEE").queue();
|
||||
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
blob.getChannel().sendMessage(
|
||||
"This command is used to send data stored in the database to whoever is authorized to view it, to view your own data, use `"
|
||||
+ getCommandName() + " -userdump`")
|
||||
.queue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class Ping implements DualCommandInterface {
|
|||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
MessageChannel channel = blob.getChannel();
|
||||
|
||||
|
||||
if (argumentMap.isEmpty()) {
|
||||
channel.sendMessage("Pong!\n" + blob.getJDA().getGatewayPing() + "ms\n").queue();
|
||||
return;
|
||||
|
@ -43,7 +43,7 @@ public class Ping implements DualCommandInterface {
|
|||
+ (googlePing > 0 ? "Google: " + googlePing + "ms\n" : "Could not connect to www.google.com\n")
|
||||
+ (discordPing > 0 ? "Discord: " + discordPing + "ms\n"
|
||||
: "Could not connect to www.discord.com\n")
|
||||
+ "JDA-Discord heartbeat: "+jdaPing+"ms";
|
||||
+ "JDA-Discord heartbeat: " + jdaPing + "ms";
|
||||
|
||||
msg.editMessage(out + "\nTime to process: " + (System.currentTimeMillis() - timeToProcess) + "ms")
|
||||
.queue();
|
||||
|
|
40
src/pkg/deepCurse/nopalmo/command/commands/info/Reload.java
Normal file
40
src/pkg/deepCurse/nopalmo/command/commands/info/Reload.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package pkg.deepCurse.nopalmo.command.commands.info;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.core.Loader;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class Reload implements DualCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] { "reload", "r" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.DEV;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "you should not need help using this command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HashMap<String, Argument> getArguments() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
// blob.getChannel().sendMessage("Refreshing caches. . .").queue();
|
||||
|
||||
blob.getChannel().sendMessage(Loader.init()).queue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
//package pkg.deepCurse.nopalmo.command.commands.testing;
|
||||
//
|
||||
//import java.util.HashMap;
|
||||
//
|
||||
//import org.jetbrains.annotations.Nullable;
|
||||
//
|
||||
//import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
|
||||
//import pkg.deepCurse.nopalmo.core.Boot;
|
||||
//import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
//import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
//
|
||||
//public class BontebokInterpret implements DualCommandInterface {
|
||||
//
|
||||
// @Override
|
||||
// public String[] getCommandCalls() {
|
||||
// return new String[] { "bontebok", "interpret", "int", "bo" };
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public HelpPage getHelpPage() {
|
||||
// return HelpPage.TESTING;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getHelp() {
|
||||
// return "This command will interpret a string using the bontebok interpreter";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @Nullable HashMap<String, Argument> getArguments() {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
//
|
||||
// blob.getChannel().sendMessage("Interpreting. . .").queue();
|
||||
//
|
||||
// String returnValue = Boot.bontebokManager.getBontebokInterpreter()
|
||||
// .InterpretString(argumentMap.get("null").getWildCardString());
|
||||
//
|
||||
// switch (returnValue.substring(0, 1)) {
|
||||
// case "0":
|
||||
// blob.getChannel().sendMessage("Operation completed with return value 0").queue();
|
||||
// break;
|
||||
// case "1":
|
||||
// blob.getChannel().sendMessage("Operation failed with return value 1"
|
||||
// + (returnValue.substring(1).isBlank() ? "" : ": " + returnValue.substring(1))).queue();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,45 @@
|
|||
package pkg.deepCurse.nopalmo.command.commands.testing;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class GuildCommand implements GuildCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] { "guild" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.TESTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "an example guild command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
|
||||
blob.getChannel().sendMessage("Message sent via command").queue();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Argument> getArguments() {
|
||||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
|
||||
args.put("arg", new Argument("arg", (CommandBlob blob) -> {
|
||||
blob.getChannel().sendMessage("message sent via argument runnable").queue();
|
||||
}).setPrefixRequirement(true).setAutoStartRunnable(true));
|
||||
|
||||
return args;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package pkg.deepCurse.nopalmo.command.commands.testing;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.PrivateCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class PrivateCommand implements PrivateCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] { "private" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.TESTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "an example private command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runPrivateCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
blob.getChannel().sendMessage("Message sent via command").queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Argument> getArguments() {
|
||||
HashMap<String, Argument> args = new HashMap<String, Argument>();
|
||||
|
||||
args.put("arg", new Argument("arg", (CommandBlob blob) -> {
|
||||
blob.getChannel().sendMessage("message sent via argument runnable").queue();
|
||||
}).setPrefixRequirement(true).setAutoStartRunnable(true));
|
||||
|
||||
return args;
|
||||
|
||||
}
|
||||
|
||||
}
|
127
src/pkg/deepCurse/nopalmo/command/commands/testing/Purge.java
Normal file
127
src/pkg/deepCurse/nopalmo/command/commands/testing/Purge.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
package pkg.deepCurse.nopalmo.command.commands.testing;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
|
||||
public class Purge implements GuildCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] { "p" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.TESTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Purges the channel of messages using many useful arguments to control the mode";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HashMap<String, Argument> getArguments() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
|
||||
//
|
||||
// if (args.size() == 1) {
|
||||
// if (!blob.getMember().hasPermission(Permission.MESSAGE_MANAGE)) {
|
||||
// blob.getChannel().sendMessage("You don't have the **MESSAGE_MANAGE** permission!").queue();
|
||||
// return;
|
||||
// }
|
||||
// int num = 0;
|
||||
// try {
|
||||
// num = Integer.parseInt(args.get(0));
|
||||
// } catch (NumberFormatException nfe) {
|
||||
// throw new NumberFormatException("Enter a number dumbass");
|
||||
// }
|
||||
// blob.getMessage().delete().complete();
|
||||
// int currentNum = num / 100;
|
||||
// if (currentNum == 0) {
|
||||
// List<Message> msg = event.getChannel().getHistory().retrievePast(num).complete();
|
||||
// event.getChannel().purgeMessages(msg);
|
||||
// // event.getChannel().sendMessage("Successfully purged `" + num + "`
|
||||
// // messages.").queue();
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// for (int i = 0; i <= currentNum; i++) {
|
||||
// if (i == num) {
|
||||
// List<Message> msg = event.getChannel().getHistory().retrievePast(num).complete();
|
||||
// event.getChannel().purgeMessages(msg);
|
||||
// // event.getChannel().sendMessage("Successfully purged `" + num + "`
|
||||
// // messages.").queue();
|
||||
// } else {
|
||||
// List<Message> msg = event.getChannel().getHistory().retrievePast(100).complete();
|
||||
// event.getChannel().purgeMessages(msg);
|
||||
// num -= 100;
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// if (Main.mode == BotMode.DEV) {
|
||||
// StringWriter sw = new StringWriter();
|
||||
// PrintWriter pw = new PrintWriter(sw);
|
||||
// e.printStackTrace(pw);
|
||||
// event.getChannel().sendMessage("```\n" + sw.toString() + "```").queue();
|
||||
// System.out.println("Error caught in: " + e.toString());
|
||||
// e.printStackTrace();
|
||||
// } else {
|
||||
// event.getChannel().sendMessage("```\n" + e + "```").queue(); // sends limited message
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// } else if (args.size() == 2) {
|
||||
//
|
||||
// if (args.get(0).contentEquals("-id") | args.get(0).contentEquals("-i")) {
|
||||
// long msgID = Long.parseLong(args.get(1));
|
||||
// blob.getChannel().retrieveMessageById(msgID).complete();
|
||||
//
|
||||
// for (Message i : blob.getChannel().getIterableHistory()) {
|
||||
// if (i.getIdLong() == msgID) {
|
||||
// break;
|
||||
// } else {
|
||||
// i.delete().queue();
|
||||
// Thread.sleep(1000);
|
||||
// }
|
||||
// }
|
||||
// // i need a better way to get args, flags, and args of flags
|
||||
// } else if (args.get(0).contentEquals("-u") | args.get(0).contentEquals("-user")) {
|
||||
//
|
||||
// long userID = Long.parseLong(args.get(1).replaceAll("[^0-9]", ""));
|
||||
// if (blob.getJDA().getUserById(userID) == null) {
|
||||
// throw new NullPointerException("Null user id");
|
||||
// }
|
||||
//
|
||||
// for (Message i : blob.getChannel().getIterableHistory()) {
|
||||
// if (i.getAuthor().getIdLong() == userID) {
|
||||
// i.delete().complete();
|
||||
// Thread.sleep(1000);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// pkg.deepCurse.nopalmo.global.Tools.wrongUsage(blob.getChannel(), this);
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// pkg.deepCurse.nopalmo.global.Tools.wrongUsage(blob.getChannel(), this);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package pkg.deepCurse.nopalmo.command.testing;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.manager.Argument;
|
||||
import pkg.deepCurse.nopalmo.manager.ClassManager;
|
||||
import pkg.deepCurse.nopalmo.manager.ClassManager.InternalReloadable;
|
||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||
import qj.util.ReflectUtil;
|
||||
|
||||
public class LiveUpdateTestCommand implements InternalReloadable<String, String>, DualCommandInterface {
|
||||
|
||||
@Override
|
||||
public String[] getCommandCalls() {
|
||||
return new String[] { "test-update" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelpPage getHelpPage() {
|
||||
return HelpPage.TESTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Used to test the live updater";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||
File file = new File(System.getProperty("user.dir") + "/external-src/");
|
||||
ClassManager<String, InternalReloadable<String, String>> manager = new ClassManager<String, InternalReloadable<String, String>>();
|
||||
|
||||
manager.addFile("testing", "testing.Testing", file);
|
||||
|
||||
String string = (String) ReflectUtil.getField("string", manager.getClass("testing")).get(null);
|
||||
|
||||
blob.getChannel().sendMessage(string).queue();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HashMap<String, Argument> getArguments() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
package pkg.deepCurse.nopalmo.core;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.impl.SimpleLoggerFactory;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
|
@ -11,14 +15,10 @@ import net.dv8tion.jda.api.requests.GatewayIntent;
|
|||
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.global.Reactions;
|
||||
import pkg.deepCurse.nopalmo.listener.DirectMessageReceivedListener;
|
||||
import pkg.deepCurse.nopalmo.listener.GuildMessageReceivedListener;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.listener.MessageReceivedListener;
|
||||
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.utils.Locks;
|
||||
import pkg.deepCurse.nopalmo.utils.LogHelper;
|
||||
|
@ -26,70 +26,58 @@ import pkg.deepCurse.nopalmo.utils.LogHelper;
|
|||
public class Boot {
|
||||
|
||||
public static JDA bot; // TODO create sharding handler
|
||||
public static DatabaseTools databaseTools = null;
|
||||
// public static final GuildCommandManager guildCommandManager = new GuildCommandManager(); // move to master manager
|
||||
// public static final DirectCommandManager directCommandManager = new DirectCommandManager(); // move to master
|
||||
// // manager
|
||||
private static Logger logger = LoggerFactory.getLogger(Boot.class.getSimpleName());
|
||||
public static final CommandManager commandManager = new CommandManager();
|
||||
// public static BontebokManager bontebokManager = null;
|
||||
|
||||
public static boolean isProd = false;
|
||||
|
||||
public static final long pid = ProcessHandle.current().pid();
|
||||
public static boolean running = true;
|
||||
public static final CommandManager commandManager = new CommandManager();
|
||||
|
||||
public static void main(String[] args) {
|
||||
LogHelper.boot("Booting: <" + pid + ">");
|
||||
|
||||
new Thread(() -> {
|
||||
long count = 0;
|
||||
while (true) {
|
||||
if (count++ > 1000000000) {
|
||||
count = 0;
|
||||
System.out.println("owo");
|
||||
}
|
||||
}
|
||||
}, "owo");
|
||||
// TODO using join and a while last time + 15000 < current time, then kill and
|
||||
// proceed as a failure
|
||||
|
||||
LogHelper.boot("Testing Lock. . .");
|
||||
// settings.actions.put("phoenix-update-confirm", (PhoenixRuntime runtime) -> {
|
||||
// LogHelper.log("Received <phoenix-update-confirm>");
|
||||
// });
|
||||
|
||||
try {
|
||||
if (Locks.dirLock("nopalmo.lock")) {
|
||||
LogHelper.boot("Failed to lock. . .\nShutting down. . .");
|
||||
System.exit(3);
|
||||
} else {
|
||||
LogHelper.boot("Nopalmo is locked. . .");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogHelper.crash(e);
|
||||
}
|
||||
logger.info("Booting: <" + pid + ">");
|
||||
|
||||
long preBootTime = System.currentTimeMillis();
|
||||
|
||||
isProd = args[2].contentEquals("prod");
|
||||
|
||||
LogHelper.boot("Connecting to mariadb:nopalmo");
|
||||
logger.info("Locking System");
|
||||
|
||||
try {
|
||||
databaseTools = new DatabaseTools(args[1]);
|
||||
LogHelper.boot("Connected. . .");
|
||||
} catch (SQLException | ClassNotFoundException e1) {
|
||||
if (Locks.dirLock(isProd ? "nopalmo.lock" : "chaos.lock")) {
|
||||
logger.info("Is locked, shutting down. . .");
|
||||
System.exit(3);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
LogHelper.boot("Failed to connect\nShutting down. . .");
|
||||
System.exit(4);
|
||||
}
|
||||
|
||||
LogHelper.boot("Init reaction/emote list");
|
||||
Reactions.init();
|
||||
LogHelper.boot("Initialized reaction/emote list. . .");
|
||||
LogHelper.boot("Init commands list");
|
||||
commandManager.init();
|
||||
LogHelper.boot("Initialized commands list. . .");
|
||||
logger.info("System locked. . .");
|
||||
|
||||
try {
|
||||
// bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL)
|
||||
// .setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS)
|
||||
// .setActivity(Activity.watching("Loading users...")).setIdle(true)
|
||||
// .addEventListeners(new GuildMessageReceivedListener())
|
||||
// .addEventListeners(new DirectMessageReceivedListener()).build().awaitReady();
|
||||
logger.info("Connecting to mariadb:nopalmo");
|
||||
NopalmoDBTools.init(isProd ? "nopalmo" : "chaos", "nopalmo", args[1]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("Failed to connect\nShutting down. . .");
|
||||
System.exit(4);
|
||||
}
|
||||
logger.info("Connected. . .");
|
||||
|
||||
try {
|
||||
// bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL)
|
||||
// .setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS)
|
||||
// .setActivity(Activity.watching("Loading users...")).setIdle(true)
|
||||
// .addEventListeners(new GuildMessageReceivedListener())
|
||||
// .addEventListeners(new DirectMessageReceivedListener()).build().awaitReady();
|
||||
|
||||
bot = JDABuilder.createDefault(args[0])
|
||||
.setActivity(Activity.of(ActivityType.WATCHING, "the loading bar. . ."))
|
||||
|
@ -99,25 +87,17 @@ public class Boot {
|
|||
|
||||
.setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL)
|
||||
|
||||
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS,
|
||||
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.DIRECT_MESSAGES,
|
||||
GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MEMBERS,
|
||||
GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_MESSAGES)
|
||||
|
||||
GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS,
|
||||
GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS,
|
||||
.enableCache(CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES)
|
||||
|
||||
GatewayIntent.GUILD_MESSAGES // , GatewayIntent.GUILD_VOICE_STATES
|
||||
)
|
||||
|
||||
.enableCache(// CacheFlag.CLIENT_STATUS,
|
||||
CacheFlag.EMOTE, // CacheFlag.ACTIVITY,
|
||||
CacheFlag.MEMBER_OVERRIDES // , CacheFlag.VOICE_STATE
|
||||
)
|
||||
|
||||
// .setIdle(true)
|
||||
.setIdle(true)
|
||||
|
||||
.setAutoReconnect(true)
|
||||
|
||||
.addEventListeners(new GuildMessageReceivedListener())
|
||||
.addEventListeners(new DirectMessageReceivedListener())
|
||||
.addEventListeners(new MessageReceivedListener())
|
||||
|
||||
.setEnableShutdownHook(true)
|
||||
|
||||
|
@ -127,22 +107,29 @@ public class Boot {
|
|||
LogHelper.crash(e);
|
||||
}
|
||||
|
||||
Loader.init();
|
||||
|
||||
logger.info("Using account: " + bot.getSelfUser().getName());
|
||||
|
||||
bot.getPresence().setStatus(OnlineStatus.ONLINE);
|
||||
bot.getPresence().setActivity(Activity.listening("Infected Mushroom"));
|
||||
|
||||
LogHelper.boot("Init status list");
|
||||
StatusManager.init();
|
||||
LogHelper.boot("Initialized status list. . .");
|
||||
|
||||
long bootTime = System.currentTimeMillis() - preBootTime;
|
||||
|
||||
LogHelper.boot("Taken " + bootTime + "ms to boot");
|
||||
logger.info("Taken " + bootTime + "ms to boot");
|
||||
|
||||
LogHelper.boot("Starting loop");
|
||||
loop();
|
||||
logger.info("Starting looping thread");
|
||||
Thread loopingThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loop();
|
||||
}
|
||||
});
|
||||
loopingThread.start();
|
||||
logger.info("Looping thread started. . .");
|
||||
}
|
||||
|
||||
private static void loop() {
|
||||
public static void loop() {
|
||||
|
||||
long lastTime = System.currentTimeMillis();
|
||||
long fifteenMins = lastTime;
|
||||
|
@ -151,7 +138,7 @@ public class Boot {
|
|||
long lastTimeUpdateStatus = lastTime;
|
||||
long lastTimeCheckUpdate = lastTime;
|
||||
|
||||
long dynamicWait = Global.getDynamicWait();
|
||||
long dynamicWait = Long.parseLong(GlobalDB.getGlobalValue("dynamicwait"));
|
||||
|
||||
while (running) {
|
||||
|
||||
|
@ -159,13 +146,19 @@ public class Boot {
|
|||
|
||||
if (now > lastTime + dynamicWait) { // dynamic wait loop
|
||||
lastTime = now;
|
||||
try {
|
||||
bot.getSelfUser();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (now > lastTimeCheckUpdate + 900000) {
|
||||
lastTimeCheckUpdate = now;
|
||||
}
|
||||
|
||||
if (now > lastTimeUpdateStatus + dynamicWait && Global.isShuffleStatusEnabled()) {
|
||||
if (now > lastTimeUpdateStatus + dynamicWait
|
||||
&& GlobalDB.getGlobalValue("isshufflestatusenabled").contentEquals("true")) {
|
||||
lastTimeUpdateStatus = now;
|
||||
|
||||
StatusManager.shuffle(bot);
|
||||
|
@ -186,6 +179,6 @@ public class Boot {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
73
src/pkg/deepCurse/nopalmo/core/Loader.java
Normal file
73
src/pkg/deepCurse/nopalmo/core/Loader.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
package pkg.deepCurse.nopalmo.core;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.impl.SimpleLoggerFactory;
|
||||
|
||||
import pkg.deepCurse.nopalmo.global.Reactions;
|
||||
import pkg.deepCurse.nopalmo.manager.StatusManager;
|
||||
|
||||
public class Loader {
|
||||
|
||||
private static Logger logger = new SimpleLoggerFactory().getLogger(Loader.class.getSimpleName());
|
||||
|
||||
public static String init() {
|
||||
StringBuilder sB = new StringBuilder();
|
||||
|
||||
logger.info("Init reaction/emote list");
|
||||
sB.append("Init reaction/emote list\n");
|
||||
try {
|
||||
Reactions.init();
|
||||
logger.info("Initialized reaction/emote list. . .");
|
||||
sB.append("Initialized reaction/emote list. . .\n");
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to initialize reaction/emote list. . .\n" + e + "\n");
|
||||
sB.append("Failed to initialize reaction/emote list. . .```properties\n" + e + "```\n");
|
||||
}
|
||||
|
||||
logger.info("Init command list");
|
||||
sB.append("Init command list\n");
|
||||
try {
|
||||
Boot.commandManager.init();
|
||||
logger.info("Initialized command list. . .");
|
||||
sB.append("Initialized command list. . .\n");
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to initialize command list. . .\n" + e + "\n");
|
||||
sB.append("Failed to initialize command list. . .```properties\n" + e + "```\n");
|
||||
}
|
||||
|
||||
logger.info("Init status list");
|
||||
sB.append("Init status list\n");
|
||||
try {
|
||||
StatusManager.init();
|
||||
logger.info("Initialized status list. . .");
|
||||
sB.append("Initialized status list. . .\n");
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to initialize status list. . .\n" + e + "\n");
|
||||
sB.append("Failed to initialize status list. . .```properties\n" + e + "```\n");
|
||||
}
|
||||
|
||||
// logger.info("Init bontedok settings");
|
||||
// sB.append("Init bontedok settings\n");
|
||||
// BontebokSettings settings = null;
|
||||
// try {
|
||||
// settings = new BontebokSettings();
|
||||
// logger.info("Initialized bontedok settings. . .");
|
||||
// sB.append("Initilaized bontedok settings\n");
|
||||
// } catch (Exception e) {
|
||||
// logger.info("Failed to initialize bontebok settings. . .\n" + e + "\n");
|
||||
// sB.append("Failed to initialize bontebok settings. . .```properties\n" + e + "```\n");
|
||||
// }
|
||||
// logger.info("Init bontedok functions");
|
||||
// sB.append("Init bontedok functions\n");
|
||||
// try {
|
||||
// Boot.bontebokManager = new BontebokManager(settings);
|
||||
// Boot.bontebokManager.init();
|
||||
// logger.info("Initialized bontedok functions. . .");
|
||||
// sB.append("Initilaized bontedok functions\n");
|
||||
// } catch (Exception e) {
|
||||
// logger.info("Failed to initialize bontebok functions. . .\n" + e + "\n");
|
||||
// sB.append("Failed to initialize bontebok functions. . .```properties\n" + e + "```\n");
|
||||
// }
|
||||
return sB.toString();
|
||||
}
|
||||
}
|
807
src/pkg/deepCurse/nopalmo/core/database/NopalmoDBTools.java
Normal file
807
src/pkg/deepCurse/nopalmo/core/database/NopalmoDBTools.java
Normal file
|
@ -0,0 +1,807 @@
|
|||
package pkg.deepCurse.nopalmo.core.database;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import org.fluentjdbc.DbContext;
|
||||
import org.fluentjdbc.DbContextConnection;
|
||||
import org.fluentjdbc.DbContextTable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.impl.SimpleLoggerFactory;
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.InfractionDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.UserDB;
|
||||
|
||||
public class NopalmoDBTools {
|
||||
|
||||
private static Logger logger = new SimpleLoggerFactory().getLogger(NopalmoDBTools.class.getSimpleName());
|
||||
|
||||
private static DbContext context = null;
|
||||
|
||||
private static DbContextTable users = null;
|
||||
private static DbContextTable guilds = null;
|
||||
private static DbContextTable developers = null;
|
||||
private static DbContextTable global = null;
|
||||
@SuppressWarnings("unused") // it will remain un implemented for a little bit
|
||||
private static DbContextTable actions = null;
|
||||
private static DbContextTable infractions = null;
|
||||
|
||||
|
||||
public static void init(String dbName, String username, String pass) {
|
||||
// logger.info("Connecting. . .");
|
||||
context = new DbContext();
|
||||
dataSource = new MysqlDataSource();
|
||||
dataSource.setDatabaseName(dbName);
|
||||
dataSource.setUser(username);
|
||||
dataSource.setPassword(pass);
|
||||
|
||||
users = context.table("users");
|
||||
guilds = context.table("guilds");
|
||||
developers = context.table("developers");
|
||||
global = context.table("global");
|
||||
actions = context.table("actions");
|
||||
infractions = context.table("infractions");
|
||||
|
||||
GlobalDB.prefix = GlobalDB.getGlobalValue("prefix");
|
||||
|
||||
// logger.info("Connected");
|
||||
}
|
||||
|
||||
public static void close() throws SQLException {
|
||||
dataSource.getConnection().close();
|
||||
}
|
||||
|
||||
public class Tools {
|
||||
|
||||
public class UserDB {
|
||||
|
||||
public static boolean getUserBoolean(long userID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<String> out = users.query().where("userid", userID).singleString(value);
|
||||
return out.isPresent() ? out.get().contentEquals("1") : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUserString(long userID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<String> out = users.query().where("userid", userID).singleString(value);
|
||||
return out.isPresent() ? out.get() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getUserLong(long userID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<Number> out = users.query().where("userid", userID).singleLong(value);
|
||||
return out.isPresent() ? out.get().longValue() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean userExists(long userID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
return users.query().where("userid", userID).singleLong("userid").isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setUserBoolean(long userID, String columnName, boolean value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
users.insert().setPrimaryKey("userid", userID).setField(columnName, value).execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
users.query().where("userid", userID).update().setField(columnName, value).execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setUserString(long userID, String columnName, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
users.insert().setPrimaryKey("userid", userID).setField(columnName, value).execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
users.query().where("userid", userID).update().setField(columnName, value).execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setUserLong(long userID, String columnName, long value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
users.insert().setPrimaryKey("userid", userID).setField(columnName, value).execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
users.query().where("userid", userID).update().setField(columnName, value).execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addUser(long userID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
users.insert().setPrimaryKey("userid", userID).execute();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeUser(long userID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
users.query().where("userid", userID).executeDelete();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDirectMessagingEnabled(long userID) {
|
||||
return getUserBoolean(userID, "allowdms");
|
||||
}
|
||||
|
||||
public static boolean isAdvancedUser(long userID) {
|
||||
return getUserBoolean(userID, "advanceduser");
|
||||
}
|
||||
|
||||
public static long getPremiumLevel(long userID) {
|
||||
return getUserLong(userID, "premiumlevel");
|
||||
}
|
||||
|
||||
public static void setDirectMessagingBoolean(long userID, boolean value) {
|
||||
setUserBoolean(userID, "allowdms", value);
|
||||
}
|
||||
|
||||
public static void setAdvancedUserBoolean(long userID, boolean value) {
|
||||
setUserBoolean(userID, "advanceduser", value);
|
||||
}
|
||||
|
||||
public static void setPremiumLevel(long userID, int value) {
|
||||
setUserLong(userID, "premiumlevel", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* this exists because the lib i tried swapping to doesnt have shit to do with
|
||||
* columns, and since its only input is long, it should be fine
|
||||
*/
|
||||
public static String generateDump(long userID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from users where userid = " + userID;
|
||||
try {
|
||||
st = users.getConnection().createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
ResultSetMetaData rsMeta = rs.getMetaData();
|
||||
int columnCount = rsMeta.getColumnCount();
|
||||
StringBuilder sB = new StringBuilder();
|
||||
while (rs.next()) {
|
||||
// Object[] values = new Object[columnCount];
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
// values[i - 1] = resultSet.getObject(i);
|
||||
sB.append(rsMeta.getColumnLabel(i) + ": " + rs.getString(i) + "\n");
|
||||
}
|
||||
}
|
||||
return sB.toString().isEmpty() ? "No data here" : sB.toString();
|
||||
|
||||
} catch (SQLException e) {
|
||||
return null;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GuildDB {
|
||||
|
||||
public static boolean getGuildBoolean(long guildID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<String> out = guilds.query().where("guildid", guildID).singleString(value);
|
||||
return out.isPresent() ? out.get().contentEquals("1") : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGuildString(long guildID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<String> out = guilds.query().where("guildid", guildID).singleString(value);
|
||||
return out.isPresent() ? out.get() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getGuildLong(long guildID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<Number> out = guilds.query().where("guildid", guildID).singleLong(value);
|
||||
return out.isPresent() ? out.get().longValue() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean guildExists(long guildID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
return guilds.query().where("guildid", guildID).singleLong("guildid").isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setGuildBoolean(long guildID, String columnName, boolean value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
guilds.insert().setPrimaryKey("guildid", guildID).setField(columnName, value).execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
guilds.query().where("guildid", guildID).update().setField(columnName, value).execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setGuildString(long guildID, String columnName, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
guilds.insert().setPrimaryKey("guildid", guildID).setField(columnName, value).execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
guilds.query().where("guildid", guildID).update().setField(columnName, value).execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setGuildLong(long guildID, String columnName, long value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
guilds.insert().setPrimaryKey("guildid", guildID).setField(columnName, value).execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
guilds.query().where("guildid", guildID).update().setField(columnName, value).execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addGuild(long guildID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
guilds.insert().setPrimaryKey("guildid", guildID).execute();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeGuild(long guildID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
guilds.query().where("guildid", guildID).executeDelete();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setJoinMessage(long guildID, String value) {
|
||||
setGuildString(guildID, "joinmessage", value);
|
||||
}
|
||||
|
||||
public static void setLeaveMessage(long guildID, String value) {
|
||||
setGuildString(guildID, "leavemessage", value);
|
||||
}
|
||||
|
||||
public static String getJoinMessage(long guildID) {
|
||||
return getGuildString(guildID, "joinmessage");
|
||||
}
|
||||
|
||||
public static String getLeaveMessage(long guildID) {
|
||||
return getGuildString(guildID, "leavemessage");
|
||||
}
|
||||
|
||||
public static String getPrefix(long guildID) {
|
||||
return getGuildString(guildID, "prefix");
|
||||
}
|
||||
|
||||
public static void setPrefix(long guildID, String value) {
|
||||
setGuildString(guildID, "prefix", value);
|
||||
}
|
||||
|
||||
public static String getDateObjectFormat(long guildID) {
|
||||
return getGuildString(guildID, "dateobjectformat");
|
||||
}
|
||||
|
||||
public static void setDateObjectFormat(long guildID, String value) {
|
||||
setGuildString(guildID, "dateobjectformat", value);
|
||||
}
|
||||
|
||||
public static boolean getUpdateOwnNameWithPrefix(long guildID) {
|
||||
return getGuildBoolean(guildID, "updatesownnamewithprefix");
|
||||
}
|
||||
|
||||
public static void setUpdateOwnNameWithPrefix(long guildID, boolean value) {
|
||||
setGuildBoolean(guildID, "updatesownnamewithprefix", value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class DeveloperDB {
|
||||
|
||||
public static boolean getDeveloperBoolean(long userID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<String> out = developers.query().where("developerid", userID).singleString(value);
|
||||
return out.isPresent() ? out.get().contentEquals("1") : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDeveloperString(long userID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<String> out = developers.query().where("developerid", userID).singleString(value);
|
||||
return out.isPresent() ? out.get() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getDeveloperLong(long userID, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Optional<Number> out = developers.query().where("developerid", userID).singleLong(value);
|
||||
return out.isPresent() ? out.get().longValue() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean developerExists(long userID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
return developers.query().where("developerid", userID).singleLong("developerid").isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDeveloperBoolean(long developerID, String columnName, boolean value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
developers.insert().setPrimaryKey("developerid", developerID).setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
developers.query().where("developerid", developerID).update().setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDeveloperString(long developerID, String columnName, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
developers.insert().setPrimaryKey("developerid", developerID).setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
developers.query().where("developerid", developerID).update().setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDeveloperLong(long developerID, String columnName, long value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
developers.insert().setPrimaryKey("developerid", developerID).setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
try {
|
||||
developers.query().where("developerid", developerID).update().setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDeveloper(long developerID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
developers.insert().setPrimaryKey("developerid", developerID).execute();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeDeveloper(long developerID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
developers.query().where("developerid", developerID).executeDelete();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPermission(long userID, String permission) {
|
||||
return getDeveloperBoolean(userID, permission);
|
||||
}
|
||||
|
||||
public static void setPermission(long userID, String permission, boolean value) {
|
||||
setDeveloperBoolean(userID, permission, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class GlobalDB {
|
||||
|
||||
public static String prefix = null;
|
||||
|
||||
public static String getGlobalValue(String id) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
return global.query().where("id", id).singleString("value").isPresent()
|
||||
? global.query().where("id", id).singleString("value").get()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
// public static void setGlobalValue(long id, String columnName, String value) {
|
||||
// try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
// try {
|
||||
// global.insert().setPrimaryKey("id", id).setField(columnName, value).execute();
|
||||
// } catch (Exception e) {
|
||||
//// e.printStackTrace();
|
||||
// try {
|
||||
// global.query().where("id", id).update().setField(columnName, value).execute();
|
||||
// } catch (Exception e2) {
|
||||
// e2.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public static boolean globalValueExists(long id) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
return global.query().where("id", id).singleLong("id").isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ActionDB {
|
||||
// TODO postponed until a later date
|
||||
}
|
||||
|
||||
public class InfractionDB {
|
||||
|
||||
public static long createInfraction(long userID, String reason, long expiryDate, long guildID,
|
||||
long invokerID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
long time = System.currentTimeMillis();
|
||||
infractions.insert().setPrimaryKey("userid", userID).setField("reason", reason)
|
||||
.setField("epochdate", time).setField("expirydate", expiryDate).execute();
|
||||
|
||||
return infractions.query().where("epochdate", time).singleLong("epochdate").isPresent()
|
||||
? infractions.query().where("epochdate", time).singleLong("epochdate").get().longValue()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* do not use unless for bulk testing in the first 10000 ids
|
||||
*
|
||||
* @param userID
|
||||
* @param reason
|
||||
* @param expiryDate
|
||||
* @param infractionID
|
||||
*/
|
||||
public static void createInfraction(long userID, String reason, long expiryDate, long guildID,
|
||||
long invokerID, long infractionID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
infractions.insert().setPrimaryKey("infractionid", infractionID).setField("reason", reason)
|
||||
.setField("epochdate", System.currentTimeMillis()).setField("expirydate", expiryDate)
|
||||
.setField("userid", userID).execute();
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteInfraction(long infractionID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
infractions.query().where("infractionid", infractionID).executeDelete();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setInfractionBoolean(long infractionID, String columnName, boolean value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
infractions.insert().setPrimaryKey("infractionid", infractionID).setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
infractions.query().where("infractionid", infractionID).update().setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setInfractionString(long infractionID, String columnName, String value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
infractions.insert().setPrimaryKey("infractionid", infractionID).setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
infractions.query().where("infractionid", infractionID).update().setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setInfractionLong(long infractionID, String columnName, long value) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
try {
|
||||
infractions.insert().setPrimaryKey("infractionid", infractionID).setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
infractions.query().where("infractionid", infractionID).update().setField(columnName, value)
|
||||
.execute();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getInfractionFromID(long infractionID) {
|
||||
if (infractionExists(infractionID)) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from infractions where infractionid = " + infractionID;
|
||||
try {
|
||||
st = infractions.getConnection().createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
ResultSetMetaData rsMeta = rs.getMetaData();
|
||||
int columnCount = rsMeta.getColumnCount();
|
||||
if (rs.next()) {
|
||||
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
map.put(rsMeta.getColumnLabel(i), rs.getString(i));
|
||||
}
|
||||
}
|
||||
return map.isEmpty() ? null : map;
|
||||
} catch (SQLException e) {
|
||||
return null;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean infractionExists(long infractionID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
return infractions.query().where("infractionID", infractionID).singleLong("infractionID")
|
||||
.isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<HashMap<String, String>> getUserInfractions(long userID) {
|
||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from infractions where userid = " + userID;
|
||||
try {
|
||||
st = infractions.getConnection().createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
ResultSetMetaData rsMeta = rs.getMetaData();
|
||||
int columnCount = rsMeta.getColumnCount();
|
||||
ArrayList<HashMap<String, String>> hashList = new ArrayList<HashMap<String, String>>();
|
||||
while (rs.next()) {
|
||||
HashMap<String, String> infractionHash = new HashMap<String, String>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
infractionHash.put(rsMeta.getColumnLabel(i), rs.getString(i));
|
||||
}
|
||||
hashList.add(infractionHash);
|
||||
}
|
||||
return hashList.isEmpty() ? null : hashList;
|
||||
} catch (SQLException e) {
|
||||
return null;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ArrayList<String> eLL = null;
|
||||
private static ArrayList<Throwable> eL = null;
|
||||
|
||||
public static void main(String... args) {
|
||||
init("chaos", "nopalmo", args[0]);
|
||||
// }
|
||||
//
|
||||
// public static void test(Runnable runnable) {
|
||||
|
||||
long userID = 99;
|
||||
// long guildID = 99;
|
||||
|
||||
Random random = new Random();
|
||||
long minutes = 0;
|
||||
long seconds = 20;
|
||||
eL = new ArrayList<Throwable>();
|
||||
eLL = new ArrayList<String>();
|
||||
ArrayList<Long> times = new ArrayList<Long>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
times.add(Tests.userLoop((minutes > 0) ? (minutes * 60) : 1 * ((seconds > 0) ? (seconds * 1000) : 1000),
|
||||
1000000000, random));
|
||||
// runnable.run();
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
times.add(
|
||||
Tests.infractionLoop((minutes > 0) ? (minutes * 60) : 1 * ((seconds > 0) ? (seconds * 1000) : 1000),
|
||||
1000000000, userID, random));
|
||||
}
|
||||
|
||||
if (!eL.isEmpty() && !eLL.isEmpty()) {
|
||||
for (int i = 0; i < eL.size(); i++) {
|
||||
System.err.println('\n' + eLL.get(i));
|
||||
eL.get(i).printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
long total = 0;
|
||||
for (long i : times) {
|
||||
total += i;
|
||||
}
|
||||
logger.info("Average of {} tests, with length of {} minutes, {} seconds, is {} : {}", times.size(), minutes,
|
||||
seconds, total / times.size(), total);
|
||||
}
|
||||
|
||||
private class Tests {
|
||||
|
||||
public static long infractionLoop(long time, long count, long userID, Random random) {
|
||||
|
||||
long userStartTime = System.currentTimeMillis();
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long targetTime = System.currentTimeMillis() + time;
|
||||
|
||||
long currentCount = 0;
|
||||
long targetCount = count;
|
||||
|
||||
for (long i = 1L; true; i++) {
|
||||
|
||||
if (currentTime >= targetTime) {
|
||||
logger.info("Breaking: Exceeding target time frame");
|
||||
break;
|
||||
} else if (currentCount >= targetCount) {
|
||||
logger.info("Breaking: Exceeding target count");
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
InfractionDB.createInfraction(userID, String.valueOf(random.nextInt()), 0, 0, 0, i);
|
||||
} catch (Throwable e) {
|
||||
eLL.add("onCreate");
|
||||
eL.add(e);
|
||||
}
|
||||
InfractionDB.getInfractionFromID(i);
|
||||
InfractionDB.setInfractionLong(i, "expirydate", userStartTime);
|
||||
InfractionDB.getInfractionFromID(i);
|
||||
try {
|
||||
InfractionDB.deleteInfraction(i);
|
||||
} catch (Throwable e) {
|
||||
eLL.add("onRemove");
|
||||
eL.add(e);
|
||||
}
|
||||
|
||||
currentTime = System.currentTimeMillis();
|
||||
currentCount++;
|
||||
|
||||
}
|
||||
|
||||
logger.info("Time taken: {}", (System.currentTimeMillis() - userStartTime));
|
||||
logger.info("Total completed count: {}", currentCount);
|
||||
// return System.currentTimeMillis() - userStartTime;
|
||||
return currentCount;
|
||||
}
|
||||
|
||||
public static long userLoop(long time, long count, Random random) {
|
||||
|
||||
long userStartTime = System.currentTimeMillis();
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long targetTime = System.currentTimeMillis() + time;
|
||||
|
||||
long currentCount = 0;
|
||||
long targetCount = count;
|
||||
|
||||
for (long i = 1L; true; i++) {
|
||||
|
||||
if (currentTime >= targetTime) {
|
||||
logger.info("Breaking: Exceeding target time frame");
|
||||
break;
|
||||
} else if (currentCount >= targetCount) {
|
||||
logger.info("Breaking: Exceeding target count");
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
UserDB.addUser(i);
|
||||
} catch (Throwable e) {
|
||||
eLL.add("onCreate");
|
||||
eL.add(e);
|
||||
}
|
||||
|
||||
UserDB.setAdvancedUserBoolean(i, true);
|
||||
UserDB.setDirectMessagingBoolean(i, false);
|
||||
UserDB.setPremiumLevel(i, 2);
|
||||
UserDB.getPremiumLevel(i);
|
||||
UserDB.isAdvancedUser(i);
|
||||
UserDB.isDirectMessagingEnabled(i);
|
||||
|
||||
try {
|
||||
UserDB.removeUser(i);
|
||||
} catch (Throwable e) {
|
||||
eLL.add("onRemove");
|
||||
eL.add(e);
|
||||
}
|
||||
|
||||
currentTime = System.currentTimeMillis();
|
||||
currentCount++;
|
||||
|
||||
}
|
||||
|
||||
logger.info("Time taken: {}", (System.currentTimeMillis() - userStartTime));
|
||||
logger.info("Total completed count: {}", currentCount);
|
||||
// return System.currentTimeMillis() - userStartTime;
|
||||
return currentCount;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,537 +0,0 @@
|
|||
package pkg.deepCurse.nopalmo.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
|
||||
public class DatabaseTools {
|
||||
|
||||
private static Connection connection = null;
|
||||
|
||||
public DatabaseTools(String password) throws SQLException, ClassNotFoundException {
|
||||
connection = createConnection(password);
|
||||
Global.updatePrefix();
|
||||
}
|
||||
|
||||
public static Connection createConnection(String password) throws SQLException, ClassNotFoundException {
|
||||
|
||||
String dbName = Boot.isProd ? "nopalmo" : "chaos";
|
||||
|
||||
String driver = "com.mysql.cj.jdbc.Driver";
|
||||
String url = "jdbc:mysql://localhost/" + dbName;
|
||||
String username = "nopalmo";
|
||||
|
||||
Class.forName(driver);
|
||||
return DriverManager.getConnection(url, username, password);
|
||||
}
|
||||
|
||||
private static void checkUpdateCounts(PreparedStatement pstmt, int[] updateCounts) {
|
||||
checkUpdateCounts(pstmt.toString(), updateCounts);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void checkUpdateCounts(String action, int[] updateCounts) {
|
||||
for (int i = 0; i < updateCounts.length; i++) {
|
||||
if (updateCounts[i] >= 0) {
|
||||
System.out.println("Successfully executed; updateCount=" + updateCounts[i] + "; On action " + action);
|
||||
} else if (updateCounts[i] == Statement.SUCCESS_NO_INFO) {
|
||||
System.out.println("Successfully executed; updateCount=Statement.SUCCESS_NO_INFO; On action " + action);
|
||||
} else if (updateCounts[i] == Statement.EXECUTE_FAILED) {
|
||||
System.out.println("Failed to execute; updateCount=Statement.EXECUTE_FAILED; On action " + action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Tools {
|
||||
|
||||
// these sub classes will represent tables and the methods therein will be for
|
||||
// actions within said table
|
||||
|
||||
public class Users {
|
||||
|
||||
public static int getPremiumLevel(long userID) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from users where userid = " + userID;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getInt("premiumlevel");
|
||||
} else {
|
||||
// throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
return 0;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAdvancedUser(long userID) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from users where userid = " + userID;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getBoolean("advanceduser");
|
||||
} else {
|
||||
// throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
return false;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
||||
public static String dump(long userID) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from users where userid = " + userID;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
ResultSetMetaData rsMeta = rs.getMetaData();
|
||||
int columnCount = rsMeta.getColumnCount();
|
||||
StringBuilder sB = new StringBuilder();
|
||||
while (rs.next()) {
|
||||
// Object[] values = new Object[columnCount];
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
// values[i - 1] = resultSet.getObject(i);
|
||||
sB.append(rsMeta.getColumnLabel(i) + ": " + rs.getString(i) + "\n");
|
||||
}
|
||||
}
|
||||
return sB.toString();
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
return null;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Guild {
|
||||
|
||||
public class Prefix {
|
||||
|
||||
@Nullable
|
||||
public static String getPrefix(@Nonnull long guildID) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from guilds where guildid = " + guildID;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getString("prefix");
|
||||
} else {
|
||||
// throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
System.err.println(
|
||||
"Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return createPrefix(guildID, Global.prefix);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
return null;
|
||||
} finally { // @formatter:off
|
||||
try {if (rs != null)rs.close();} catch (Exception e) {}
|
||||
try {if (st != null)st.close();} catch (Exception e) {}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
||||
public static String createPrefix(@Nonnull long guildID, @Nullable String prefix)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (prefix == null || prefix.isEmpty()) {
|
||||
// throw new IllegalArgumentException("Input cannot be empty");
|
||||
prefix = Global.prefix;
|
||||
}
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
|
||||
String query = "insert into guilds(guildid, prefix) values(?, ?);";
|
||||
try {
|
||||
pstmt = connection.prepareStatement(query);
|
||||
|
||||
pstmt.setLong(1, guildID);
|
||||
pstmt.setString(2, prefix);
|
||||
pstmt.addBatch();
|
||||
|
||||
int[] updateCounts = pstmt.executeBatch();
|
||||
checkUpdateCounts(pstmt, updateCounts);
|
||||
pstmt.close();
|
||||
// connection.commit();
|
||||
return prefix;
|
||||
} catch (SQLException e) {
|
||||
SQLCode.sqlTranslate(pstmt, e);
|
||||
for (int i : new int[] { 1062 }) {
|
||||
if (i == e.getErrorCode()) {
|
||||
return setPrefix(guildID, prefix);
|
||||
}
|
||||
}
|
||||
try {
|
||||
connection.rollback();
|
||||
} catch (Exception e2) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String setPrefix(long guildID, String prefix) throws IllegalArgumentException {
|
||||
|
||||
if (prefix.isEmpty()) {
|
||||
throw new IllegalArgumentException("Input cannot be empty");
|
||||
}
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
|
||||
String query = "update guilds set prefix = ? where guildid = ?;";
|
||||
try {
|
||||
pstmt = connection.prepareStatement(query);
|
||||
|
||||
pstmt.setLong(2, guildID);
|
||||
pstmt.setString(1, prefix);
|
||||
pstmt.addBatch();
|
||||
|
||||
int[] updateCounts = pstmt.executeBatch();
|
||||
checkUpdateCounts(pstmt, updateCounts);
|
||||
pstmt.close();
|
||||
// conn.commit();
|
||||
return prefix;
|
||||
} catch (SQLException e) {
|
||||
SQLCode.sqlTranslate(pstmt, e);
|
||||
try {
|
||||
connection.rollback();
|
||||
} catch (Exception e2) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Developers {
|
||||
|
||||
public static boolean getDeveloperBoolean(long userID, String key) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from developers where userid = " + userID;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getBoolean(key);
|
||||
} else {
|
||||
// throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (st != null)
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
public static String getDeveloperString(long userID, String key) {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from developers where userid = " + userID;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getString(key);
|
||||
} else {
|
||||
// throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (st != null)
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
public static boolean canPowerOffBot(long userID) {
|
||||
return getDeveloperBoolean(userID, "canPowerOffBot");
|
||||
}
|
||||
|
||||
public static boolean canUseInformationCommands(long userID) {
|
||||
return getDeveloperBoolean(userID, "canuseinformationcommands");
|
||||
}
|
||||
|
||||
public static boolean hasPermission(long userID, String permission) {
|
||||
return getDeveloperBoolean(userID, permission);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Global {
|
||||
|
||||
public static String prefix = null;
|
||||
|
||||
public static void updatePrefix() throws SQLException {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from global where id = 'prefix'";
|
||||
String msg = "Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query;
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
prefix = rs.getString("value");
|
||||
} else {
|
||||
// throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
|
||||
System.err.println(msg);
|
||||
throw new NullPointerException(msg);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
throw new SQLException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (st != null)
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
public static boolean isShuffleStatusEnabled() {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from global where id = 'isshufflestatusenabled'";
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getString("value").contentEquals("true");
|
||||
} else {
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (st != null)
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
public static int getDynamicWait() {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from global where id = 'dynamicwait'";
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getInt("value");
|
||||
} else {
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return 45000;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
return 45000;
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (st != null)
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
public static int getEmbedColor() {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
String query = "select * from global where id = 'embedcolor'";
|
||||
try {
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(query);
|
||||
if (rs.next()) {
|
||||
return rs.getInt("value");
|
||||
} else {
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
SQLCode.getMessage(query, e.getErrorCode());
|
||||
// System.out.println("eeeeee");
|
||||
return 0;
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (st != null)
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public class Reaction { // started off as a good idea but it sucks
|
||||
// public static String getReaction(long reactionID) {
|
||||
// Statement st = null;
|
||||
// ResultSet rs = null;
|
||||
// String query = "select * from reactions where id = '"+reactionID+"'";
|
||||
// try {
|
||||
// st = connection.createStatement();
|
||||
// rs = st.executeQuery(query);
|
||||
// if (rs.next()) {
|
||||
// return rs.getString("val");
|
||||
// } else {
|
||||
// // throw new SQLException(null, null, 33); // we need a real catcher here
|
||||
// System.err
|
||||
// .println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// } catch (SQLException e) {
|
||||
// sqlTranslate(query, e.getErrorCode());
|
||||
// // System.out.println("eeeeee");
|
||||
// return null;
|
||||
// } finally {
|
||||
// try {
|
||||
// if (rs != null)
|
||||
// rs.close();
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// if (st != null)
|
||||
// st.close();
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
//
|
||||
// // try { if (conn != null) conn.close(); } catch (Exception e) {};
|
||||
// }
|
||||
// // return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package pkg.deepCurse.nopalmo.database;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLCode {
|
||||
|
||||
public static String getMessage(String action, int errorCode) {
|
||||
switch (errorCode) {
|
||||
case 1062:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; ER_DUP_ENTRY; On action " + action);
|
||||
return "";
|
||||
case 1054:
|
||||
System.err
|
||||
.println("Failed to execute; errorCode=" + errorCode + "; ER_BAD_FIELD_ERROR; On action " + action);
|
||||
return "";
|
||||
default:
|
||||
System.err.println("Failed to execute; errorCode=" + errorCode + "; Unknown code; On action " + action);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void sqlTranslate(String action, SQLException e) {
|
||||
SQLCode.getMessage(action, e.getErrorCode());
|
||||
}
|
||||
|
||||
public static void sqlTranslate(PreparedStatement pstmt, SQLException e) {
|
||||
SQLCode.getMessage(pstmt.toString(), e.getErrorCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -4,12 +4,19 @@ import java.util.HashMap;
|
|||
|
||||
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() {
|
||||
insert("galaxyThumb", 801657838358495232L);
|
||||
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) {
|
||||
|
@ -17,11 +24,12 @@ public class Reactions {
|
|||
}
|
||||
|
||||
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) {
|
||||
return "<:" + id + ":" + reactionMap.get(id) + ">";
|
||||
return id.startsWith(":") ? internalReactionMap.get(id.substring(1))
|
||||
: "<:" + id + ":" + reactionMap.get(id) + ">";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
package pkg.deepCurse.nopalmo.global;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import pkg.deepCurse.nopalmo.command.CommandInterface;
|
||||
|
||||
public class Tools {
|
||||
|
||||
public static Random random = new Random();
|
||||
|
||||
public static void wrongUsage(MessageChannel messageChannel, CommandInterface command) {
|
||||
messageChannel.sendMessage("Wrong Command Usage!\n" + command.getUsage(false)).queue();
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
// tc.sendMessage("Wrong Command Usage!\n" + c.getUsage()).queue();
|
||||
// }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +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.guild.GuildMessageReceivedEvent;
|
||||
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 GuildMessageReceivedListener extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onReady(@Nonnull ReadyEvent event) {
|
||||
System.out.println("GuildMessageReceivedListener is now ready\n" + event.getGuildAvailableCount() + "/"
|
||||
+ event.getGuildTotalCount() + " : " + event.getGuildUnavailableCount() + " <"
|
||||
+ event.getResponseNumber() + ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
||||
Message message = event.getMessage();
|
||||
String messageRaw = message.getContentRaw();
|
||||
|
||||
if (messageRaw.contentEquals(Global.prefix + Global.prefix)
|
||||
&& DatabaseTools.Tools.Developers.canPowerOffBot(event.getAuthor().getIdLong())) {
|
||||
|
||||
// message.addReaction(Reactions.getReaction("galaxyThumb")).complete();
|
||||
// TODO re enable
|
||||
|
||||
message.delete().complete();
|
||||
|
||||
event.getJDA().shutdown();
|
||||
System.exit(7);
|
||||
}
|
||||
|
||||
if (!event.getAuthor().isBot()) {
|
||||
Boot.commandManager.startCommand(event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package pkg.deepCurse.nopalmo.listener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.impl.SimpleLoggerFactory;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.DeveloperDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.global.Reactions;
|
||||
|
||||
public class MessageReceivedListener extends ListenerAdapter {
|
||||
|
||||
private Logger logger = new SimpleLoggerFactory().getLogger(this.getClass().getSimpleName());
|
||||
|
||||
@Override
|
||||
public void onReady(@Nonnull ReadyEvent event) {
|
||||
logger.info("MessageReceivedListener is now ready " + event.getGuildAvailableCount() + "/"
|
||||
+ event.getGuildTotalCount() + " : " + event.getGuildUnavailableCount() + " <"
|
||||
+ event.getResponseNumber() + ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
|
||||
try {
|
||||
Message message = event.getMessage();
|
||||
String messageRaw = message.getContentRaw();
|
||||
|
||||
if (messageRaw.contentEquals(GlobalDB.prefix + GlobalDB.prefix)
|
||||
&& DeveloperDB.hasPermission(event.getAuthor().getIdLong(), "canpoweroffbot")) {
|
||||
|
||||
message.addReaction(Reactions.getReaction(":eggplant")).complete();
|
||||
|
||||
event.getJDA().shutdown();
|
||||
System.exit(7);
|
||||
}
|
||||
|
||||
if (!event.getAuthor().isBot()) {
|
||||
Boot.commandManager.startCommand(event);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
event.getChannel().sendMessage(e.toString()).queue();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,9 @@
|
|||
package pkg.deepCurse.nopalmo.manager;
|
||||
|
||||
public class Argument {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// README
|
||||
//
|
||||
// This tool is used simply for now, but it will be worth while if you get used
|
||||
// to it
|
||||
//
|
||||
// this allows extra organization and ease of use throughout the creation of
|
||||
// commands
|
||||
// instead of one simple list where if args[1] == "all" do code
|
||||
// this allows the same functionality, if not more with a little bit of learning
|
||||
// you can go back to what it was before, but i honestly believe this system is
|
||||
// worthwhile
|
||||
// it just needs polish and reports on usage for optimization
|
||||
//
|
||||
//// TL;DR ITS A NEW FEATURE, GIVE IT TIME
|
||||
public class Argument {
|
||||
|
||||
private int requiredArgs = 0;
|
||||
private String argName = null;
|
||||
|
@ -30,7 +18,8 @@ public class Argument {
|
|||
private String permissionLevel = null;
|
||||
private boolean isRequired = false;
|
||||
private boolean isDeveloper = false;
|
||||
|
||||
private List<String> aliases = new ArrayList<String>();
|
||||
|
||||
public static final String argumentPrefix = "-"; // This exists for the sole reason of customization and will
|
||||
// generally not change, ever, its recommended you keep it to
|
||||
// something other than empty to help ensure that what the user
|
||||
|
@ -117,29 +106,29 @@ public class Argument {
|
|||
// return this;
|
||||
// }
|
||||
|
||||
public Argument setPrefixRequirement(Boolean bool) {
|
||||
this.requiresPrefix = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Argument setIsWildcard(Boolean bool) {
|
||||
|
||||
if (this.position<=-1) {
|
||||
|
||||
if (this.position <= -1) {
|
||||
throw new IllegalArgumentException("Cannot create a wildcard without a position; set a position first");
|
||||
}
|
||||
|
||||
|
||||
this.isWildcard = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Boolean getIsWildcard() {
|
||||
return isWildcard;
|
||||
}
|
||||
|
||||
public boolean getPrefixRequirement() {
|
||||
public boolean isPrefixRequired() {
|
||||
return this.requiresPrefix;
|
||||
}
|
||||
|
||||
public Argument setPrefixRequirement(Boolean bool) {
|
||||
this.requiresPrefix = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
@ -150,7 +139,7 @@ public class Argument {
|
|||
}
|
||||
|
||||
public interface RunnableArg {
|
||||
|
||||
|
||||
public void run(CommandBlob blob);
|
||||
|
||||
}
|
||||
|
@ -165,7 +154,7 @@ public class Argument {
|
|||
}
|
||||
|
||||
public Argument setAutoStartRunnable(boolean bool) {
|
||||
this.autoStartRunnable = bool;
|
||||
this.autoStartRunnable = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -191,7 +180,7 @@ public class Argument {
|
|||
this.isDeveloper = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public String getPermission() {
|
||||
return this.permissionLevel;
|
||||
}
|
||||
|
@ -199,7 +188,7 @@ public class Argument {
|
|||
public boolean isRequired() {
|
||||
return this.isRequired;
|
||||
}
|
||||
|
||||
|
||||
public Argument setIsRequired(boolean bool) {
|
||||
this.isRequired = bool;
|
||||
return this;
|
||||
|
@ -214,4 +203,15 @@ public class Argument {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Argument addAliases(String... alias) {
|
||||
for (String i : alias) {
|
||||
this.aliases.add(i);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
77
src/pkg/deepCurse/nopalmo/manager/BontebokManager.java
Normal file
77
src/pkg/deepCurse/nopalmo/manager/BontebokManager.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
//package pkg.deepCurse.nopalmo.manager;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import pkg.deepCurse.bontebok.core.BontebokFunctionInterface;
|
||||
//import pkg.deepCurse.bontebok.core.BontebokInterpreter;
|
||||
//import pkg.deepCurse.bontebok.core.BontebokSettings;
|
||||
//import pkg.deepCurse.nopalmo.global.Reactions;
|
||||
//
|
||||
//public class BontebokManager {
|
||||
//
|
||||
// private BontebokInterpreter interpreter = null;
|
||||
// private BontebokSettings settings = null;
|
||||
//
|
||||
// public BontebokManager(BontebokSettings settings) {
|
||||
// interpreter = new BontebokInterpreter(settings);
|
||||
// this.settings = settings;
|
||||
// }
|
||||
//
|
||||
// public BontebokManager init() {
|
||||
// interpreter.clearFunctionMap();
|
||||
// interpreter.addFunction("reply", new BontebokNopalmoFunctionInterface() {
|
||||
//
|
||||
// @Override
|
||||
// public void run(List<String> args, CommandBlob blob) {
|
||||
// StringBuilder sB = new StringBuilder();
|
||||
// for (String i : args) {
|
||||
// sB.append(i);
|
||||
// }
|
||||
// blob.getMessage().reply(sB.toString()).queue();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getRequiredArgs() {
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// interpreter.addFunction("react", new BontebokNopalmoFunctionInterface() {
|
||||
//
|
||||
// @Override
|
||||
// public void run(List<String> args, CommandBlob blob) {
|
||||
// try {
|
||||
// blob.getMessage().addReaction(Reactions.getReaction(args.get(0))).queue();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getRequiredArgs() {
|
||||
// return 1;
|
||||
// }
|
||||
// });
|
||||
// return this;
|
||||
// }
|
||||
//
|
||||
// public BontebokInterpreter getBontebokInterpreter() {
|
||||
// return interpreter;
|
||||
// }
|
||||
//
|
||||
// public BontebokSettings getBontebokSettings() {
|
||||
// return settings;
|
||||
// }
|
||||
//
|
||||
// public interface BontebokNopalmoFunctionInterface extends BontebokFunctionInterface {
|
||||
//
|
||||
// @Override
|
||||
// public default void run(List<String> args) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// void run(List<String> args, CommandBlob blob);
|
||||
// }
|
||||
//
|
||||
//}
|
78
src/pkg/deepCurse/nopalmo/manager/ClassManager.java
Normal file
78
src/pkg/deepCurse/nopalmo/manager/ClassManager.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
package pkg.deepCurse.nopalmo.manager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.HashMap;
|
||||
|
||||
import qj.util.lang.DynamicClassLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author u1d
|
||||
*
|
||||
* @param <K> access key, typically the name of the class for simplicity
|
||||
* @param <CT> class type, supply InternalReloadable if you are unsure of what
|
||||
* to use
|
||||
*/
|
||||
public class ClassManager<K, CT> {
|
||||
|
||||
private HashMap<K, Class<CT>> classMap;
|
||||
private ClassLoader classLoader;
|
||||
private URLClassLoader urlClassLoader;
|
||||
|
||||
public ClassManager() {
|
||||
classLoader = getClass().getClassLoader();
|
||||
classMap = new HashMap<K, Class<CT>>();
|
||||
}
|
||||
|
||||
public void add(K key, String path) throws ClassNotFoundException {
|
||||
Class<CT> loadedMyClass = (Class<CT>) classLoader.loadClass(path);
|
||||
classMap.put(key, loadedMyClass);
|
||||
}
|
||||
|
||||
public void addFile(K key, String name, File file) throws ClassNotFoundException, IOException {
|
||||
classMap.put(key, (Class<CT>) new DynamicClassLoader(file.getPath()).load(name));
|
||||
// Class<CT> loadedMyClass = (Class<CT>) Class.forName(name, true, urlClassLoader.newInstance(new URL[] {file.toURI().toURL()}));
|
||||
// classMap.put(key, loadedMyClass);
|
||||
}
|
||||
|
||||
public void remove(String path) {
|
||||
|
||||
}
|
||||
|
||||
public void removeFile(File file) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This reloadable is for internal use, if you wish to add to its functionality,
|
||||
* simply create a new interface that implements this one (InternalReloadable)
|
||||
*
|
||||
* @author u1d
|
||||
*/
|
||||
public interface InternalReloadable<K, V> {
|
||||
/**
|
||||
* a data bus for use with dumping data that need to persist across reloads
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default public HashMap<K, V> dump() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* a data bus for use with loading data that need to persist across reloads
|
||||
*
|
||||
* @param bulk
|
||||
*/
|
||||
default public void load(HashMap<K, V> dBus) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Class<CT> getClass(K key) {
|
||||
return classMap.get(key);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,117 +3,183 @@ package pkg.deepCurse.nopalmo.manager;
|
|||
import java.util.ArrayList;
|
||||
|
||||
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.PrivateChannel;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.Event;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
|
||||
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 CommandManager commandManager = null;
|
||||
private ArrayList<String> args = 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 BontebokInterpreter interpreter = null;
|
||||
|
||||
private long userID = 0;
|
||||
private long channelID = 0;
|
||||
private boolean isDeveloper = false;
|
||||
private boolean isWebhookMessage = false;
|
||||
private boolean isFromGuild = false;
|
||||
|
||||
public CommandBlob(GuildMessageReceivedEvent event) {
|
||||
public CommandBlob(MessageReceivedEvent event, CommandManager commandManager) {
|
||||
this.event = event;
|
||||
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) {
|
||||
this.event = event;
|
||||
this.bot = event.getJDA();
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public CommandBlob(GuildCommandBlob blob) {
|
||||
this.args = blob.getArgs();
|
||||
this.channelID = blob.getChannelID();
|
||||
this.commandManager = blob.getCommandManager();
|
||||
this.event = blob.getEvent();
|
||||
this.userID = blob.getUserID();
|
||||
this.bot = blob.getEvent().getJDA();
|
||||
public void setCommandManager(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
public CommandBlob(DirectCommandBlob blob) {
|
||||
this.args = blob.getArgs();
|
||||
this.channelID = blob.getChannelID();
|
||||
this.commandManager = blob.getCommandManager();
|
||||
this.event = blob.getEvent();
|
||||
this.userID = blob.getUserID();
|
||||
this.bot = blob.getEvent().getJDA();
|
||||
public ArrayList<Argument> getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public void setArgs(ArrayList<Argument> args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public long getAuthorID() {
|
||||
return authorID;
|
||||
}
|
||||
|
||||
public void setAuthorID(long authorID) {
|
||||
this.authorID = authorID;
|
||||
}
|
||||
|
||||
public long getChannelID() {
|
||||
return channelID;
|
||||
}
|
||||
|
||||
public CommandBlob setChannelID(long channelID) {
|
||||
public void setChannelID(long channelID) {
|
||||
this.channelID = channelID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageChannel getChannel() {
|
||||
TextChannel textChannel = bot.getTextChannelById(channelID);
|
||||
if (textChannel != null){
|
||||
return textChannel;
|
||||
}
|
||||
PrivateChannel privateChannel = bot.getPrivateChannelById(channelID);
|
||||
if (privateChannel != null){
|
||||
return privateChannel;
|
||||
}
|
||||
return null;
|
||||
public long getGuildID() {
|
||||
return guildID;
|
||||
}
|
||||
|
||||
public MessageChannel getMessageChannel(long channelID) {
|
||||
return bot.getTextChannelById(channelID);
|
||||
public void setGuildID(long guildID) {
|
||||
this.guildID = guildID;
|
||||
}
|
||||
|
||||
public long getUserID() {
|
||||
return userID;
|
||||
public long getMessageID() {
|
||||
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() {
|
||||
return bot;
|
||||
}
|
||||
|
||||
public CommandBlob setUserID(long userID) {
|
||||
this.userID = userID;
|
||||
return this;
|
||||
public void setBot(JDA bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
public ArrayList<String> getArgs() {
|
||||
return args;
|
||||
public MessageChannel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public CommandBlob setArgs(ArrayList<String> args) {
|
||||
this.args = args;
|
||||
return this;
|
||||
public void setChannel(MessageChannel messageChannel) {
|
||||
this.channel = messageChannel;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
|
||||
public User getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public CommandBlob setCommandManager(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
return this;
|
||||
public void setAuthor(User author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Event getEvent() {
|
||||
if (event instanceof GuildMessageReceivedEvent) {
|
||||
return (GuildMessageReceivedEvent) event;
|
||||
} else if (event instanceof MessageReceivedEvent) {
|
||||
return (MessageReceivedEvent) event;
|
||||
} else
|
||||
return null;
|
||||
public Member getMember() {
|
||||
return member;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean isDeveloper() {
|
||||
return isDeveloper;
|
||||
}
|
||||
|
||||
public void setDeveloper(boolean isDeveloper) {
|
||||
this.isDeveloper = isDeveloper;
|
||||
}
|
||||
|
||||
// public BontebokInterpreter getInterpreter() {
|
||||
// return interpreter;
|
||||
// }
|
||||
//
|
||||
// public CommandBlob setInterpreter(BontebokInterpreter interpreter) {
|
||||
// this.interpreter = interpreter;
|
||||
// return this;
|
||||
// }
|
||||
}
|
||||
|
|
9
src/pkg/deepCurse/nopalmo/manager/CommandLoop.java
Normal file
9
src/pkg/deepCurse/nopalmo/manager/CommandLoop.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package pkg.deepCurse.nopalmo.manager;
|
||||
|
||||
public class CommandLoop {
|
||||
|
||||
// public static add() {
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -12,28 +12,35 @@ import java.util.concurrent.Executor;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.dv8tion.jda.api.events.Event;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
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.PrivateCommandInterface;
|
||||
import pkg.deepCurse.nopalmo.command.commands.fun.Stupid;
|
||||
import pkg.deepCurse.nopalmo.command.commands.general.Prefix;
|
||||
import pkg.deepCurse.nopalmo.command.commands.general.Test;
|
||||
import pkg.deepCurse.nopalmo.command.commands.info.Git;
|
||||
import pkg.deepCurse.nopalmo.command.commands.info.Help;
|
||||
import pkg.deepCurse.nopalmo.command.commands.info.Info;
|
||||
import pkg.deepCurse.nopalmo.command.commands.info.Ping;
|
||||
import pkg.deepCurse.nopalmo.command.commands.info.Reload;
|
||||
import pkg.deepCurse.nopalmo.command.commands.testing.GuildCommand;
|
||||
import pkg.deepCurse.nopalmo.command.commands.testing.PrivateCommand;
|
||||
import pkg.deepCurse.nopalmo.command.testing.LiveUpdateTestCommand;
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.DeveloperDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GuildDB;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.UserDB;
|
||||
import pkg.deepCurse.nopalmo.global.Tools;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private final Map<String, GuildCommandInterface> guildCommandMap = new HashMap<>();
|
||||
private final Map<String, DirectCommandInterface> directCommandMap = new HashMap<>();
|
||||
private final Map<String, CommandInterface> commandMap = new HashMap<>();
|
||||
// private final Map<String, DirectCommandInterface> directCommandMap = new
|
||||
// HashMap<>();
|
||||
private static Executor executor = null;
|
||||
|
||||
public CommandManager() {
|
||||
|
@ -42,78 +49,48 @@ public class CommandManager {
|
|||
}
|
||||
|
||||
public void init() {
|
||||
addCommand(new Help(this));
|
||||
addCommand(new Ping());
|
||||
addCommand(new Git());
|
||||
addCommand(new Prefix());
|
||||
addCommand(new Test());
|
||||
addCommand(new Info());
|
||||
commandMap.clear();
|
||||
addCommand(new Help(this));// guild
|
||||
addCommand(new Ping()); // dual
|
||||
addCommand(new Git()); // dual
|
||||
addCommand(new Prefix()); // guild
|
||||
addCommand(new Test()); // guild
|
||||
addCommand(new Info()); // guild direct
|
||||
addCommand(new GuildCommand()); // guild
|
||||
addCommand(new PrivateCommand()); // private
|
||||
addCommand(new Reload()); // dual
|
||||
// addCommand(new BontebokInterpret()); // dual
|
||||
addCommand(new Stupid()); // guild
|
||||
addCommand(new LiveUpdateTestCommand());
|
||||
}
|
||||
|
||||
private void addCommand(CommandInterface c) {
|
||||
if (c instanceof DirectCommandInterface) {
|
||||
addDirectCommand((DirectCommandInterface) c);
|
||||
}
|
||||
if (c instanceof GuildCommandInterface) {
|
||||
addGuildCommand((GuildCommandInterface) c);
|
||||
|
||||
for (String i : c.getCommandCalls()) {
|
||||
// if (!commandMap.containsKey(i)) {
|
||||
commandMap.put(i, c);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
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 CommandInterface getCommand(String commandName) {
|
||||
return commandMap.get(commandName);
|
||||
}
|
||||
|
||||
public Collection<DirectCommandInterface> getDirectCommands() {
|
||||
return directCommandMap.values();
|
||||
public Collection<CommandInterface> getCommands() {
|
||||
return commandMap.values();
|
||||
}
|
||||
|
||||
public DirectCommandInterface getDirectCommand(String commandName) {
|
||||
if (commandName != null) {
|
||||
return directCommandMap.get(commandName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void startCommand(MessageReceivedEvent event) { // TODO split up more
|
||||
|
||||
private void addGuildCommand(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 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();
|
||||
String prefix = Global.prefix;
|
||||
String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
||||
final String prefix = event.isFromGuild() ? (GuildDB.getPrefix(event.getGuild().getIdLong()) != null
|
||||
? GuildDB.getPrefix(event.getGuild().getIdLong())
|
||||
: GlobalDB.prefix) : GlobalDB.prefix;
|
||||
final String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
||||
|
||||
String splicer = null;
|
||||
|
||||
if (message.startsWith(pingPrefix + " ")) {
|
||||
splicer = pingPrefix + " ";
|
||||
} else if (message.startsWith(prefix)) {
|
||||
|
@ -127,26 +104,31 @@ public class CommandManager {
|
|||
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
|
||||
final String commandCall = split[0].toLowerCase();
|
||||
|
||||
if (guildCommandMap.containsKey(commandCall)) {
|
||||
if (commandMap.containsKey(commandCall)) {
|
||||
|
||||
UserDB.addUser(event.getAuthor().getIdLong());
|
||||
|
||||
if (event.isFromGuild()) {
|
||||
GuildDB.addGuild(event.getGuild().getIdLong());
|
||||
}
|
||||
|
||||
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>();
|
||||
CommandBlob commandBlob = new CommandBlob(event, this);
|
||||
CommandInterface command = commandMap.get(commandCall);
|
||||
|
||||
DirectCommandBlob commandBlob = new DirectCommandBlob(event);
|
||||
DirectCommandInterface command = directCommandMap.get(commandCall);
|
||||
HashMap<String, Argument> argumentList = new HashMap<String, Argument>();
|
||||
// commandBlob.setInterpreter(Boot.bontebokManager.getBontebokInterpreter());
|
||||
|
||||
HashMap<String, Argument> argumentMap = new HashMap<String, Argument>();
|
||||
HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
|
||||
|
||||
long commandStartTime = System.currentTimeMillis();
|
||||
|
||||
boolean printTime = false;
|
||||
byte argSkipCount = 0;
|
||||
boolean remainsValid = true;
|
||||
|
||||
HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
|
||||
|
||||
if (command.getArguments() != null) {
|
||||
for (Argument i : command.getArguments().values()) {
|
||||
if (i.getPosition() >= 0) {
|
||||
|
@ -166,7 +148,7 @@ public class CommandManager {
|
|||
printTime = true;
|
||||
break;
|
||||
case "\\perm":
|
||||
commandBlob.setUserID(380045419381784576L);
|
||||
commandBlob.setAuthorID(380045419381784576L);
|
||||
break;
|
||||
case "\\del":
|
||||
event.getMessage().delete().queue();
|
||||
|
@ -176,30 +158,46 @@ public class CommandManager {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// split up so global commands are actually global, and will not be affected by
|
||||
// neighboring local args
|
||||
|
||||
if (DeveloperDB.developerExists(commandBlob.getAuthorID())) {
|
||||
commandBlob.setDeveloper(DeveloperDB.getDeveloperBoolean(commandBlob.getAuthorID(),
|
||||
"developercommandpermission"));
|
||||
}
|
||||
for (int i = 0; i < newArgs.size(); i++) {
|
||||
String x = newArgs.get(i);
|
||||
x = x.toLowerCase();
|
||||
if (argSkipCount <= 0) {
|
||||
if (command.getArguments() != null) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (x.startsWith(Argument.argumentPrefix)) {
|
||||
|
||||
String pre = x.substring(Argument.argumentPrefix.length());
|
||||
|
||||
if (!command.getArguments().keySet().contains(pre)) {
|
||||
for (Argument arg : command.getArguments().values()) {
|
||||
if (arg.getAliases().contains(pre)) {
|
||||
// System.out.println("ALIAS FOUND");
|
||||
pre = arg.getArgName();
|
||||
}
|
||||
}
|
||||
} // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)"
|
||||
// "wildcard"
|
||||
|
||||
if (command.getArguments().keySet().contains(pre)) {
|
||||
|
||||
offset++;
|
||||
if (command.getArguments().get(pre).getPermission() == null
|
||||
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
||||
|| DeveloperDB.hasPermission(commandBlob.getAuthorID(),
|
||||
command.getArguments().get(pre).getPermission())) {
|
||||
if (command.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
|
||||
remainsValid = false;
|
||||
}
|
||||
argumentList.put(pre, command.getArguments().get(pre));
|
||||
argumentMap.put(pre, command.getArguments().get(pre));
|
||||
if (command.getArguments().get(pre).isAutoStartRunnable()
|
||||
&& command.getArguments().get(pre).getRunnableArg() != null) {
|
||||
command.getArguments().get(pre).getRunnableArg()
|
||||
.run(new CommandBlob(commandBlob));
|
||||
command.getArguments().get(pre).getRunnableArg().run(commandBlob);
|
||||
}
|
||||
} else {
|
||||
Tools.invalidPermissions(event.getChannel(), command);
|
||||
|
@ -210,45 +208,72 @@ public class CommandManager {
|
|||
Tools.wrongUsage(event.getChannel(), command);
|
||||
remainsValid = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} else {
|
||||
|
||||
if (!command.getArguments().keySet().contains(x)) {
|
||||
for (Argument arg : command.getArguments().values()) {
|
||||
if (arg.getAliases().contains(x)) {
|
||||
// System.out.println("ALIAS FOUND");
|
||||
x = arg.getArgName();
|
||||
}
|
||||
}
|
||||
} // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)"
|
||||
// "wildcard"
|
||||
|
||||
if (command.getArguments().get(x) != null) {
|
||||
if (command.getArguments().get(x).isPrefixRequired()) {
|
||||
Tools.wrongUsage(event.getChannel(), command);
|
||||
remainsValid = false;
|
||||
}
|
||||
if (command.getArguments().get(x).getPermission() == null
|
||||
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
|
||||
|| DeveloperDB.hasPermission(commandBlob.getAuthorID(),
|
||||
command.getArguments().get(x).getPermission())) {
|
||||
if (command.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
|
||||
remainsValid = false;
|
||||
}
|
||||
argumentList.put(x, command.getArguments().get(x));
|
||||
argumentMap.put(x, command.getArguments().get(x));
|
||||
offset++;
|
||||
if (command.getArguments().get(x).isAutoStartRunnable()
|
||||
&& command.getArguments().get(x).getRunnableArg() != null) {
|
||||
command.getArguments().get(x).getRunnableArg()
|
||||
.run(new CommandBlob(commandBlob));
|
||||
command.getArguments().get(x).getRunnableArg().run(commandBlob);
|
||||
}
|
||||
} else {
|
||||
Tools.invalidPermissions(event.getChannel(), command);
|
||||
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()) {
|
||||
|
||||
Argument posix = positionalArgs.get(i - offset);
|
||||
|
||||
// if (!command.getArguments().keySet().contains(x)) {
|
||||
// for (Argument arg : command.getArguments().values()) {
|
||||
// if (arg.getAliases().contains(x)) {
|
||||
//// System.out.println("ALIAS FOUND");
|
||||
// x = arg.getArgName();
|
||||
// }
|
||||
// }
|
||||
// } // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)" "wildcard"
|
||||
|
||||
if (posix != null) {
|
||||
if (posix.getPermission() == null || DeveloperDB
|
||||
.hasPermission(commandBlob.getAuthorID(), posix.getPermission())) {
|
||||
if (posix.isSkipOriginalTaskOnRunnable()) {
|
||||
remainsValid = false;
|
||||
}
|
||||
if (positionalArgs.get(i - offset).getIsWildcard()) {
|
||||
argumentList.put(positionalArgs.get(i - offset).getArgName(),
|
||||
positionalArgs.get(i - offset).setWildCardString(x));
|
||||
if (posix.getIsWildcard()) {
|
||||
argumentMap.put(posix.getArgName(), posix.setWildCardString(x));
|
||||
} else {
|
||||
Tools.wrongUsage(event.getChannel(), command);
|
||||
remainsValid = false;
|
||||
}
|
||||
if (positionalArgs.get(i - offset).isAutoStartRunnable()
|
||||
&& positionalArgs.get(i - offset).getRunnableArg() != null) {
|
||||
positionalArgs.get(i - offset).getRunnableArg()
|
||||
.run(new CommandBlob(commandBlob));
|
||||
if (posix.isAutoStartRunnable() && posix.getRunnableArg() != null) {
|
||||
posix.getRunnableArg().run(commandBlob);
|
||||
}
|
||||
} else {
|
||||
Tools.invalidPermissions(event.getChannel(), command);
|
||||
|
@ -257,24 +282,15 @@ public class CommandManager {
|
|||
} else
|
||||
event.getChannel().sendMessage("pos is null").queue();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Tools.wrongUsage(event.getChannel(), command);
|
||||
remainsValid = false;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (command.isNSFW() && !commandBlob.getChannel().isNSFW()) {
|
||||
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())) {
|
||||
if (command.getPremiumLevel() > UserDB.getPremiumLevel(commandBlob.getAuthorID())) {
|
||||
commandBlob.getChannel().sendMessage(
|
||||
"Sorry, but you cannot run this command, it is premium subs only, of at least tier "
|
||||
+ command.getPremiumLevel())
|
||||
|
@ -282,10 +298,55 @@ public class CommandManager {
|
|||
remainsValid = false;
|
||||
}
|
||||
|
||||
if (Help.deniedPages.contains(command.getHelpPage())) {
|
||||
if (!commandBlob.isDeveloper()) {
|
||||
commandBlob.getChannel()
|
||||
.sendMessage("Sorry, but you are not allowed to run this command. . ").queue();
|
||||
remainsValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
commandBlob.setCommandManager(this);
|
||||
|
||||
if (event.isFromGuild()) {
|
||||
if (command.isNSFW() && !((TextChannel) commandBlob.getChannel()).isNSFW()) {
|
||||
commandBlob.getChannel().sendMessage(
|
||||
"Sorry, but you cannot run this command here, maybe try somewhere more private?")
|
||||
.queue();
|
||||
remainsValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (remainsValid) {
|
||||
command.runDirectCommand(commandBlob, argumentList);
|
||||
|
||||
if (command.getArguments() == null) {
|
||||
StringBuilder sB = new StringBuilder();
|
||||
for (String i : newArgs) {
|
||||
sB.append(i + " ");
|
||||
}
|
||||
argumentMap.clear();
|
||||
argumentMap.put("null", new Argument("null").setWildCardString(sB.toString().trim()));
|
||||
}
|
||||
|
||||
if (command instanceof DualCommandInterface) {
|
||||
((DualCommandInterface) command).runDualCommand(commandBlob, argumentMap);
|
||||
} else if (command instanceof GuildCommandInterface && event.isFromGuild()) {
|
||||
((GuildCommandInterface) command).runGuildCommand(commandBlob, argumentMap);
|
||||
} else if (command instanceof PrivateCommandInterface && !event.isFromGuild()) {
|
||||
((PrivateCommandInterface) command).runPrivateCommand(commandBlob, argumentMap);
|
||||
}
|
||||
|
||||
if (command instanceof GuildCommandInterface && !event.isFromGuild()
|
||||
&& !(command instanceof PrivateCommandInterface)) {
|
||||
event.getChannel()
|
||||
.sendMessage("Sorry, but you need to be in a "
|
||||
+ (UserDB.isAdvancedUser(commandBlob.getAuthorID()) ? "guild" : "server")
|
||||
+ " to use this command. . .")
|
||||
.queue();
|
||||
} else if (command instanceof PrivateCommandInterface && event.isFromGuild()
|
||||
&& !(command instanceof GuildCommandInterface)) {
|
||||
event.getChannel().sendMessage("Sorry, but this command will only run in dms. . .").queue();
|
||||
}
|
||||
}
|
||||
|
||||
if (printTime) {
|
||||
|
@ -321,220 +382,4 @@ public class CommandManager {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -2,12 +2,12 @@ package pkg.deepCurse.nopalmo.manager;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
|
||||
import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||
import pkg.deepCurse.nopalmo.global.Tools;
|
||||
|
||||
public class StatusManager {
|
||||
|
||||
|
@ -18,24 +18,19 @@ public class StatusManager {
|
|||
activityList.add(Activity.watching("my lead developer eat a watermelon whole"));
|
||||
activityList.add(Activity.watching(
|
||||
Boot.bot.getUserCache().asList().size() + " users in " + Boot.bot.getGuilds().size() + " servers"));
|
||||
activityList.add(Activity.watching("for " + Global.prefix+ "help"));
|
||||
activityList.add(Activity.competing("your mothers love"));
|
||||
activityList.add(Activity.watching("for " + GlobalDB.prefix + "help"));
|
||||
activityList.add(Activity.listening("Infected Mushroom"));
|
||||
}
|
||||
|
||||
public static void shuffle(JDA bot) {
|
||||
|
||||
int rand = new Random().nextInt(activityList.size());
|
||||
|
||||
int rand = Tools.random.nextInt(activityList.size());
|
||||
bot.getPresence().setActivity(activityList.get(rand));
|
||||
selection = rand;
|
||||
|
||||
}
|
||||
|
||||
public static void set(JDA bot, int interger) {
|
||||
|
||||
bot.getPresence().setActivity(activityList.get(interger));
|
||||
selection = interger;
|
||||
|
||||
}
|
||||
|
||||
public static void increment(JDA bot) {
|
||||
|
|
22
src/pkg/deepCurse/nopalmo/server/socket/Socks.java
Normal file
22
src/pkg/deepCurse/nopalmo/server/socket/Socks.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package pkg.deepCurse.nopalmo.server.socket;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
public class Socks {
|
||||
|
||||
// public static void sendStringSock(String address, int port, String input) {
|
||||
// try {
|
||||
// Socket cSocket = new Socket(address, port);
|
||||
// DataOutputStream dOut = new DataOutputStream(cSocket.getOutputStream());
|
||||
// dOut.writeUTF(input);
|
||||
// dOut.flush();
|
||||
// dOut.close();
|
||||
// cSocket.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package pkg.deepCurse.nopalmo.utils;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
@ -13,9 +14,10 @@ public class Locks {
|
|||
*
|
||||
* @param lockName
|
||||
* @return true on exists, false on vacant
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static boolean dirLock(String lockName) throws Exception {
|
||||
public static boolean dirLock(String lockName) throws IOException {
|
||||
|
||||
long pid = 0L;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package pkg.deepCurse.nopalmo.utils;
|
||||
|
||||
import pkg.deepCurse.nopalmo.core.Boot;
|
||||
|
||||
/**
|
||||
* this class exists for the sole reason of im lazy, as far as i know, this is
|
||||
* really bad practice and i will replace it at some point, or at least upgrade
|
||||
|
@ -11,33 +9,18 @@ import pkg.deepCurse.nopalmo.core.Boot;
|
|||
*/
|
||||
public class LogHelper {
|
||||
|
||||
public static int loggerLevel = 0;
|
||||
|
||||
public static boolean bootEnabled = true;
|
||||
public static boolean guildCommandManagerEnabled = true;
|
||||
|
||||
public static void boot(String text) {
|
||||
boot(text, 0);
|
||||
}
|
||||
|
||||
public static void boot(String text, int level) {
|
||||
if (bootEnabled && level <= loggerLevel) {
|
||||
System.out.println(Boot.class + ": " + text);
|
||||
}
|
||||
}
|
||||
// public static void log(String text, Class<?> clazz) {
|
||||
// log(text, 0, clazz);
|
||||
// }
|
||||
//
|
||||
// public static void log(String text, int level, Class<?> clazz) {
|
||||
// if (bootEnabled && level <= loggerLevel) {
|
||||
// System.out.println(clazz + ": " + text);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void crash(Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(8);
|
||||
}
|
||||
|
||||
public static void guildCommandManager(String text) {
|
||||
guildCommandManager(text);
|
||||
}
|
||||
|
||||
public static void guildCommandManager(String text, int level) {
|
||||
if (guildCommandManagerEnabled && level <= loggerLevel) {
|
||||
System.out.println(Boot.class + ": " + text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ public class UptimePing {
|
|||
|
||||
}
|
||||
|
||||
// System.out.println("fix me"); // not sure why this is here
|
||||
|
||||
if (socketAddress.getAddress() == null) {
|
||||
return -1;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue