From 0fd5d09e3eda03fb34071751f6ce15e844e35afe Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Jan 2023 12:27:40 -0500 Subject: [PATCH 1/3] Command added to remote build on Dev server. --- src/discord/MagicBot.java | 6 ++- src/discord/handlers/DevBuildHandler.java | 48 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/discord/handlers/DevBuildHandler.java diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 8744e3e4..571442e7 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -226,6 +226,9 @@ public class MagicBot extends ListenerAdapter { case "#trash": TrashRequestHandler.handleRequest(event, args); break; + case "#devbuild": + DevBuildHandler.handleRequest(event, args); + break; default: junkbot(command, args); break; @@ -302,7 +305,8 @@ public class MagicBot extends ListenerAdapter { "#setavail true/false Toggle status of database access.\n" + "#server reboot/shutdown are your options.\n" + "#logs magicbot/world/login n (tail)\n" + - "#flash send flash message\n" + + "#flash Send flash message\n" + + "#devbuild Builds on Dev server.\n" + "#trash /detail/flush"; sendResponse(event, helpString); } diff --git a/src/discord/handlers/DevBuildHandler.java b/src/discord/handlers/DevBuildHandler.java new file mode 100644 index 00000000..a1fd5fa6 --- /dev/null +++ b/src/discord/handlers/DevBuildHandler.java @@ -0,0 +1,48 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package discord.handlers; + +import discord.MagicBot; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.pmw.tinylog.Logger; + +import java.io.IOException; + +public class DevBuildHandler { + + public static void handleRequest(MessageReceivedEvent event, String[] args) { + + String buildTarget; + String execString = ""; + + // Early exit if database unavailable or is not an admin + + if (MagicBot.isAdminEvent(event) == false) + return; + + // No command supplied? + + if (args.length != 1) + return; + + buildTarget = args[0].toLowerCase().trim(); + execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + + + if (execString.isEmpty() == false) { + try { + Runtime.getRuntime().exec(execString); + } catch (IOException e) { + e.printStackTrace(); + } + MagicBot.sendResponse(event, "MagicBot has for to built " + buildTarget + "on Dev"); + Logger.info(event.getAuthor().getName() + " built " + buildTarget + " on Dev"); + } + } +} \ No newline at end of file From c002eec8bda4166e20793895e1edef675e7f5e36 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Jan 2023 12:44:16 -0500 Subject: [PATCH 2/3] Consolidated all into one command #dev. --- src/discord/MagicBot.java | 4 +- ...ildHandler.java => DevRequestHandler.java} | 38 ++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) rename src/discord/handlers/{DevBuildHandler.java => DevRequestHandler.java} (57%) diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 571442e7..bb1351a6 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -227,7 +227,7 @@ public class MagicBot extends ListenerAdapter { TrashRequestHandler.handleRequest(event, args); break; case "#devbuild": - DevBuildHandler.handleRequest(event, args); + DevRequestHandler.handleRequest(event, args); break; default: junkbot(command, args); @@ -306,7 +306,7 @@ public class MagicBot extends ListenerAdapter { "#server reboot/shutdown are your options.\n" + "#logs magicbot/world/login n (tail)\n" + "#flash Send flash message\n" + - "#devbuild Builds on Dev server.\n" + + "#dev build /restart/debug/shutdown\n" + "#trash /detail/flush"; sendResponse(event, helpString); } diff --git a/src/discord/handlers/DevBuildHandler.java b/src/discord/handlers/DevRequestHandler.java similarity index 57% rename from src/discord/handlers/DevBuildHandler.java rename to src/discord/handlers/DevRequestHandler.java index a1fd5fa6..4a856db9 100644 --- a/src/discord/handlers/DevBuildHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -14,11 +14,12 @@ import org.pmw.tinylog.Logger; import java.io.IOException; -public class DevBuildHandler { +public class DevRequestHandler { public static void handleRequest(MessageReceivedEvent event, String[] args) { - String buildTarget; + String serverCommand; + String buildTarget = ""; String execString = ""; // Early exit if database unavailable or is not an admin @@ -31,9 +32,34 @@ public class DevBuildHandler { if (args.length != 1) return; - buildTarget = args[0].toLowerCase().trim(); - execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + serverCommand = args[0].toLowerCase().trim(); + if (args.length == 2) + buildTarget = args[1].toLowerCase().trim(); + + + // only reboot or shutdown + + if ("rebootshutdown".contains(serverCommand) == false) + return; + + switch (serverCommand) { + + case "build" : + execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + break; + case "reboot": + execString = "/bin/sh -c ./mbdevrestart.sh"; + break; + case "debug": + execString = "/bin/sh -c ./mbdevdebug.sh"; + break; + case "shutdown": + execString = "/bin/sh -c ./mbdevkill.sh"; + break; + default: + break; + } if (execString.isEmpty() == false) { try { @@ -41,8 +67,8 @@ public class DevBuildHandler { } catch (IOException e) { e.printStackTrace(); } - MagicBot.sendResponse(event, "MagicBot has for to built " + buildTarget + "on Dev"); - Logger.info(event.getAuthor().getName() + " built " + buildTarget + " on Dev"); + MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand); + Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget); } } } \ No newline at end of file From 825d1897cbf07e3d2bcd3a5e3a9c577787fa685e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Jan 2023 17:18:57 -0500 Subject: [PATCH 3/3] Removal of vestigial string restriction. Command renamed to #dev --- src/discord/MagicBot.java | 6 +++--- src/discord/handlers/DevRequestHandler.java | 8 +------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index bb1351a6..6a94647c 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -217,6 +217,9 @@ public class MagicBot extends ListenerAdapter { case "#server": ServerRequestHandler.handleRequest(event, args); break; + case "#dev": + DevRequestHandler.handleRequest(event, args); + break; case "#logs": LogsRequestHandler.handleRequest(event, args); break; @@ -226,9 +229,6 @@ public class MagicBot extends ListenerAdapter { case "#trash": TrashRequestHandler.handleRequest(event, args); break; - case "#devbuild": - DevRequestHandler.handleRequest(event, args); - break; default: junkbot(command, args); break; diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 4a856db9..e4240e44 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -37,12 +37,6 @@ public class DevRequestHandler { if (args.length == 2) buildTarget = args[1].toLowerCase().trim(); - - // only reboot or shutdown - - if ("rebootshutdown".contains(serverCommand) == false) - return; - switch (serverCommand) { case "build" : @@ -67,7 +61,7 @@ public class DevRequestHandler { } catch (IOException e) { e.printStackTrace(); } - MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand); + MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + buildTarget); Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget); } }