From 65c79f9d9b3c999be06396c25be696f6fa945ba8 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 25 Sep 2023 18:32:23 +0700 Subject: [PATCH] stop logging the disconnect and connect messages when too much --- .../chomens_bot/plugins/LoggerPlugin.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java index 60cf324..04eeb5a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java @@ -14,12 +14,23 @@ public class LoggerPlugin extends ChatPlugin.Listener { public boolean logToConsole = true; + private int totalConnects = 0; + public LoggerPlugin(Bot bot) { this.bot = bot; bot.addListener(new Bot.Listener() { @Override public void connecting() { + totalConnects++; + + if (totalConnects > 20) return; + else if (totalConnects == 20) { + log("Suspending connecting and disconnect messages from now on"); + + return; + } + log( String.format( "Connecting to: %s:%s", @@ -39,6 +50,8 @@ public class LoggerPlugin extends ChatPlugin.Listener { ) ); + totalConnects = 0; + if (addedListener) return; bot.chat.addListener(LoggerPlugin.this); addedListener = true; @@ -46,6 +59,8 @@ public class LoggerPlugin extends ChatPlugin.Listener { @Override public void disconnected (DisconnectedEvent event) { + if (totalConnects >= 20) return; + final Component reason = event.getReason(); final String message = "Disconnected from " + bot.host + ":" + bot.port + ", reason: ";