Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(new GitHubCommand(githubReference));
features.add(new ModMailCommand(jda, config));
features.add(new HelpThreadCommand(config, helpSystemHelper, metrics));
features.add(new ReportCommand(config));
features.add(new ReportCommand(config, actionsStore));
features.add(new BookmarksCommand(bookmarksSystem));

features.add(new ChatGptCommand(chatGptService, helpSystemHelper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
Expand All @@ -25,6 +26,7 @@
import org.togetherjava.tjbot.features.BotCommandAdapter;
import org.togetherjava.tjbot.features.CommandVisibility;
import org.togetherjava.tjbot.features.MessageContextCommand;
import org.togetherjava.tjbot.features.componentids.Lifespan;
import org.togetherjava.tjbot.features.utils.MessageUtils;

import java.awt.Color;
Expand All @@ -36,6 +38,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Implements the /report command, which allows users to report a selected offensive message from
Expand All @@ -53,15 +56,20 @@ public final class ReportCommand extends BotCommandAdapter implements MessageCon
private final Predicate<String> modMailChannelNamePredicate;
private final Predicate<String> configModGroupPattern;
private final String configModMailChannelPattern;
private final ModerationActionsStore moderationActionsStore;

/**
* Creates a new instance.
*
* @param config to get the channel to forward reports to
* @param moderationActionsStore to get the history of moderation actions against the reported
* user
*/
public ReportCommand(Config config) {
public ReportCommand(Config config, ModerationActionsStore moderationActionsStore) {
super(Commands.message(COMMAND_NAME), CommandVisibility.GUILD);

this.moderationActionsStore = Objects.requireNonNull(moderationActionsStore);

modMailChannelNamePredicate =
Pattern.compile(config.getModMailChannelPattern()).asMatchPredicate();

Expand Down Expand Up @@ -182,9 +190,12 @@ private MessageCreateAction createModMessage(String reportReason,
.setColor(AMBIENT_COLOR)
.build();

String historyButtonId = generateComponentId(Lifespan.REGULAR, reportedMessage.authorId);

MessageCreateAction message =
modMailAuditLog.sendMessageEmbeds(reportedMessageEmbed, reportReasonEmbed)
.addActionRow(Button.link(reportedMessage.jumpUrl, "Go to message"));
.addActionRow(Button.link(reportedMessage.jumpUrl, "Go to message"),
Button.primary(historyButtonId, "View history"));

Optional<Role> moderatorRole = guild.getRoles()
.stream()
Expand Down Expand Up @@ -222,7 +233,7 @@ private static String createUserReply(Result<Message> result) {
}

private record ReportedMessage(String content, String id, String jumpUrl, String channelID,
Instant timestamp, String authorName, String authorAvatarUrl) {
Instant timestamp, String authorName, String authorAvatarUrl, String authorId) {
static ReportedMessage ofArgs(List<String> args) {
String content = args.getFirst();
String id = args.get(1);
Expand All @@ -231,8 +242,44 @@ static ReportedMessage ofArgs(List<String> args) {
Instant timestamp = Instant.parse(args.get(4));
String authorName = args.get(5);
String authorAvatarUrl = args.get(6);
String authorId = args.get(7);
return new ReportedMessage(content, id, jumpUrl, channelID, timestamp, authorName,
authorAvatarUrl);
authorAvatarUrl, authorId);
}
}

@Override
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {

long guildId = event.getGuild().getIdLong();
long reportedUserId = Long.parseLong(args.getFirst());

List<ActionRecord> actionsAgainstReportedUser =
moderationActionsStore.getActionsByTargetAscending(guildId, reportedUserId);

EmbedBuilder embedBuilder = new EmbedBuilder()
.setTitle("Moderation History for User (ID: " + reportedUserId + ")")
.setColor(Color.ORANGE);

String description = "User has a clean record.";

if (!actionsAgainstReportedUser.isEmpty()) {
String historyContent = actionsAgainstReportedUser.stream()
.map(action -> String.format(
"• **%s** (Case #%d) - Reason: *%s* (Issued: <t:%d:R>)",
action.actionType(), action.caseId(),
MessageUtils.abbreviate(action.reason(), 100),
action.issuedAt().getEpochSecond()))
.collect(Collectors.joining("\n"));

description =
MessageUtils.abbreviate(historyContent, MessageEmbed.DESCRIPTION_MAX_LENGTH);
}

embedBuilder.setDescription(description);

event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a particular reason you went for a single embed instead of the style from /audit?
imo what you did there looks worse in terms of UI. and it abbreviating instead of offering proper next/prev buttons (like /audit) means people still have to use /audit if they want full history.
(but okay, maybe thats not needed as this is meant as a quick-overview instead)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is for a quick look at the recent actions against the reported user but if you want I can do the other one too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally i prefer embeds over text, the ui in discord is just superior that way. but imo this is best to be decided by the team. maybe share a screenshot in the discord channel and ask for feedback on that part


}

}
Loading