diff --git a/src/main/java/net/javadiscord/javabot/data/config/SystemsConfig.java b/src/main/java/net/javadiscord/javabot/data/config/SystemsConfig.java index c39d97a66..d05ac00f0 100644 --- a/src/main/java/net/javadiscord/javabot/data/config/SystemsConfig.java +++ b/src/main/java/net/javadiscord/javabot/data/config/SystemsConfig.java @@ -36,6 +36,13 @@ public class SystemsConfig { */ private int asyncPoolSize = 4; + + /** + * The location of some sort of bash script that re-compiles a new version of the Bot. + * Example in Pull Request #330. + */ + private String redeployScriptLocation = ""; + /** * Configuration for the Hikari connection pool that's used for the bot's * SQL data source. diff --git a/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java b/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java index 067df1d94..aeff56916 100644 --- a/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java @@ -7,17 +7,20 @@ import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.javadiscord.javabot.Bot; import net.javadiscord.javabot.util.Checks; +import net.javadiscord.javabot.util.ExceptionLogger; import net.javadiscord.javabot.util.Responses; import org.jetbrains.annotations.NotNull; +import java.io.IOException; + /** *

This class represents the /redeploy command.

* Command that lets staff-members redeploy the bot. *

- * This only works if the way the bot is hosted is set up correctly, for example with a bash script that handles - * compilation and a service set up with that bash script running before the bot gets started. + * This only works if the way the bot is hosted is set up correctly with a bash script that handles + * compilation and a service set up that automatically restarts the Bot. *

- * I have explained how we do it in https://github.com/Java-Discord/JavaBot/pull/195 + * I have explained how we do it in PR #330. */ @Slf4j public class RedeployCommand extends SlashCommand { @@ -39,8 +42,23 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { return; } log.warn("Redeploying... Requested by: " + event.getUser().getAsTag()); - event.reply("**Redeploying...** This may take some time.").queue(); + event.reply("Redeploying, this may take a few minutes.").queue(); + try { + Process p = new ProcessBuilder("/bin/sh", Bot.getConfig().getSystems().getRedeployScriptLocation()).start(); + p.waitFor(); + String result = new String(p.getInputStream().readAllBytes()); + if (result.contains("COMPILATION FAILED")) { + event.getHook().sendMessage("Compilation failed, redeploy canceled.").queue(); + log.warn("Redeploy canceled due to compilation error."); + return; + } else { + event.getHook().sendMessage("Compilation successful, restarting...").queue(); + } + } catch (InterruptedException | IOException e) { + ExceptionLogger.capture(e, getClass().getSimpleName()); + } Bot.getMessageCache().synchronize(); + event.getJDA().shutdown(); System.exit(0); } -} \ No newline at end of file +}