diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index f1e054e641..7980e34733 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -6,10 +6,7 @@ import org.togetherjava.tjbot.commands.basic.VcActivityCommand; import org.togetherjava.tjbot.commands.free.FreeCommand; import org.togetherjava.tjbot.commands.mathcommands.TeXCommand; -import org.togetherjava.tjbot.commands.moderation.BanCommand; -import org.togetherjava.tjbot.commands.moderation.KickCommand; -import org.togetherjava.tjbot.commands.moderation.ModerationActionsStore; -import org.togetherjava.tjbot.commands.moderation.UnbanCommand; +import org.togetherjava.tjbot.commands.moderation.*; import org.togetherjava.tjbot.commands.tags.TagCommand; import org.togetherjava.tjbot.commands.tags.TagManageCommand; import org.togetherjava.tjbot.commands.tags.TagSystem; @@ -59,6 +56,7 @@ public enum Commands { commands.add(new BanCommand(actionsStore)); commands.add(new UnbanCommand(actionsStore)); commands.add(new FreeCommand()); + commands.add(new AuditCommand(actionsStore)); return commands; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java new file mode 100644 index 0000000000..1b756927d2 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/AuditCommand.java @@ -0,0 +1,144 @@ +package org.togetherjava.tjbot.commands.moderation; + +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.Interaction; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.TimeUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; +import org.togetherjava.tjbot.commands.SlashCommandVisibility; +import org.togetherjava.tjbot.config.Config; + +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; +import java.util.regex.Pattern; + +/** + * This command lists all moderation actions that have been taken against a given user, for example + * warnings, mutes and bans. + *
+ * The command fails if the user triggering it is lacking permissions to either audit other users or
+ * to audit the specific given user (for example a moderator attempting to audit an admin).
+ */
+public final class AuditCommand extends SlashCommandAdapter {
+ private static final String TARGET_OPTION = "user";
+ private static final String COMMAND_NAME = "audit";
+ private static final String ACTION_VERB = "audit";
+ private final Predicate> messagesTask = RestAction
+ .allOf(actions.stream().map(action -> actionToMessage(action, jda)).toList());
+ messagesTask.map(messages -> prependElement(summary, messages))
+ .flatMap(messages -> event.getHook().sendMessageEmbeds(messages))
+ .queue();
+ }
+}
diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java
index 4070c3dfa5..deaa4a6c95 100644
--- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java
+++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java
@@ -25,7 +25,7 @@ enum ModerationUtils {
* {@link Guild#ban(User, int, String)}.
*/
private static final int REASON_MAX_LENGTH = 512;
- private static final Color AMBIENT_COLOR = Color.decode("#895FE8");
+ static final Color AMBIENT_COLOR = Color.decode("#895FE8");
/**
* Checks whether the given reason is valid. If not, it will handle the situation and respond to