11package net .discordjug .javabot .systems .staff_commands ;
22
33import xyz .dynxsty .dih4jda .interactions .commands .application .SlashCommand ;
4+
5+ import java .util .concurrent .ScheduledExecutorService ;
6+ import java .util .concurrent .TimeUnit ;
7+
48import lombok .extern .slf4j .Slf4j ;
59import net .discordjug .javabot .data .config .BotConfig ;
610import net .discordjug .javabot .data .h2db .message_cache .MessageCache ;
1216import net .dv8tion .jda .api .interactions .commands .build .Commands ;
1317
1418import org .jetbrains .annotations .NotNull ;
19+ import org .springframework .boot .SpringApplication ;
20+ import org .springframework .context .ConfigurableApplicationContext ;
1521
1622/**
1723 * <h3>This class represents the /redeploy command.</h3>
2632public class RedeployCommand extends SlashCommand {
2733 private final MessageCache messageCache ;
2834 private final BotConfig botConfig ;
35+ private final ScheduledExecutorService asyncPool ;
36+ private final ConfigurableApplicationContext applicationContext ;
2937
3038 /**
3139 * The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
3240 * @param messageCache A service managing recent messages
3341 * @param botConfig The main configuration of the bot
42+ * @param asyncPool The thread pool used for asynchronous operations
43+ * @param applicationContext The spring application context
3444 */
35- public RedeployCommand (MessageCache messageCache , BotConfig botConfig ) {
45+ public RedeployCommand (MessageCache messageCache , BotConfig botConfig , ScheduledExecutorService asyncPool , ConfigurableApplicationContext applicationContext ) {
3646 this .messageCache = messageCache ;
3747 this .botConfig =botConfig ;
48+ this .asyncPool = asyncPool ;
49+ this .applicationContext = applicationContext ;
3850 setCommandData (Commands .slash ("redeploy" , "(ADMIN-ONLY) Makes the bot redeploy." )
3951 .setDefaultPermissions (DefaultMemberPermissions .DISABLED )
4052 .setGuildOnly (true )
@@ -51,6 +63,14 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
5163 log .warn ("Redeploying... Requested by: " + UserUtils .getUserTag (event .getUser ()));
5264 event .reply ("**Redeploying...** This may take some time." ).queue ();
5365 messageCache .synchronize ();
54- System .exit (0 );
66+ asyncPool .shutdownNow ();
67+ try {
68+ asyncPool .awaitTermination (3 , TimeUnit .SECONDS );
69+ event .getJDA ().shutdown ();
70+ event .getJDA ().awaitShutdown (3 , TimeUnit .SECONDS );
71+ } catch (InterruptedException e ) {
72+ Thread .currentThread ().interrupt ();
73+ }
74+ SpringApplication .exit (applicationContext , () -> 0 );
5575 }
5676}
0 commit comments