From 5e9a1f09173de5ed63d2a24593e5b38d26389fe5 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:43:45 +0700 Subject: [PATCH] fix: stopping stuff in Main and IRCPlugin --- src/main/java/me/chayapak1/chomens_bot/Main.java | 10 +++++++--- .../me/chayapak1/chomens_bot/plugins/IRCPlugin.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/Main.java b/src/main/java/me/chayapak1/chomens_bot/Main.java index e5234bd..34c6729 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Main.java +++ b/src/main/java/me/chayapak1/chomens_bot/Main.java @@ -43,6 +43,8 @@ public class Main { private static boolean alreadyStarted = false; + private static boolean stopping = false; + private static final List alreadyAddedThreads = new ArrayList<>(); private static JDA jda = null; @@ -187,6 +189,10 @@ public class Main { // most of these are stolen from HBot public static void stop () { + if (stopping) return; + + stopping = true; + executor.shutdown(); PersistentDataUtilities.stop(); @@ -215,9 +221,7 @@ public class Main { bot.discord.sendMessageInstantly("Stopping..", channelId); } - if (ircEnabled) { - bot.irc.quit("Stopping.."); - } + if (ircEnabled) bot.irc.quit("Stopping.."); bot.stop(); } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/IRCPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/IRCPlugin.java index 6de3957..6c6a172 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/IRCPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/IRCPlugin.java @@ -169,7 +169,7 @@ public class IRCPlugin extends ListenerAdapter { } public void quit (String reason) { - bot.sendIRC().quitServer(reason); + if (bot.isConnected()) bot.sendIRC().quitServer(reason); } private void connected (Bot bot) {