Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -51,13 +52,14 @@
import java.util.ArrayList;
import java.util.Collection;


/**
* Utility class that offers all features that should be registered by the system, such as commands.
* New features have to be added here, where {@link BotCore} will then pick it up from and register
* it with the system.
* <p>
* 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() {
Expand All @@ -73,9 +75,11 @@ 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<Feature> createFeatures(JDA jda, Database database, Config config) {
public static Collection<Feature> createFeatures(JDA jda, Database database, Config config,
Logger logger) {
Comment on lines +81 to +82
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y don't u just create a logger in this class

FeatureBlacklistConfig blacklistConfig = config.getFeatureBlacklistConfig();
JShellEval jshellEval = new JShellEval(config.getJshell());

Expand All @@ -89,7 +93,7 @@ public static Collection<Feature> 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<Feature> features = new ArrayList<>();
Expand Down Expand Up @@ -161,6 +165,11 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(new JShellCommand(jshellEval));

FeatureBlacklist<Class<?>> blacklist = blacklistConfig.normal();
return features.stream().filter(f -> blacklist.isEnabled(f.getClass())).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();
Comment on lines +168 to +172
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as u can see using peek is forbidden, so just put the log in filter method.

Also ur changing the logic before it removed the blacklisted features and kept all others, now it'll do the opposite


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class BotCore extends ListenerAdapter implements CommandProvider {
*/
public BotCore(JDA jda, Database database, Config config) {
this.config = config;
Collection<Feature> features = Features.createFeatures(jda, database, config);
Collection<Feature> features = Features.createFeatures(jda, database, config, logger);

// Message receivers
features.stream()
Expand Down