You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.5 KiB
74 lines
2.5 KiB
2 years ago
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||
|
// 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;
|
||
|
|
||
2 years ago
|
public class DevRequestHandler {
|
||
2 years ago
|
|
||
|
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||
|
|
||
2 years ago
|
String serverCommand;
|
||
|
String buildTarget = "";
|
||
2 years ago
|
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;
|
||
|
|
||
2 years ago
|
serverCommand = args[0].toLowerCase().trim();
|
||
2 years ago
|
|
||
2 years ago
|
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;
|
||
|
}
|
||
2 years ago
|
|
||
|
if (execString.isEmpty() == false) {
|
||
|
try {
|
||
|
Runtime.getRuntime().exec(execString);
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
2 years ago
|
MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand);
|
||
|
Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget);
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|