From 4be485df0f82e6493d0ab092b5ff8c5ddfd84d77 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 8 May 2025 18:47:55 +0700 Subject: [PATCH] feat: option to log connection status messages or not --- build-number.txt | 2 +- src/main/java/me/chayapak1/chomens_bot/Configuration.java | 1 + .../java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java | 4 ++-- .../java/me/chayapak1/chomens_bot/plugins/LoggerPlugin.java | 4 ++-- src/main/resources/default-config.yml | 2 ++ 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build-number.txt b/build-number.txt index 0f6faa9c..26807db2 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3169 \ No newline at end of file +3173 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/Configuration.java b/src/main/java/me/chayapak1/chomens_bot/Configuration.java index c0d17272..000a6b9d 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Configuration.java +++ b/src/main/java/me/chayapak1/chomens_bot/Configuration.java @@ -176,6 +176,7 @@ public class Configuration { public boolean useChat = false; public boolean useSNBTComponents = true; public boolean coreCommandSpy = true; + public boolean logConnectionStatusMessages = true; public boolean resolveSRV = true; public int reconnectDelay = 2000; public int chatQueueDelay = 125; 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 0ecd4653..4298ac1a 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java @@ -112,7 +112,7 @@ public class DiscordPlugin { @Override public void onConnecting () { - if (bot.connectAttempts > 6) return; + if (!bot.options.logConnectionStatusMessages || bot.connectAttempts > 6) return; else if (bot.connectAttempts == 6) { sendMessageInstantly(I18nUtilities.get("info.suppressing"), channelId); @@ -141,7 +141,7 @@ public class DiscordPlugin { @Override public void disconnected (final DisconnectedEvent event) { - if (bot.connectAttempts >= 6) return; + if (!bot.options.logConnectionStatusMessages || bot.connectAttempts >= 6) return; final String reason = ComponentUtilities.stringifyDiscordAnsi(event.getReason()); sendMessageInstantly( diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/LoggerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/LoggerPlugin.java index 2011d672..aa706671 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/LoggerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/LoggerPlugin.java @@ -43,7 +43,7 @@ public class LoggerPlugin implements Listener { @Override public void onConnecting () { - if (bot.connectAttempts > 10) return; + if (!bot.options.logConnectionStatusMessages || bot.connectAttempts > 10) return; else if (bot.connectAttempts == 10) { log(I18nUtilities.get("info.suppressing")); @@ -70,7 +70,7 @@ public class LoggerPlugin implements Listener { @Override public void disconnected (final DisconnectedEvent event) { - if (bot.connectAttempts >= 10) return; + if (!bot.options.logConnectionStatusMessages || bot.connectAttempts >= 10) return; final Component message = Component.translatable( I18nUtilities.get("info.disconnected"), diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index c17cf547..4d88da8b 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -147,6 +147,7 @@ bots: # useChat - when the bot tellraws it will chat instead of using the core to run tellraw # useSNBTComponents - if the server is >=1.21.5, it's pretty likely that you can enable this since 1.21.5 supports SNBT components # coreCommandSpy - set to true if server supports enabling player's commandspy through command block, defaults to true + # logConnectionStatusMessages - logs connecting and disconnected messages to console (and the log file) and discord if set to true, defaults to true # resolveSRV - whether to resolve SRV records on the server. the notchian minecraft doesn't resolve them # essentialsMessages - the messages in essentials that the bot uses for self care (no example is intentional) # coreRateLimit - will ignore commands if reached the ratelimit @@ -167,6 +168,7 @@ bots: # useChat: false # useSNBTComponents: true # coreCommandSpy: true + # logConnectionStatusMessages: true # resolveSRV: true # reconnectDelay: 2000 # chatQueueDelay: 125