From d63c12f0f4b4f6cad2f4ec57742ef6bfc3965ebd Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Sat, 1 Jun 2024 15:40:37 +0300 Subject: [PATCH] Make counters a module --- config/build.gradle | 8 ++++++ .../camelot/config/module/Counters.groovy | 14 ++++++++++ .../src/sample}/groovy/sample.camelot.groovy | 0 sample-config/build.gradle | 11 -------- settings.gradle | 1 - .../java/net/neoforged/camelot/BotMain.java | 3 +-- .../camelot/module/CountersModule.java | 26 +++++++++++++++++++ 7 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 config/src/main/groovy/net/neoforged/camelot/config/module/Counters.groovy rename {sample-config/src/main => config/src/sample}/groovy/sample.camelot.groovy (100%) delete mode 100644 sample-config/build.gradle create mode 100644 src/main/java/net/neoforged/camelot/module/CountersModule.java diff --git a/config/build.gradle b/config/build.gradle index 04aa15a..30ee594 100644 --- a/config/build.gradle +++ b/config/build.gradle @@ -13,6 +13,12 @@ rootProject.gradleutils { setupSigning(project: this.project, signAllPublications: true) } +sourceSets { + sample { + compileClasspath += main.compileClasspath + } +} + repositories { mavenCentral() } @@ -33,6 +39,8 @@ dependencies { api "org.apache.groovy:groovy:${project.groovy_version}" api "org.apache.groovy:groovy-contracts:${project.groovy_version}" implementation group: 'org.kohsuke', name: 'github-api', version: project.ghapi_version + + sampleCompileOnly(sourceSets.main.output) } publishing { diff --git a/config/src/main/groovy/net/neoforged/camelot/config/module/Counters.groovy b/config/src/main/groovy/net/neoforged/camelot/config/module/Counters.groovy new file mode 100644 index 0000000..4538e66 --- /dev/null +++ b/config/src/main/groovy/net/neoforged/camelot/config/module/Counters.groovy @@ -0,0 +1,14 @@ +package net.neoforged.camelot.config.module + +import groovy.transform.CompileStatic + +/** + * The module responsible for counters.
+ *

+ * Counters can be used for... counting things in server.
+ * A counter can be incremented by sending {@code ++} in chat (and {@code --} for + * decrementing), and queried using {@code ==}. + */ +@CompileStatic +class Counters extends ModuleConfiguration { +} diff --git a/sample-config/src/main/groovy/sample.camelot.groovy b/config/src/sample/groovy/sample.camelot.groovy similarity index 100% rename from sample-config/src/main/groovy/sample.camelot.groovy rename to config/src/sample/groovy/sample.camelot.groovy diff --git a/sample-config/build.gradle b/sample-config/build.gradle deleted file mode 100644 index 6168c22..0000000 --- a/sample-config/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id 'groovy' -} - -repositories { - mavenCentral() -} - -dependencies { - implementation project(':config') -} diff --git a/settings.gradle b/settings.gradle index 8f43035..21626a7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,3 @@ plugins { rootProject.name = 'Camelot' include ':config' -include ':sample-config' diff --git a/src/main/java/net/neoforged/camelot/BotMain.java b/src/main/java/net/neoforged/camelot/BotMain.java index 1ec2983..6e5d06e 100644 --- a/src/main/java/net/neoforged/camelot/BotMain.java +++ b/src/main/java/net/neoforged/camelot/BotMain.java @@ -22,7 +22,6 @@ import net.neoforged.camelot.db.transactionals.LoggingChannelsDAO; import net.neoforged.camelot.db.transactionals.PendingUnbansDAO; import net.neoforged.camelot.db.transactionals.StatsDAO; -import net.neoforged.camelot.listener.CountersListener; import net.neoforged.camelot.listener.DismissListener; import net.neoforged.camelot.log.ChannelLogging; import net.neoforged.camelot.log.JoinsLogging; @@ -248,7 +247,7 @@ public static void main(String[] args) { .setActivity(Activity.customStatus("Listening for your commands")) .setMemberCachePolicy(MemberCachePolicy.ALL) .addEventListeners(new ModerationActionRecorder()) - .addEventListeners(BUTTON_MANAGER, new CountersListener(), new DismissListener()); + .addEventListeners(BUTTON_MANAGER, new DismissListener()); try { Database.init(); diff --git a/src/main/java/net/neoforged/camelot/module/CountersModule.java b/src/main/java/net/neoforged/camelot/module/CountersModule.java new file mode 100644 index 0000000..dbfaf29 --- /dev/null +++ b/src/main/java/net/neoforged/camelot/module/CountersModule.java @@ -0,0 +1,26 @@ +package net.neoforged.camelot.module; + +import com.google.auto.service.AutoService; +import net.dv8tion.jda.api.JDABuilder; +import net.neoforged.camelot.config.module.Counters; +import net.neoforged.camelot.listener.CountersListener; + +/** + * The module for counters. + */ +@AutoService(Counters.class) +public class CountersModule extends CamelotModule.Base { + public CountersModule() { + super(Counters.class); + } + + @Override + public String id() { + return "counters"; + } + + @Override + public void registerListeners(JDABuilder builder) { + builder.addEventListeners(new CountersListener()); + } +}