Skip to content

Commit bc99346

Browse files
committed
Imrpoved Redeploy System
1 parent a2f8cb4 commit bc99346

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/main/java/net/javadiscord/javabot/data/config/SystemsConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class SystemsConfig {
3636
*/
3737
private int asyncPoolSize = 4;
3838

39+
40+
/**
41+
* The location of some sort of bash script that re-compiles a new version of the Bot.
42+
*/
43+
private String redeployScriptLocation = "";
44+
3945
/**
4046
* Configuration for the Hikari connection pool that's used for the bot's
4147
* SQL data source.

src/main/java/net/javadiscord/javabot/systems/staff_commands/RedeployCommand.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
import net.dv8tion.jda.api.interactions.commands.build.Commands;
88
import net.javadiscord.javabot.Bot;
99
import net.javadiscord.javabot.util.Checks;
10+
import net.javadiscord.javabot.util.ExceptionLogger;
1011
import net.javadiscord.javabot.util.Responses;
1112
import org.jetbrains.annotations.NotNull;
1213

1314
/**
1415
* <h3>This class represents the /redeploy command.</h3>
1516
* Command that lets staff-members redeploy the bot.
1617
* <p>
17-
* This only works if the way the bot is hosted is set up correctly, for example with a bash script that handles
18-
* compilation and a service set up with that bash script running before the bot gets started.
18+
* This only works if the way the bot is hosted is set up correctly with a bash script that handles
19+
* compilation and a service set up that automatically restarts the Bot..
1920
* <p>
2021
* I have explained how we do it in https://github.com/Java-Discord/JavaBot/pull/195
2122
*/
@@ -39,7 +40,21 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
3940
return;
4041
}
4142
log.warn("Redeploying... Requested by: " + event.getUser().getAsTag());
42-
event.reply("**Redeploying...** This may take some time.").queue();
43+
event.reply("Redeploying, this may take a few minutes.").queue();
44+
try {
45+
Process p = new ProcessBuilder("/bin/sh", Bot.config.getSystems().getRedeployScriptLocation()).start();
46+
p.waitFor();
47+
String result = new String(p.getInputStream().readAllBytes());
48+
if (result.contains("COMPILATION FAILED")) {
49+
event.getHook().sendMessage("Compilation failed, redeploy canceled.").queue();
50+
log.warn("Redeploy canceled due to compilation error.");
51+
return;
52+
} else {
53+
event.getHook().sendMessage("Compilation successful, restarting...").queue();
54+
}
55+
} catch (Exception e) {
56+
ExceptionLogger.capture(e, getClass().getSimpleName());
57+
}
4358
Bot.messageCache.synchronize();
4459
System.exit(0);
4560
}

0 commit comments

Comments
 (0)