77import net .dv8tion .jda .api .interactions .commands .build .Commands ;
88import net .javadiscord .javabot .Bot ;
99import net .javadiscord .javabot .util .Checks ;
10+ import net .javadiscord .javabot .util .ExceptionLogger ;
1011import net .javadiscord .javabot .util .Responses ;
1112import 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