From e9c510588a96bb5220f0d262a8b5626c4b384d6b Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:49:50 +0700 Subject: [PATCH] add connect and disconnect suspending for discord too --- .../chomens_bot/plugins/DiscordPlugin.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 3a73468..9619873 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java @@ -33,7 +33,7 @@ import java.util.List; import java.util.*; // please ignore my ohio code -// also this is one of the classes which has >100 lines or actually >300 LMAO +// also this is one of the classes which has >100 lines or actually >400 LMAO public class DiscordPlugin { public final JDA jda; @@ -45,6 +45,8 @@ public class DiscordPlugin { public final String discordUrl; + private int totalConnects = 0; + public boolean shuttedDown = false; public DiscordPlugin (Configuration config, JDA jda) { @@ -104,6 +106,15 @@ public class DiscordPlugin { @Override public void connecting() { + totalConnects++; + + if (totalConnects > 20) return; + else if (totalConnects == 20) { + sendMessageInstantly("Suspending connecting and disconnect messages from now on", channelId); + + return; + } + sendMessageInstantly( String.format( "Connecting to: `%s:%s`", @@ -116,6 +127,8 @@ public class DiscordPlugin { @Override public void connected (ConnectedEvent event) { + totalConnects = 0; + sendMessageInstantly( String.format( "Successfully connected to: `%s:%s`", @@ -128,6 +141,8 @@ public class DiscordPlugin { @Override public void disconnected(DisconnectedEvent event) { + if (totalConnects >= 20) return; + final String reason = ComponentUtilities.stringifyAnsi(event.getReason()); sendMessageInstantly( "Disconnected: \n" +