-
-
Notifications
You must be signed in to change notification settings - Fork 101
Disabled Features should be logged #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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() { | ||
|
@@ -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) { | ||
FeatureBlacklistConfig blacklistConfig = config.getFeatureBlacklistConfig(); | ||
JShellEval jshellEval = new JShellEval(config.getJshell()); | ||
|
||
|
@@ -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<>(); | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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