removing phoenix as it is in an unfinished state, and is being replaced
Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
parent
35e9b0082f
commit
4d3c17e054
10 changed files with 152 additions and 287 deletions
|
@ -11,7 +11,6 @@
|
||||||
<classpathentry kind="lib" path="/libs-java/discord/JDA-4.4.0_350-withDependencies.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-api-1.7.9.jar"/>
|
||||||
<classpathentry kind="lib" path="/libs-java/logging/slf4j-simple-1.7.9.jar"/>
|
<classpathentry kind="lib" path="/libs-java/logging/slf4j-simple-1.7.9.jar"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/phoenix-runtime"/>
|
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/libs-java"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/libs-java"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/classreloading"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/classreloading"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
/nopalmo.lock
|
/nopalmo.lock
|
||||||
/.classpath
|
/.classpath
|
||||||
/.project
|
/.project
|
||||||
|
/chaos.lock
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
3 : Failed to lock
|
|
||||||
4 : Failed to connect to maria
|
|
||||||
7 : Shut down by developer
|
Failed to lock
|
||||||
8 : LoggerHelper.crash(Exception e);
|
Failed to connect to maria
|
||||||
|
|
||||||
|
|
||||||
|
Shut down by developer
|
||||||
|
LoggerHelper.crash(Exception e);
|
|
@ -47,6 +47,4 @@ public class LiveUpdateTestCommand implements InternalReloadable<String,String>,
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package pkg.deepCurse.nopalmo.core;
|
package pkg.deepCurse.nopalmo.core;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.impl.SimpleLoggerFactory;
|
import org.slf4j.impl.SimpleLoggerFactory;
|
||||||
|
@ -22,12 +19,8 @@ import pkg.deepCurse.nopalmo.core.database.NopalmoDBTools.Tools.GlobalDB;
|
||||||
import pkg.deepCurse.nopalmo.listener.MessageReceivedListener;
|
import pkg.deepCurse.nopalmo.listener.MessageReceivedListener;
|
||||||
import pkg.deepCurse.nopalmo.manager.CommandManager;
|
import pkg.deepCurse.nopalmo.manager.CommandManager;
|
||||||
import pkg.deepCurse.nopalmo.manager.StatusManager;
|
import pkg.deepCurse.nopalmo.manager.StatusManager;
|
||||||
import pkg.deepCurse.nopalmo.server.socket.Socks;
|
import pkg.deepCurse.nopalmo.utils.Locks;
|
||||||
import pkg.deepCurse.nopalmo.utils.LogHelper;
|
import pkg.deepCurse.nopalmo.utils.LogHelper;
|
||||||
import pkg.deepCurse.phoenixRuntime.core.PhoenixCommandManager;
|
|
||||||
import pkg.deepCurse.phoenixRuntime.core.PhoenixInterface;
|
|
||||||
import pkg.deepCurse.phoenixRuntime.core.PhoenixRuntime;
|
|
||||||
import pkg.deepCurse.phoenixRuntime.core.PhoenixSettings;
|
|
||||||
|
|
||||||
public class Boot {
|
public class Boot {
|
||||||
|
|
||||||
|
@ -42,42 +35,34 @@ public class Boot {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
PhoenixSettings settings = new PhoenixSettings().setAuthentication(args[3]).setCommandSplitRegex(", ")
|
|
||||||
.setCommandManager(new PhoenixCommandManager());
|
|
||||||
|
|
||||||
// TODO using join and a while last time + 15000 < current time, then kill and
|
// TODO using join and a while last time + 15000 < current time, then kill and
|
||||||
// proceed as a failure
|
// proceed as a failure
|
||||||
|
|
||||||
settings.commandManager.addCommand("phoenix-update", (PhoenixRuntime runtime, List<String> commandArgs) -> {
|
|
||||||
logger.info("Received <phoenix-update>");
|
|
||||||
|
|
||||||
Socks.sendStringSock(settings.address, settings.commonPort, "phoenix-update-confirm");
|
|
||||||
|
|
||||||
logger.info("Sent <phoenix-update-confirm>");
|
|
||||||
|
|
||||||
if (bot != null) {
|
|
||||||
bot.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.shutdown(9);
|
|
||||||
});
|
|
||||||
|
|
||||||
// settings.actions.put("phoenix-update-confirm", (PhoenixRuntime runtime) -> {
|
// settings.actions.put("phoenix-update-confirm", (PhoenixRuntime runtime) -> {
|
||||||
// LogHelper.log("Received <phoenix-update-confirm>");
|
// LogHelper.log("Received <phoenix-update-confirm>");
|
||||||
// });
|
// });
|
||||||
|
|
||||||
PhoenixRuntime runtime = new PhoenixRuntime(settings, new PhoenixInterface() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void boot() {
|
|
||||||
logger.info("Booting: <" + pid + ">");
|
logger.info("Booting: <" + pid + ">");
|
||||||
|
|
||||||
long preBootTime = System.currentTimeMillis();
|
long preBootTime = System.currentTimeMillis();
|
||||||
|
|
||||||
isProd = args[2].contentEquals("prod");
|
isProd = args[2].contentEquals("prod");
|
||||||
|
|
||||||
|
logger.info("Locking System");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Connecting to mariadb:nopalmo"+args[1]);
|
if (Locks.dirLock(isProd ? "nopalmo.lock" : "chaos.lock")) {
|
||||||
|
logger.info("Is locked, shutting down. . .");
|
||||||
|
System.exit(3);
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("System locked. . .");
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info("Connecting to mariadb:nopalmo");
|
||||||
NopalmoDBTools.init(isProd ? "nopalmo" : "chaos", "nopalmo", args[1]);
|
NopalmoDBTools.init(isProd ? "nopalmo" : "chaos", "nopalmo", args[1]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -132,11 +117,18 @@ public class Boot {
|
||||||
|
|
||||||
logger.info("Taken " + bootTime + "ms to boot");
|
logger.info("Taken " + bootTime + "ms to boot");
|
||||||
|
|
||||||
logger.info("Starting loop");
|
logger.info("Starting looping thread");
|
||||||
|
Thread loopingThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
loopingThread.start();
|
||||||
|
logger.info("Looping thread started. . .");
|
||||||
|
}
|
||||||
|
|
||||||
public void loop() {
|
public static void loop() {
|
||||||
|
|
||||||
long lastTime = System.currentTimeMillis();
|
long lastTime = System.currentTimeMillis();
|
||||||
long fifteenMins = lastTime;
|
long fifteenMins = lastTime;
|
||||||
|
@ -186,28 +178,6 @@ public class Boot {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
runtime.setLockedRunnable(() -> {
|
|
||||||
logger.info("System is locked\nSending <phoenix-update> instead. . . ");
|
|
||||||
|
|
||||||
try {
|
|
||||||
Socket cSocket = new Socket("127.0.0.1", settings.commonPort);
|
|
||||||
DataOutputStream dOut = new DataOutputStream(cSocket.getOutputStream());
|
|
||||||
dOut.writeUTF("phoenix-update");
|
|
||||||
dOut.flush();
|
|
||||||
dOut.close();
|
|
||||||
cSocket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// settings.getRuntime().shutdown(0);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
runtime.launch();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.fluentjdbc.DbContext;
|
import org.fluentjdbc.DbContext;
|
||||||
import org.fluentjdbc.DbContextConnection;
|
import org.fluentjdbc.DbContextConnection;
|
||||||
import org.fluentjdbc.DbContextTable;
|
import org.fluentjdbc.DbContextTable;
|
||||||
|
@ -499,7 +500,8 @@ public class NopalmoDBTools {
|
||||||
|
|
||||||
public class InfractionDB {
|
public class InfractionDB {
|
||||||
|
|
||||||
public static long createInfraction(long userID, String reason, long expiryDate) {
|
public static long createInfraction(long userID, String reason, long expiryDate, long guildID,
|
||||||
|
long invokerID) {
|
||||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
infractions.insert().setPrimaryKey("userid", userID).setField("reason", reason)
|
infractions.insert().setPrimaryKey("userid", userID).setField("reason", reason)
|
||||||
|
@ -519,7 +521,8 @@ public class NopalmoDBTools {
|
||||||
* @param expiryDate
|
* @param expiryDate
|
||||||
* @param infractionID
|
* @param infractionID
|
||||||
*/
|
*/
|
||||||
public static void createInfraction(long userID, String reason, long expiryDate, long infractionID) {
|
public static void createInfraction(long userID, String reason, long expiryDate, long guildID,
|
||||||
|
long invokerID, long infractionID) {
|
||||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
||||||
infractions.insert().setPrimaryKey("infractionid", infractionID).setField("reason", reason)
|
infractions.insert().setPrimaryKey("infractionid", infractionID).setField("reason", reason)
|
||||||
.setField("epochdate", System.currentTimeMillis()).setField("expirydate", expiryDate)
|
.setField("epochdate", System.currentTimeMillis()).setField("expirydate", expiryDate)
|
||||||
|
@ -666,7 +669,7 @@ public class NopalmoDBTools {
|
||||||
// public static void test(Runnable runnable) {
|
// public static void test(Runnable runnable) {
|
||||||
|
|
||||||
long userID = 99;
|
long userID = 99;
|
||||||
long guildID = 99;
|
// long guildID = 99;
|
||||||
|
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
long minutes = 0;
|
long minutes = 0;
|
||||||
|
@ -723,7 +726,7 @@ public class NopalmoDBTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InfractionDB.createInfraction(userID, String.valueOf(random.nextInt()), 0, i);
|
InfractionDB.createInfraction(userID, String.valueOf(random.nextInt()), 0, 0, 0, i);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
eLL.add("onCreate");
|
eLL.add("onCreate");
|
||||||
eL.add(e);
|
eL.add(e);
|
||||||
|
|
|
@ -1,111 +0,0 @@
|
||||||
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 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 boolean guildExists(long guildID) {
|
|
||||||
try (DbContextConnection idk = context.startConnection(dataSource)) {
|
|
||||||
return guilds.query().where("guildid", guildID).singleLong("guildid").isPresent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TYPE
|
|
||||||
|
|
||||||
add
|
|
||||||
remove
|
|
||||||
exists
|
|
||||||
set(long string boolean)
|
|
||||||
get(long string boolean)
|
|
||||||
|
|
||||||
misc interactions...
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -160,8 +160,8 @@ public class CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DeveloperDB.developerExists(commandBlob.getAuthorID())) {
|
if (DeveloperDB.developerExists(commandBlob.getAuthorID())) {
|
||||||
commandBlob.setDeveloper(
|
commandBlob.setDeveloper(DeveloperDB.getDeveloperBoolean(commandBlob.getAuthorID(),
|
||||||
DeveloperDB.getDeveloperBoolean(commandBlob.getAuthorID(), "developercommandpermission"));
|
"developercommandpermission"));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < newArgs.size(); i++) {
|
for (int i = 0; i < newArgs.size(); i++) {
|
||||||
String x = newArgs.get(i);
|
String x = newArgs.get(i);
|
||||||
|
@ -182,7 +182,8 @@ public class CommandManager {
|
||||||
pre = arg.getArgName();
|
pre = arg.getArgName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)" "wildcard"
|
} // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)"
|
||||||
|
// "wildcard"
|
||||||
|
|
||||||
if (command.getArguments().keySet().contains(pre)) {
|
if (command.getArguments().keySet().contains(pre)) {
|
||||||
|
|
||||||
|
@ -219,7 +220,8 @@ public class CommandManager {
|
||||||
x = arg.getArgName();
|
x = arg.getArgName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)" "wildcard"
|
} // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)"
|
||||||
|
// "wildcard"
|
||||||
|
|
||||||
if (command.getArguments().get(x) != null) {
|
if (command.getArguments().get(x) != null) {
|
||||||
if (command.getArguments().get(x).isPrefixRequired()) {
|
if (command.getArguments().get(x).isPrefixRequired()) {
|
||||||
|
@ -259,21 +261,18 @@ public class CommandManager {
|
||||||
// } // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)" "wildcard"
|
// } // TODO RIP ROOT ALIAS PREFIX IN FAVOR OF "--long-name" "-s (shortname)" "wildcard"
|
||||||
|
|
||||||
if (posix != null) {
|
if (posix != null) {
|
||||||
if (posix.getPermission() == null
|
if (posix.getPermission() == null || DeveloperDB
|
||||||
|| DeveloperDB.hasPermission(commandBlob.getAuthorID(),
|
.hasPermission(commandBlob.getAuthorID(), posix.getPermission())) {
|
||||||
posix.getPermission())) {
|
|
||||||
if (posix.isSkipOriginalTaskOnRunnable()) {
|
if (posix.isSkipOriginalTaskOnRunnable()) {
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
}
|
}
|
||||||
if (posix.getIsWildcard()) {
|
if (posix.getIsWildcard()) {
|
||||||
argumentMap.put(posix.getArgName(),
|
argumentMap.put(posix.getArgName(), posix.setWildCardString(x));
|
||||||
posix.setWildCardString(x));
|
|
||||||
} else {
|
} else {
|
||||||
Tools.wrongUsage(event.getChannel(), command);
|
Tools.wrongUsage(event.getChannel(), command);
|
||||||
remainsValid = false;
|
remainsValid = false;
|
||||||
}
|
}
|
||||||
if (posix.isAutoStartRunnable()
|
if (posix.isAutoStartRunnable() && posix.getRunnableArg() != null) {
|
||||||
&& posix.getRunnableArg() != null) {
|
|
||||||
posix.getRunnableArg().run(commandBlob);
|
posix.getRunnableArg().run(commandBlob);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package pkg.deepCurse.nopalmo.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
@ -13,9 +14,10 @@ public class Locks {
|
||||||
*
|
*
|
||||||
* @param lockName
|
* @param lockName
|
||||||
* @return true on exists, false on vacant
|
* @return true on exists, false on vacant
|
||||||
|
* @throws IOException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static boolean dirLock(String lockName) throws Exception {
|
public static boolean dirLock(String lockName) throws IOException {
|
||||||
|
|
||||||
long pid = 0L;
|
long pid = 0L;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue