Skip to content

Commit

Permalink
Split moderation commands into their own module
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed May 27, 2024
1 parent 4467f96 commit 35ad492
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.neoforged.camelot.config.module

import groovy.transform.CompileStatic

/**
* The module that provides moderation commands.
* <p>
* The commands included in this module are:
* <ul>
* <li>{@code /warn add}, {@code /warn delete}</li>
* <li>{@code /note add}, {@code /note remove}</li>
* <li>{@code /mute}, {@code /unmute}</li>
* <li>{@code /ban}, {@code /unban}</li>
* <li>{@code /kick}</li>
* <li>{@code /purge}</li>
* </ul>
*/
@CompileStatic
class Moderation extends ModuleConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The package containing the configurations of all Camelot modules.
*/
package net.neoforged.camelot.config.module;
16 changes: 1 addition & 15 deletions src/main/java/net/neoforged/camelot/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/net/neoforged/camelot/module/ModerationModule.java
Original file line number Diff line number Diff line change
@@ -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<Moderation> {
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()
);
}
}

0 comments on commit 35ad492

Please sign in to comment.