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