Skip to content

Commit

Permalink
Update cannot moderate commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jul 19, 2024
1 parent 960e8e7 commit 3334d27
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 19 deletions.
6 changes: 0 additions & 6 deletions src/main/java/net/neoforged/camelot/BotMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.neoforged.camelot.module.api.ParameterType;
import net.neoforged.camelot.util.AuthUtil;
import net.neoforged.camelot.util.Utils;
import net.neoforged.camelot.util.jda.AppEmojiManager;
import net.neoforged.camelot.util.jda.ButtonManager;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
Expand Down Expand Up @@ -88,11 +87,6 @@ public class BotMain {
*/
public static final ButtonManager BUTTON_MANAGER = new ButtonManager();

/**
* The static application emoji manager
*/
public static final AppEmojiManager EMOJI_MANAGER = new AppEmojiManager(AppEmojiManager.EmojiBundle.fromClasspath("emojis"));

/**
* The static {@link ScheduledExecutorService} for scheduling tasks.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import net.neoforged.camelot.BotMain;
import net.neoforged.camelot.util.Emojis;
import net.neoforged.camelot.util.jda.ButtonManager;
import org.jetbrains.annotations.Nullable;

Expand All @@ -26,8 +27,8 @@
* @param <T> the pagination data
*/
public abstract class PaginatableCommand<T extends PaginatableCommand.PaginationData> extends SlashCommand {
private static final Emoji PREV_EMOJI = BotMain.EMOJI_MANAGER.getLazyEmoji("prevpage");
private static final Emoji NEXT_EMOJI = BotMain.EMOJI_MANAGER.getLazyEmoji("nextpage");
private static final Emoji PREV_EMOJI = Emojis.MANAGER.getLazyEmoji("prevpage");
private static final Emoji NEXT_EMOJI = Emojis.MANAGER.getLazyEmoji("nextpage");

protected final Function<Throwable, MessageEditData> exceptionally = throwable -> {
BotMain.LOGGER.error("Encountered exception paginating command {}: ", this.name, throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.neoforged.camelot.Database;
import net.neoforged.camelot.module.BanAppealModule;
import net.neoforged.camelot.module.WebServerModule;
import net.neoforged.camelot.util.Emojis;
import org.jetbrains.annotations.Nullable;
import net.neoforged.camelot.db.schemas.ModLogEntry;
import net.neoforged.camelot.db.transactionals.PendingUnbansDAO;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected ModerationAction<Integer> createEntry(SlashCommandEvent event) {
}
targetId = usr.getIdLong();
} else {
Preconditions.checkArgument(canModerate(target, event.getMember()), "Cannot moderate user!");
Preconditions.checkArgument(canModerate(target, event.getMember()), Emojis.ADMIN_ABOOZ.getFormatted() + " Cannot moderate user!");
targetId = target.getIdLong();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.RestAction;
import net.neoforged.camelot.util.Emojis;
import org.jetbrains.annotations.Nullable;
import net.neoforged.camelot.db.schemas.ModLogEntry;

Expand All @@ -33,7 +34,7 @@ public KickCommand() {
@Override
protected ModerationAction<Void> createEntry(SlashCommandEvent event) {
final Member target = event.optMember("user");
Preconditions.checkArgument(canModerate(target, event.getMember()), "Cannot moderate user!");
Preconditions.checkArgument(canModerate(target, event.getMember()), Emojis.ADMIN_ABOOZ.getFormatted() + " Cannot moderate user!");
return new ModerationAction<>(
ModLogEntry.kick(target.getIdLong(), event.getGuild().getIdLong(), event.getUser().getIdLong(), event.optString("reason")),
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ protected final void execute(SlashCommandEvent event) {
try {
action = createEntry(event);
} catch (IllegalArgumentException exception) {
event.reply("Failed to validate arguments: " + exception.getMessage())
.setEphemeral(true).queue();
event.reply(exception.getMessage()).setEphemeral(true).queue();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.RestAction;
import net.neoforged.camelot.util.Emojis;
import org.jetbrains.annotations.Nullable;
import net.neoforged.camelot.db.schemas.ModLogEntry;
import net.neoforged.camelot.util.DateUtils;
Expand Down Expand Up @@ -40,7 +41,7 @@ public MuteCommand() {
@SuppressWarnings("DataFlowIssue")
protected ModerationAction<Void> createEntry(SlashCommandEvent event) {
final Member target = event.optMember("user");
Preconditions.checkArgument(canModerate(target, event.getMember()), "Cannot moderate user!");
Preconditions.checkArgument(canModerate(target, event.getMember()), Emojis.ADMIN_ABOOZ.getFormatted() + " Cannot moderate user!");
Preconditions.checkArgument(target.getTimeOutEnd() == null || target.getTimeOutEnd().isBefore(OffsetDateTime.now()), "User is already muted!");

final Duration time = event.getOption("duration", MAX_DURATION, it -> DateUtils.getDurationFromInput(it.getAsString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.RestAction;
import net.neoforged.camelot.util.Emojis;
import org.jetbrains.annotations.Nullable;
import net.neoforged.camelot.db.schemas.ModLogEntry;

Expand Down Expand Up @@ -36,7 +37,7 @@ public UnmuteCommand() {
@SuppressWarnings("DataFlowIssue")
protected ModerationAction<Void> createEntry(SlashCommandEvent event) {
final Member target = event.optMember("user");
Preconditions.checkArgument(canModerate(target, event.getMember()), "Cannot moderate user!");
Preconditions.checkArgument(canModerate(target, event.getMember()), Emojis.ADMIN_ABOOZ.getFormatted() + " Cannot moderate user!");
Preconditions.checkArgument(target.getTimeOutEnd() != null && target.getTimeOutEnd().isAfter(OffsetDateTime.now()), "User is not timed out!");
return new ModerationAction<>(
ModLogEntry.unmute(target.getIdLong(), event.getGuild().getIdLong(), event.getUser().getIdLong(), event.optString("reason")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DeleteCommand() {
this.help = "Delete a warning from an user";
this.options = List.of(
new OptionData(OptionType.USER, "user", "The user to delete a warn from", true),
new OptionData(OptionType.INTEGER, "warn", "The number of the note to remove", true)
new OptionData(OptionType.INTEGER, "warn", "The number of the warning (case) to remove", true)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.neoforged.camelot.listener.DismissListener;
import net.neoforged.camelot.module.api.CamelotModule;
import net.neoforged.camelot.module.api.ParameterType;
import net.neoforged.camelot.util.Emojis;

import java.util.ArrayList;

Expand Down Expand Up @@ -50,7 +51,7 @@ protected void execute(SlashCommandEvent event) {

@Override
public void registerListeners(JDABuilder builder) {
builder.addEventListeners(BotMain.BUTTON_MANAGER, BotMain.EMOJI_MANAGER, new DismissListener());
builder.addEventListeners(BotMain.BUTTON_MANAGER, Emojis.MANAGER, new DismissListener());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.neoforged.camelot.BotMain;
import net.neoforged.camelot.config.module.FilePreview;
import net.neoforged.camelot.module.api.CamelotModule;
import net.neoforged.camelot.util.Emojis;
import net.neoforged.camelot.util.Utils;
import org.jetbrains.annotations.NotNull;
import org.kohsuke.github.GHGistBuilder;
Expand All @@ -25,7 +25,7 @@ public FilePreviewModule() {
super(FilePreview.class);
}

private static final Emoji EMOJI = BotMain.EMOJI_MANAGER.getLazyEmoji("gist");
private static final Emoji EMOJI = Emojis.MANAGER.getLazyEmoji("gist");
private static final Pattern CODEBLOCK_PATTERN = Pattern.compile("`{3}(?<lang>\\w*)\\n(?<content>[\\s\\S]*?)\\n`{3}", Pattern.MULTILINE);
private static final Random RANDOM = new Random();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.neoforged.camelot.listener.ReferencingListener;
import net.neoforged.camelot.module.api.CamelotModule;
import net.neoforged.camelot.util.DateUtils;
import net.neoforged.camelot.util.Emojis;
import net.neoforged.camelot.util.Utils;

import java.awt.*;
Expand All @@ -55,7 +56,7 @@ public RemindersModule() {
}

private static final String SNOOZE_BUTTON_ID = "snooze_reminder";
private static final Emoji SNOOZE_EMOJI = BotMain.EMOJI_MANAGER.getLazyEmoji("snooze");
private static final Emoji SNOOZE_EMOJI = Emojis.MANAGER.getLazyEmoji("snooze");

private List<ActionRow> snoozeButtons = List.of();

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/neoforged/camelot/util/Emojis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.neoforged.camelot.util;

import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.neoforged.camelot.util.jda.AppEmojiManager;

/**
* Common application-level emojis.
*/
public class Emojis {
/**
* The static application emoji manager
*/
public static final AppEmojiManager MANAGER = new AppEmojiManager(AppEmojiManager.EmojiBundle.fromClasspath("emojis"));

public static final Emoji ADMIN_ABOOZ = MANAGER.getLazyEmoji("adminabooz");
}
Binary file added src/main/resources/emojis/adminabooz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/resources/emojis/emojis.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ gist=gist.png
# Pagination
prevpage=prevpage.png
nextpage=nextpage.png

# Misc fun things
adminabooz=adminabooz.png

0 comments on commit 3334d27

Please sign in to comment.