From 35ad492cd26fc8d18477765f47ba28e3c7e7d1c2 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Mon, 27 May 2024 23:22:37 +0300 Subject: [PATCH] Split moderation commands into their own module --- .../camelot/config/module/Moderation.groovy | 20 +++++++++ .../camelot/config/module/package-info.java | 4 ++ .../neoforged/camelot/commands/Commands.java | 16 +------- .../camelot/configuration/ConfigMigrator.java | 2 +- .../camelot/module/BanAppealModule.java | 4 +- .../camelot/module/InfoChannelsModule.java | 6 ++- .../camelot/module/ModerationModule.java | 41 +++++++++++++++++++ 7 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 config/src/main/groovy/net/neoforged/camelot/config/module/Moderation.groovy create mode 100644 config/src/main/groovy/net/neoforged/camelot/config/module/package-info.java create mode 100644 src/main/java/net/neoforged/camelot/module/ModerationModule.java diff --git a/config/src/main/groovy/net/neoforged/camelot/config/module/Moderation.groovy b/config/src/main/groovy/net/neoforged/camelot/config/module/Moderation.groovy new file mode 100644 index 0000000..4e2610e --- /dev/null +++ b/config/src/main/groovy/net/neoforged/camelot/config/module/Moderation.groovy @@ -0,0 +1,20 @@ +package net.neoforged.camelot.config.module + +import groovy.transform.CompileStatic + +/** + * The module that provides moderation commands. + *

+ * The commands included in this module are: + *

+ */ +@CompileStatic +class Moderation extends ModuleConfiguration { +} diff --git a/config/src/main/groovy/net/neoforged/camelot/config/module/package-info.java b/config/src/main/groovy/net/neoforged/camelot/config/module/package-info.java new file mode 100644 index 0000000..96d1e7d --- /dev/null +++ b/config/src/main/groovy/net/neoforged/camelot/config/module/package-info.java @@ -0,0 +1,4 @@ +/** + * The package containing the configurations of all Camelot modules. + */ +package net.neoforged.camelot.config.module; diff --git a/src/main/java/net/neoforged/camelot/commands/Commands.java b/src/main/java/net/neoforged/camelot/commands/Commands.java index e18fb2f..a06de7d 100644 --- a/src/main/java/net/neoforged/camelot/commands/Commands.java +++ b/src/main/java/net/neoforged/camelot/commands/Commands.java @@ -52,22 +52,8 @@ public static void init() { .addSlashCommand(new PingCommand()) .addSlashCommand(new HelpCommand(BotMain.BUTTON_MANAGER)) - // Moderation commands - .addSlashCommands( - new ModLogsCommand(BotMain.BUTTON_MANAGER), - new NoteCommand(), new WarnCommand(), - new MuteCommand(), new UnmuteCommand(), - new KickCommand(), new PurgeCommand(), - new BanCommand(), new UnbanCommand() - ) - // Information commands - .addSlashCommands(RuleCommand.INSTANCE, new McAgeCommand(), new VersioningCommand(), new ConfigurationCommand()) - - .addCommand(RuleCommand.INSTANCE) - - // Message context menus - .addContextMenus(new InfoChannelCommand.UploadToDiscohookContextMenu()); + .addSlashCommands(new McAgeCommand(), new VersioningCommand(), new ConfigurationCommand()); BotMain.forEachModule(module -> module.registerCommands(builder)); diff --git a/src/main/java/net/neoforged/camelot/configuration/ConfigMigrator.java b/src/main/java/net/neoforged/camelot/configuration/ConfigMigrator.java index 7a88717..78f66ed 100644 --- a/src/main/java/net/neoforged/camelot/configuration/ConfigMigrator.java +++ b/src/main/java/net/neoforged/camelot/configuration/ConfigMigrator.java @@ -56,7 +56,7 @@ public String migrate(Properties properties) { script.appendLine("auth = appAuthentication {").indent(); script.appendProperty("appId", properties.getProperty("githubAppId")); script.appendLine("privateKey = secret(readFile('github.pem'))"); - script.appendLine("installation = organization(" + escape(properties.getProperty("githubInstallationOwner", "")) + ")"); + script.appendLine("installation = organization('" + escape(properties.getProperty("githubInstallationOwner", "")) + "')"); script.indentEnd().appendLine("}"); } else { if (!properties.getProperty("githubPAT", "").isBlank()) { diff --git a/src/main/java/net/neoforged/camelot/module/BanAppealModule.java b/src/main/java/net/neoforged/camelot/module/BanAppealModule.java index 1d42aa2..4a3c92f 100644 --- a/src/main/java/net/neoforged/camelot/module/BanAppealModule.java +++ b/src/main/java/net/neoforged/camelot/module/BanAppealModule.java @@ -397,7 +397,7 @@ private void onModal(ModalInteractionEvent event) { .flatMap(_ -> closeAppeal(thread, true)) .flatMap(_ -> retrieveUser) .onSuccess(user -> sendMailFromServer(appeal.email(), user, guild, "Ban appeal rejected", - pre(text("You appeal has been "), b(text("rejected")), text(".")), + pre(text("Your appeal has been "), b(text("rejected")), text(".")), pre(text("You may appeal again in "), b(text(blockDaysStr)), text(" days.")), hr(), h5("Reason"), @@ -453,7 +453,7 @@ private void onButton(ButtonInteractionEvent event) { .setMaxUses(1).setMaxAge((long) 7, TimeUnit.DAYS) .reason("Un-ban invite for " + userId) .onSuccess(invite -> sendMailFromServer(appeal.email(), user, event.getGuild(), "Ban appeal approved", - pre(text("You appeal has been "), b(text("approved")), text(".")), + pre(text("Your appeal has been "), b(text("approved")), text(".")), pre(text("You may join the server again using "), a("this invite link").withHref(invite.getUrl()), text(" which expires in 7 days.")) ))) .onSuccess(_ -> Database.appeals().useExtension(BanAppealsDAO.class, db -> db.deleteAppeal(appeal.guildId(), appeal.userId()))) diff --git a/src/main/java/net/neoforged/camelot/module/InfoChannelsModule.java b/src/main/java/net/neoforged/camelot/module/InfoChannelsModule.java index 3aa02fc..12551dc 100644 --- a/src/main/java/net/neoforged/camelot/module/InfoChannelsModule.java +++ b/src/main/java/net/neoforged/camelot/module/InfoChannelsModule.java @@ -5,6 +5,7 @@ import net.dv8tion.jda.api.JDA; import net.neoforged.camelot.BotMain; import net.neoforged.camelot.commands.information.InfoChannelCommand; +import net.neoforged.camelot.commands.information.RuleCommand; import net.neoforged.camelot.config.module.InfoChannels; import java.util.concurrent.TimeUnit; @@ -30,7 +31,10 @@ public boolean shouldLoad() { @Override public void registerCommands(CommandClientBuilder builder) { - builder.addSlashCommand(new InfoChannelCommand()); + builder.addSlashCommand(new InfoChannelCommand()) + .addSlashCommand(RuleCommand.INSTANCE) + .addCommand(RuleCommand.INSTANCE) + .addContextMenu(new InfoChannelCommand.UploadToDiscohookContextMenu()); } @Override diff --git a/src/main/java/net/neoforged/camelot/module/ModerationModule.java b/src/main/java/net/neoforged/camelot/module/ModerationModule.java new file mode 100644 index 0000000..776af19 --- /dev/null +++ b/src/main/java/net/neoforged/camelot/module/ModerationModule.java @@ -0,0 +1,41 @@ +package net.neoforged.camelot.module; + +import com.google.auto.service.AutoService; +import com.jagrosh.jdautilities.command.CommandClientBuilder; +import net.neoforged.camelot.BotMain; +import net.neoforged.camelot.commands.moderation.BanCommand; +import net.neoforged.camelot.commands.moderation.KickCommand; +import net.neoforged.camelot.commands.moderation.ModLogsCommand; +import net.neoforged.camelot.commands.moderation.MuteCommand; +import net.neoforged.camelot.commands.moderation.NoteCommand; +import net.neoforged.camelot.commands.moderation.PurgeCommand; +import net.neoforged.camelot.commands.moderation.UnbanCommand; +import net.neoforged.camelot.commands.moderation.UnmuteCommand; +import net.neoforged.camelot.commands.moderation.WarnCommand; +import net.neoforged.camelot.config.module.Moderation; + +/** + * The module that provides moderation commands. + */ +@AutoService(CamelotModule.class) +public class ModerationModule extends CamelotModule.Base { + public ModerationModule() { + super(Moderation.class); + } + + @Override + public String id() { + return "moderation"; + } + + @Override + public void registerCommands(CommandClientBuilder builder) { + builder.addSlashCommands( + new ModLogsCommand(BotMain.BUTTON_MANAGER), + new NoteCommand(), new WarnCommand(), + new MuteCommand(), new UnmuteCommand(), + new KickCommand(), new PurgeCommand(), + new BanCommand(), new UnbanCommand() + ); + } +}