Browse Source

Merge remote-tracking branch 'origin/MagicBot_DevCmds' into post-wipe-merge

master
MagicBot 2 years ago
parent
commit
9a2503b9c3
  1. 6
      src/discord/MagicBot.java
  2. 68
      src/discord/handlers/DevRequestHandler.java

6
src/discord/MagicBot.java

@ -217,6 +217,9 @@ public class MagicBot extends ListenerAdapter { @@ -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;
@ -302,7 +305,8 @@ public class MagicBot extends ListenerAdapter { @@ -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 <text> send flash message\n" +
"#flash <text> Send flash message\n" +
"#dev build <target>/restart/debug/shutdown\n" +
"#trash <blank>/detail/flush";
sendResponse(event, helpString);
}

68
src/discord/handlers/DevRequestHandler.java

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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 DevRequestHandler {
public static void handleRequest(MessageReceivedEvent event, String[] args) {
String serverCommand;
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;
serverCommand = args[0].toLowerCase().trim();
if (args.length == 2)
buildTarget = args[1].toLowerCase().trim();
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 {
Runtime.getRuntime().exec(execString);
} catch (IOException e) {
e.printStackTrace();
}
MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + buildTarget);
Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget);
}
}
}
Loading…
Cancel
Save