diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java index 9619873..5d64eb2 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java @@ -45,7 +45,7 @@ public class DiscordPlugin { public final String discordUrl; - private int totalConnects = 0; + private final Map totalConnects = new HashMap<>(); public boolean shuttedDown = false; @@ -70,6 +70,8 @@ public class DiscordPlugin { for (Bot bot : Main.bots) { final String channelId = servers.get(bot.host + ":" + bot.port); + totalConnects.put(channelId, 0); // is this necessary? + bot.addListener(new Bot.Listener() { @Override public void loadedPlugins() { @@ -106,10 +108,12 @@ public class DiscordPlugin { @Override public void connecting() { - totalConnects++; + final int newTotalConnects = totalConnects.get(channelId) + 1; - if (totalConnects > 20) return; - else if (totalConnects == 20) { + totalConnects.put(channelId, newTotalConnects); + + if (newTotalConnects > 20) return; + else if (newTotalConnects == 20) { sendMessageInstantly("Suspending connecting and disconnect messages from now on", channelId); return; @@ -127,7 +131,7 @@ public class DiscordPlugin { @Override public void connected (ConnectedEvent event) { - totalConnects = 0; + totalConnects.put(channelId, 0); sendMessageInstantly( String.format( @@ -141,7 +145,7 @@ public class DiscordPlugin { @Override public void disconnected(DisconnectedEvent event) { - if (totalConnects >= 20) return; + if (totalConnects.get(channelId) >= 20) return; final String reason = ComponentUtilities.stringifyAnsi(event.getReason()); sendMessageInstantly(