Skip to content

Commit

Permalink
Add an eachModule DSL method
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Aug 8, 2024
1 parent b4e8fed commit f9093a3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import org.kohsuke.github.GitHub
* <p>
* 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.
* <p>
* For this module to work, you must configure {@link #auth} with a Personal Access Token that has the {@code gist} permission:
* <pre class="groovyTestCase">
module(FilePreview) {
auth = patAuthentication({@code <pat>})
}
* </pre>
*/
@CompileStatic
class FilePreview extends ModuleConfiguration implements GHAuth {
Expand All @@ -25,6 +32,14 @@ class FilePreview extends ModuleConfiguration implements GHAuth {

/**
* The file extensions that can be gisted.
* <p>
* To avoid replacing the default extensions, you should use the {@code +=} syntax to append other extensions:
* <pre class="groovyTestCase">
module(FilePreview) {
// Whitelist the .abcd extension
extensions += ['abcd']
}
* </pre>
*/
Set<String> extensions = DEFAULT_EXTENSIONS
}

0 comments on commit f9093a3

Please sign in to comment.