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);
|
|
@ -12,11 +12,11 @@ import pkg.deepCurse.nopalmo.manager.ClassManager.InternalReloadable;
|
||||||
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
import pkg.deepCurse.nopalmo.manager.CommandBlob;
|
||||||
import qj.util.ReflectUtil;
|
import qj.util.ReflectUtil;
|
||||||
|
|
||||||
public class LiveUpdateTestCommand implements InternalReloadable<String,String>, DualCommandInterface {
|
public class LiveUpdateTestCommand implements InternalReloadable<String, String>, DualCommandInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getCommandCalls() {
|
public String[] getCommandCalls() {
|
||||||
return new String[] {"test-update"};
|
return new String[] { "test-update" };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,20 +33,18 @@ public class LiveUpdateTestCommand implements InternalReloadable<String,String>,
|
||||||
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
|
||||||
File file = new File(System.getProperty("user.dir") + "/external-src/");
|
File file = new File(System.getProperty("user.dir") + "/external-src/");
|
||||||
ClassManager<String, InternalReloadable<String, String>> manager = new ClassManager<String, InternalReloadable<String, String>>();
|
ClassManager<String, InternalReloadable<String, String>> manager = new ClassManager<String, InternalReloadable<String, String>>();
|
||||||
|
|
||||||
manager.addFile("testing", "testing.Testing", file);
|
manager.addFile("testing", "testing.Testing", file);
|
||||||
|
|
||||||
String string = (String) ReflectUtil.getField("string", manager.getClass("testing")).get(null);
|
String string = (String) ReflectUtil.getField("string", manager.getClass("testing")).get(null);
|
||||||
|
|
||||||
blob.getChannel().sendMessage(string).queue();
|
blob.getChannel().sendMessage(string).queue();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable HashMap<String, Argument> getArguments() {
|
public @Nullable HashMap<String, Argument> getArguments() {
|
||||||
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,172 +35,149 @@ 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() {
|
logger.info("Booting: <" + pid + ">");
|
||||||
|
|
||||||
@Override
|
long preBootTime = System.currentTimeMillis();
|
||||||
public void boot() {
|
|
||||||
logger.info("Booting: <" + pid + ">");
|
|
||||||
|
|
||||||
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")) {
|
||||||
NopalmoDBTools.init(isProd ? "nopalmo" : "chaos", "nopalmo", args[1]);
|
logger.info("Is locked, shutting down. . .");
|
||||||
} catch (Exception e) {
|
System.exit(3);
|
||||||
e.printStackTrace();
|
}
|
||||||
logger.info("Failed to connect\nShutting down. . .");
|
} catch (IOException e1) {
|
||||||
System.exit(4);
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
logger.info("Connected. . .");
|
|
||||||
|
|
||||||
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)
|
// bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL)
|
||||||
// .setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS)
|
// .setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS)
|
||||||
// .setActivity(Activity.watching("Loading users...")).setIdle(true)
|
// .setActivity(Activity.watching("Loading users...")).setIdle(true)
|
||||||
// .addEventListeners(new GuildMessageReceivedListener())
|
// .addEventListeners(new GuildMessageReceivedListener())
|
||||||
// .addEventListeners(new DirectMessageReceivedListener()).build().awaitReady();
|
// .addEventListeners(new DirectMessageReceivedListener()).build().awaitReady();
|
||||||
|
|
||||||
bot = JDABuilder.createDefault(args[0])
|
bot = JDABuilder.createDefault(args[0])
|
||||||
.setActivity(Activity.of(ActivityType.WATCHING, "the loading bar. . ."))
|
.setActivity(Activity.of(ActivityType.WATCHING, "the loading bar. . ."))
|
||||||
.setStatus(OnlineStatus.DO_NOT_DISTURB)
|
.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,
|
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.DIRECT_MESSAGES,
|
||||||
GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MEMBERS,
|
GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MEMBERS,
|
||||||
GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_MESSAGES)
|
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) {
|
} catch (Exception e) {
|
||||||
LogHelper.crash(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().setStatus(OnlineStatus.ONLINE);
|
||||||
bot.getPresence().setActivity(Activity.listening("Infected Mushroom"));
|
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();
|
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;
|
||||||
long fiveMins = lastTime;
|
long fiveMins = lastTime;
|
||||||
long threeMins = lastTime;
|
long threeMins = lastTime;
|
||||||
long lastTimeUpdateStatus = lastTime;
|
long lastTimeUpdateStatus = lastTime;
|
||||||
long lastTimeCheckUpdate = 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();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (now > lastTime + dynamicWait) { // dynamic wait loop
|
||||||
|
lastTime = now;
|
||||||
|
try {
|
||||||
|
bot.getSelfUser();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
runtime.setLockedRunnable(() -> {
|
if (now > lastTimeCheckUpdate + 900000) {
|
||||||
logger.info("System is locked\nSending <phoenix-update> instead. . . ");
|
lastTimeCheckUpdate = now;
|
||||||
|
|
||||||
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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -701,7 +704,7 @@ public class NopalmoDBTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Tests {
|
private class Tests {
|
||||||
|
|
||||||
public static long infractionLoop(long time, long count, long userID, Random random) {
|
public static long infractionLoop(long time, long count, long userID, Random random) {
|
||||||
|
|
||||||
long userStartTime = System.currentTimeMillis();
|
long userStartTime = System.currentTimeMillis();
|
||||||
|
@ -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...
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package pkg.deepCurse.nopalmo.manager;
|
package pkg.deepCurse.nopalmo.manager;
|
||||||
|
|
||||||
public class CommandLoop {
|
public class CommandLoop {
|
||||||
|
|
||||||
// public static add() {
|
// public static add() {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,17 +90,17 @@ public class CommandManager {
|
||||||
final String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
final String pingPrefix = "<@!" + event.getJDA().getSelfUser().getIdLong() + ">";
|
||||||
|
|
||||||
String splicer = null;
|
String splicer = null;
|
||||||
|
|
||||||
if (message.startsWith(pingPrefix + " ")) {
|
if (message.startsWith(pingPrefix + " ")) {
|
||||||
splicer = pingPrefix + " ";
|
splicer = pingPrefix + " ";
|
||||||
} else if (message.startsWith(prefix)) {
|
} else if (message.startsWith(prefix)) {
|
||||||
splicer = prefix;
|
splicer = prefix;
|
||||||
} else if (message.startsWith(pingPrefix)) {
|
} else if (message.startsWith(pingPrefix)) {
|
||||||
splicer = pingPrefix;
|
splicer = pingPrefix;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
|
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
|
||||||
final String commandCall = split[0].toLowerCase();
|
final String commandCall = split[0].toLowerCase();
|
||||||
|
|
||||||
|
@ -158,10 +158,10 @@ public class CommandManager {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
|
|
||||||
|
@ -211,7 +212,7 @@ public class CommandManager {
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (!command.getArguments().keySet().contains(x)) {
|
if (!command.getArguments().keySet().contains(x)) {
|
||||||
for (Argument arg : command.getArguments().values()) {
|
for (Argument arg : command.getArguments().values()) {
|
||||||
if (arg.getAliases().contains(x)) {
|
if (arg.getAliases().contains(x)) {
|
||||||
|
@ -219,8 +220,9 @@ 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()) {
|
||||||
Tools.wrongUsage(event.getChannel(), command);
|
Tools.wrongUsage(event.getChannel(), command);
|
||||||
|
@ -246,9 +248,9 @@ public class CommandManager {
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Argument posix = positionalArgs.get(i - offset);
|
Argument posix = positionalArgs.get(i - offset);
|
||||||
|
|
||||||
// if (!command.getArguments().keySet().contains(x)) {
|
// if (!command.getArguments().keySet().contains(x)) {
|
||||||
// for (Argument arg : command.getArguments().values()) {
|
// for (Argument arg : command.getArguments().values()) {
|
||||||
// if (arg.getAliases().contains(x)) {
|
// if (arg.getAliases().contains(x)) {
|
||||||
|
@ -257,23 +259,20 @@ 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
Reference in a new issue