From f4e3decd8b71bb5874096a85718fb81b64a354a0 Mon Sep 17 00:00:00 2001 From: Abhishekk24 <123966857+Abhishekk24@users.noreply.github.com> Date: Sat, 9 Dec 2023 18:50:49 +0530 Subject: [PATCH 1/3] Disabled Features should be logged --- .../org/togetherjava/tjbot/features/Features.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index 67502eca2c..e76f112f89 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -161,6 +161,16 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new JShellCommand(jshellEval)); FeatureBlacklist> blacklist = blacklistConfig.normal(); - return features.stream().filter(f -> blacklist.isEnabled(f.getClass())).toList(); + List enabledFeatures = features.stream() + .filter(f -> blacklist.isEnabled(f.getClass())) + .peek(f -> { + if (!blacklist.isEnabled(f.getClass())) { + // Log INFO level message for each disabled feature + BotCore.log.info("Feature '{}' is disabled.", f.getClass().getSimpleName()); + } + }) + .toList(); + + return enabledFeatures; } } From 3ec0ddb7eaca491e8eb0e6d76d84e804a60583db Mon Sep 17 00:00:00 2001 From: Abhishekk24 <123966857+Abhishekk24@users.noreply.github.com> Date: Sat, 9 Dec 2023 19:10:06 +0530 Subject: [PATCH 2/3] Resolved the feature and formatted the file --- .../togetherjava/tjbot/features/Features.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index e76f112f89..f85d98dd28 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -50,6 +50,8 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; /** * Utility class that offers all features that should be registered by the system, such as commands. @@ -57,7 +59,7 @@ * it with the system. *

* To add a new slash command, extend the commands returned by - * {@link #createFeatures(JDA, Database, Config)}. + * {@link #createFeatures(JDA, Database, Config, Logger)}. */ public class Features { private Features() { @@ -73,9 +75,10 @@ private Features() { * @param jda the JDA instance commands will be registered at * @param database the database of the application, which features can use to persist data * @param config the configuration features should use + * @param logger the logger instance to log disabled features * @return a collection of all features */ - public static Collection createFeatures(JDA jda, Database database, Config config) { + public static Collection createFeatures(JDA jda, Database database, Config config, Logger logger) { FeatureBlacklistConfig blacklistConfig = config.getFeatureBlacklistConfig(); JShellEval jshellEval = new JShellEval(config.getJshell()); @@ -89,7 +92,7 @@ public static Collection createFeatures(JDA jda, Database database, Con ChatGptService chatGptService = new ChatGptService(config); HelpSystemHelper helpSystemHelper = new HelpSystemHelper(config, database, chatGptService); - // NOTE The system can add special system relevant commands also by itself, + // NOTE The system can add special system-relevant commands also by itself, // hence this list may not necessarily represent the full list of all commands actually // available. Collection features = new ArrayList<>(); @@ -102,8 +105,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new ScamHistoryPurgeRoutine(scamHistoryStore)); features.add(new HelpThreadMetadataPurger(database)); features.add(new HelpThreadActivityUpdater(helpSystemHelper)); - features - .add(new AutoPruneHelperRoutine(config, helpSystemHelper, modAuditLogWriter, database)); + features.add(new AutoPruneHelperRoutine(config, helpSystemHelper, modAuditLogWriter, database)); features.add(new HelpThreadAutoArchiver(helpSystemHelper)); features.add(new LeftoverBookmarksCleanupRoutine(bookmarksSystem)); @@ -161,16 +163,11 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new JShellCommand(jshellEval)); FeatureBlacklist> blacklist = blacklistConfig.normal(); - List enabledFeatures = features.stream() - .filter(f -> blacklist.isEnabled(f.getClass())) - .peek(f -> { - if (!blacklist.isEnabled(f.getClass())) { - // Log INFO level message for each disabled feature - BotCore.log.info("Feature '{}' is disabled.", f.getClass().getSimpleName()); - } - }) - .toList(); + return features.stream().filter(f -> !blacklist.isEnabled(f.getClass())).peek(f -> { + // Log INFO level message for each disabled feature using the provided logger + String message = "Feature '" + f.getClass().getSimpleName() + "' is disabled."; + logger.info(message); + }).toList(); - return enabledFeatures; } } From 279b660a8a1fdecf2e61a5d3460a0f5f918f8f65 Mon Sep 17 00:00:00 2001 From: Abhishekk24 <123966857+Abhishekk24@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:10:25 +0530 Subject: [PATCH 3/3] Done the correction as mentioned --- .../java/org/togetherjava/tjbot/features/Features.java | 10 ++++++---- .../togetherjava/tjbot/features/system/BotCore.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index f85d98dd28..4f38a55915 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.features; import net.dv8tion.jda.api.JDA; +import org.slf4j.Logger; import org.togetherjava.tjbot.config.Config; import org.togetherjava.tjbot.config.FeatureBlacklist; @@ -50,8 +51,7 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; + /** * Utility class that offers all features that should be registered by the system, such as commands. @@ -78,7 +78,8 @@ private Features() { * @param logger the logger instance to log disabled features * @return a collection of all features */ - public static Collection createFeatures(JDA jda, Database database, Config config, Logger logger) { + public static Collection createFeatures(JDA jda, Database database, Config config, + Logger logger) { FeatureBlacklistConfig blacklistConfig = config.getFeatureBlacklistConfig(); JShellEval jshellEval = new JShellEval(config.getJshell()); @@ -105,7 +106,8 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new ScamHistoryPurgeRoutine(scamHistoryStore)); features.add(new HelpThreadMetadataPurger(database)); features.add(new HelpThreadActivityUpdater(helpSystemHelper)); - features.add(new AutoPruneHelperRoutine(config, helpSystemHelper, modAuditLogWriter, database)); + features + .add(new AutoPruneHelperRoutine(config, helpSystemHelper, modAuditLogWriter, database)); features.add(new HelpThreadAutoArchiver(helpSystemHelper)); features.add(new LeftoverBookmarksCleanupRoutine(bookmarksSystem)); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java b/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java index efa539db49..5de3b16091 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java @@ -71,7 +71,7 @@ public final class BotCore extends ListenerAdapter implements CommandProvider { */ public BotCore(JDA jda, Database database, Config config) { this.config = config; - Collection features = Features.createFeatures(jda, database, config); + Collection features = Features.createFeatures(jda, database, config, logger); // Message receivers features.stream()