fix the fix

This commit is contained in:
Chayapak 2024-10-23 17:57:32 +07:00
parent e9c510588a
commit 76b4885c1c

View file

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