add connect and disconnect suspending for discord too

This commit is contained in:
Chayapak 2024-10-23 13:49:50 +07:00
parent bb86bf80c7
commit e9c510588a

View file

@ -33,7 +33,7 @@ import java.util.List;
import java.util.*; import java.util.*;
// please ignore my ohio code // 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 class DiscordPlugin {
public final JDA jda; public final JDA jda;
@ -45,6 +45,8 @@ public class DiscordPlugin {
public final String discordUrl; public final String discordUrl;
private int totalConnects = 0;
public boolean shuttedDown = false; public boolean shuttedDown = false;
public DiscordPlugin (Configuration config, JDA jda) { public DiscordPlugin (Configuration config, JDA jda) {
@ -104,6 +106,15 @@ public class DiscordPlugin {
@Override @Override
public void connecting() { public void connecting() {
totalConnects++;
if (totalConnects > 20) return;
else if (totalConnects == 20) {
sendMessageInstantly("Suspending connecting and disconnect messages from now on", channelId);
return;
}
sendMessageInstantly( sendMessageInstantly(
String.format( String.format(
"Connecting to: `%s:%s`", "Connecting to: `%s:%s`",
@ -116,6 +127,8 @@ public class DiscordPlugin {
@Override @Override
public void connected (ConnectedEvent event) { public void connected (ConnectedEvent event) {
totalConnects = 0;
sendMessageInstantly( sendMessageInstantly(
String.format( String.format(
"Successfully connected to: `%s:%s`", "Successfully connected to: `%s:%s`",
@ -128,6 +141,8 @@ public class DiscordPlugin {
@Override @Override
public void disconnected(DisconnectedEvent event) { public void disconnected(DisconnectedEvent event) {
if (totalConnects >= 20) return;
final String reason = ComponentUtilities.stringifyAnsi(event.getReason()); final String reason = ComponentUtilities.stringifyAnsi(event.getReason());
sendMessageInstantly( sendMessageInstantly(
"Disconnected: \n" + "Disconnected: \n" +