From f9093a370c95f2cc288aad596cf6af9e8831007a Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 8 Aug 2024 14:41:23 +0300 Subject: [PATCH] Add an `eachModule` DSL method --- README.md | 7 +++++++ .../neoforged/camelot/config/CamelotConfig.groovy | 11 +++++++++++ .../camelot/config/module/FilePreview.groovy | 15 +++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..fd9cdce --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Camelot +Camelot is a self-hosted Discord bot with various features such as tricks (custom commands), moderation commands, +file Gist creation, quotes, counters etc. +This bot is maintained and used by [NeoForged](https://neoforged.net), the Minecraft mod loader and is developed primarily for +Minecraft-related servers. It also serves as a replacement for [K9](https://www.tterrag.com/k9/), without mappings. + +Setup documentation and other information can be found on the [Wiki](https://github.com/neoforged/Camelot/wiki). diff --git a/config/src/main/groovy/net/neoforged/camelot/config/CamelotConfig.groovy b/config/src/main/groovy/net/neoforged/camelot/config/CamelotConfig.groovy index dd37072..110c879 100644 --- a/config/src/main/groovy/net/neoforged/camelot/config/CamelotConfig.groovy +++ b/config/src/main/groovy/net/neoforged/camelot/config/CamelotConfig.groovy @@ -81,6 +81,17 @@ class CamelotConfig { return conf } + /** + * Run the provided closure over every module. + * Can be used to disable each module by default. + * @param configurator the closure to run on every module + */ + void eachModule(@DelegatesTo(value = ModuleConfiguration, strategy = Closure.DELEGATE_FIRST) @ClosureParams(value = SimpleType, options = 'net.neoforged.camelot.config.module.ModuleConfiguration') Closure configurator) { + modules.values().each { + ConfigUtils.configure(it, configurator) + } + } + void validate() { if (!token) { throw new IllegalArgumentException('Bot API Token must be provided!') diff --git a/config/src/main/groovy/net/neoforged/camelot/config/module/FilePreview.groovy b/config/src/main/groovy/net/neoforged/camelot/config/module/FilePreview.groovy index 6e9264b..725a396 100644 --- a/config/src/main/groovy/net/neoforged/camelot/config/module/FilePreview.groovy +++ b/config/src/main/groovy/net/neoforged/camelot/config/module/FilePreview.groovy @@ -8,6 +8,13 @@ import org.kohsuke.github.GitHub *

* If enabled, messages containing attachments with specific suffixes will have a reaction added by the bot. * If the reaction is clicked by another user, a Gist will be created from the attachments of the message. + *

+ * For this module to work, you must configure {@link #auth} with a Personal Access Token that has the {@code gist} permission: + *

+module(FilePreview) {
+    auth = patAuthentication({@code })
+}
+ * 
*/ @CompileStatic class FilePreview extends ModuleConfiguration implements GHAuth { @@ -25,6 +32,14 @@ class FilePreview extends ModuleConfiguration implements GHAuth { /** * The file extensions that can be gisted. + *

+ * To avoid replacing the default extensions, you should use the {@code +=} syntax to append other extensions: + *

+ module(FilePreview) {
+     // Whitelist the .abcd extension
+     extensions += ['abcd']
+ }
+     * 
*/ Set extensions = DEFAULT_EXTENSIONS }