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:
deepCurse 2022-02-16 10:27:27 -04:00
parent 35e9b0082f
commit 4d3c17e054
No known key found for this signature in database
GPG key ID: EEBCBB60C9DFC782
10 changed files with 152 additions and 287 deletions

View file

@ -11,7 +11,6 @@
<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="/phoenix-runtime"/>
<classpathentry combineaccessrules="false" kind="src" path="/libs-java"/>
<classpathentry combineaccessrules="false" kind="src" path="/classreloading"/>
<classpathentry kind="output" path="bin"/>

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/nopalmo.lock
/.classpath
/.project
/chaos.lock

View file

@ -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);

View file

@ -12,11 +12,11 @@ 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 {
public class LiveUpdateTestCommand implements InternalReloadable<String, String>, DualCommandInterface {
@Override
public String[] getCommandCalls() {
return new String[] {"test-update"};
return new String[] { "test-update" };
}
@Override
@ -47,6 +47,4 @@ public class LiveUpdateTestCommand implements InternalReloadable<String,String>,
return null;
}
}

View file

@ -1,9 +1,6 @@
package pkg.deepCurse.nopalmo.core;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.List;
import org.slf4j.Logger;
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.manager.CommandManager;
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.phoenixRuntime.core.PhoenixCommandManager;
import pkg.deepCurse.phoenixRuntime.core.PhoenixInterface;
import pkg.deepCurse.phoenixRuntime.core.PhoenixRuntime;
import pkg.deepCurse.phoenixRuntime.core.PhoenixSettings;
public class Boot {
@ -42,172 +35,149 @@ public class Boot {
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
// 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) -> {
// LogHelper.log("Received <phoenix-update-confirm>");
// });
PhoenixRuntime runtime = new PhoenixRuntime(settings, new PhoenixInterface() {
logger.info("Booting: <" + pid + ">");
@Override
public void boot() {
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 {
logger.info("Connecting to mariadb:nopalmo"+args[1]);
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 {
if (Locks.dirLock(isProd ? "nopalmo.lock" : "chaos.lock")) {
logger.info("Is locked, shutting down. . .");
System.exit(3);
}
} catch (IOException e1) {
e1.printStackTrace();
}
try {
logger.info("System locked. . .");
try {
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. . ."))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
bot = JDABuilder.createDefault(args[0])
.setActivity(Activity.of(ActivityType.WATCHING, "the loading bar. . ."))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setMaxBufferSize(Integer.MAX_VALUE)
.setMaxBufferSize(Integer.MAX_VALUE)
.setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL)
.setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MEMBERS,
GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_MESSAGES)
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MEMBERS,
GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_MESSAGES)
.enableCache(CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES)
.enableCache(CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES)
// .setIdle(true)
// .setIdle(true)
.setAutoReconnect(true)
.setAutoReconnect(true)
.addEventListeners(new MessageReceivedListener())
.addEventListeners(new MessageReceivedListener())
.setEnableShutdownHook(true)
.setEnableShutdownHook(true)
.build().awaitReady();
.build().awaitReady();
} catch (Exception e) {
LogHelper.crash(e);
}
} catch (Exception e) {
LogHelper.crash(e);
}
Loader.init();
Loader.init();
logger.info("Using account: " + bot.getSelfUser().getName());
logger.info("Using account: " + bot.getSelfUser().getName());
bot.getPresence().setStatus(OnlineStatus.ONLINE);
bot.getPresence().setActivity(Activity.listening("Infected Mushroom"));
bot.getPresence().setStatus(OnlineStatus.ONLINE);
bot.getPresence().setActivity(Activity.listening("Infected Mushroom"));
long bootTime = System.currentTimeMillis() - preBootTime;
long bootTime = System.currentTimeMillis() - preBootTime;
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();
}
});
loopingThread.start();
logger.info("Looping thread started. . .");
}
public void loop() {
public static void loop() {
long lastTime = System.currentTimeMillis();
long fifteenMins = lastTime;
long fiveMins = lastTime;
long threeMins = lastTime;
long lastTimeUpdateStatus = lastTime;
long lastTimeCheckUpdate = lastTime;
long lastTime = System.currentTimeMillis();
long fifteenMins = lastTime;
long fiveMins = lastTime;
long threeMins = lastTime;
long lastTimeUpdateStatus = lastTime;
long lastTimeCheckUpdate = lastTime;
long dynamicWait = Long.parseLong(GlobalDB.getGlobalValue("dynamicwait"));
long dynamicWait = Long.parseLong(GlobalDB.getGlobalValue("dynamicwait"));
while (running) {
while (running) {
long now = System.currentTimeMillis();
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
&& GlobalDB.getGlobalValue("isshufflestatusenabled").contentEquals("true")) {
lastTimeUpdateStatus = now;
StatusManager.shuffle(bot);
}
if (now > fifteenMins + 900000) {
fifteenMins = now;
}
if (now > fiveMins + 300000) {
fiveMins = now;
}
if (now > threeMins + 180000) {
threeMins = now;
}
long now = System.currentTimeMillis();
if (now > lastTime + dynamicWait) { // dynamic wait loop
lastTime = now;
try {
bot.getSelfUser();
} catch (Exception e) {
e.printStackTrace();
}
}
});
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();
if (now > lastTimeCheckUpdate + 900000) {
lastTimeCheckUpdate = now;
}
// settings.getRuntime().shutdown(0);
if (now > lastTimeUpdateStatus + dynamicWait
&& GlobalDB.getGlobalValue("isshufflestatusenabled").contentEquals("true")) {
lastTimeUpdateStatus = now;
});
StatusManager.shuffle(bot);
runtime.launch();
}
if (now > fifteenMins + 900000) {
fifteenMins = now;
}
if (now > fiveMins + 300000) {
fiveMins = now;
}
if (now > threeMins + 180000) {
threeMins = now;
}
}
}
}

View file

@ -8,6 +8,7 @@ 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;
@ -499,7 +500,8 @@ public class NopalmoDBTools {
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)) {
long time = System.currentTimeMillis();
infractions.insert().setPrimaryKey("userid", userID).setField("reason", reason)
@ -519,7 +521,8 @@ public class NopalmoDBTools {
* @param expiryDate
* @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)) {
infractions.insert().setPrimaryKey("infractionid", infractionID).setField("reason", reason)
.setField("epochdate", System.currentTimeMillis()).setField("expirydate", expiryDate)
@ -666,7 +669,7 @@ public class NopalmoDBTools {
// public static void test(Runnable runnable) {
long userID = 99;
long guildID = 99;
// long guildID = 99;
Random random = new Random();
long minutes = 0;
@ -723,7 +726,7 @@ public class NopalmoDBTools {
}
try {
InfractionDB.createInfraction(userID, String.valueOf(random.nextInt()), 0, i);
InfractionDB.createInfraction(userID, String.valueOf(random.nextInt()), 0, 0, 0, i);
} catch (Throwable e) {
eLL.add("onCreate");
eL.add(e);

View file

@ -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...

View file

@ -91,15 +91,15 @@ public class CommandManager {
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;
}
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 commandCall = split[0].toLowerCase();
@ -160,8 +160,8 @@ public class CommandManager {
}
if (DeveloperDB.developerExists(commandBlob.getAuthorID())) {
commandBlob.setDeveloper(
DeveloperDB.getDeveloperBoolean(commandBlob.getAuthorID(), "developercommandpermission"));
commandBlob.setDeveloper(DeveloperDB.getDeveloperBoolean(commandBlob.getAuthorID(),
"developercommandpermission"));
}
for (int i = 0; i < newArgs.size(); i++) {
String x = newArgs.get(i);
@ -182,7 +182,8 @@ public class CommandManager {
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)) {
@ -219,7 +220,8 @@ public class CommandManager {
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).isPrefixRequired()) {
@ -259,21 +261,18 @@ public class CommandManager {
// } // 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.getPermission() == null || DeveloperDB
.hasPermission(commandBlob.getAuthorID(), posix.getPermission())) {
if (posix.isSkipOriginalTaskOnRunnable()) {
remainsValid = false;
}
if (posix.getIsWildcard()) {
argumentMap.put(posix.getArgName(),
posix.setWildCardString(x));
argumentMap.put(posix.getArgName(), posix.setWildCardString(x));
} else {
Tools.wrongUsage(event.getChannel(), command);
remainsValid = false;
}
if (posix.isAutoStartRunnable()
&& posix.getRunnableArg() != null) {
if (posix.isAutoStartRunnable() && posix.getRunnableArg() != null) {
posix.getRunnableArg().run(commandBlob);
}
} else {

View file

@ -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;