Skip to content

Commit a7a0944

Browse files
authored
Ping moderators when /modmail and /report commands are used. (#699)
* Ping moderators when /modmail command is used. * Rename moderator group string to match the style * Ping moderators when /report command is used. * Extra space * Refactor * Fix CR comments * Fix CR comments
1 parent 0e2d54f commit a7a0944

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/moderation/ReportCommand.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.dv8tion.jda.api.entities.Guild;
77
import net.dv8tion.jda.api.entities.Message;
88
import net.dv8tion.jda.api.entities.MessageEmbed;
9+
import net.dv8tion.jda.api.entities.Role;
910
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
1011
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
1112
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
@@ -52,6 +53,7 @@ public final class ReportCommand extends BotCommandAdapter implements MessageCon
5253
private static final Color AMBIENT_COLOR = Color.BLACK;
5354
private final Cache<Long, Instant> authorToLastReportInvocation = createCooldownCache();
5455
private final Predicate<String> modMailChannelNamePredicate;
56+
private final Predicate<String> configModGroupPattern;
5557
private final String configModMailChannelPattern;
5658

5759
/**
@@ -66,6 +68,9 @@ public ReportCommand(Config config) {
6668
Pattern.compile(config.getModMailChannelPattern()).asMatchPredicate();
6769

6870
configModMailChannelPattern = config.getModMailChannelPattern();
71+
72+
configModGroupPattern =
73+
Pattern.compile(config.getHeavyModerationRolePattern()).asMatchPredicate();
6974
}
7075

7176
private Cache<Long, Instant> createCooldownCache() {
@@ -177,9 +182,21 @@ private MessageCreateAction createModMessage(String reportReason,
177182
.setDescription(reportReason)
178183
.setColor(AMBIENT_COLOR)
179184
.build();
180-
return modMailAuditLog.sendMessageEmbeds(reportedMessageEmbed, reportReasonEmbed)
181-
.addActionRow(DiscordClientAction.Channels.GUILD_CHANNEL_MESSAGE.asLinkButton(
182-
"Go to Message", guild.getId(), reportedMessage.channelID, reportedMessage.id));
185+
186+
MessageCreateAction message =
187+
modMailAuditLog.sendMessageEmbeds(reportedMessageEmbed, reportReasonEmbed)
188+
.addActionRow(DiscordClientAction.Channels.GUILD_CHANNEL_MESSAGE.asLinkButton(
189+
"Go to Message", guild.getId(), reportedMessage.channelID,
190+
reportedMessage.id));
191+
192+
Optional<Role> moderatorRole = guild.getRoles()
193+
.stream()
194+
.filter(role -> configModGroupPattern.test(role.getName()))
195+
.findFirst();
196+
197+
moderatorRole.ifPresent(role -> message.setContent(role.getAsMention()));
198+
199+
return message;
183200
}
184201

185202
private void sendModMessage(ModalInteractionEvent event, List<String> args,

application/src/main/java/org/togetherjava/tjbot/commands/moderation/modmail/ModMailCommand.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.dv8tion.jda.api.EmbedBuilder;
66
import net.dv8tion.jda.api.JDA;
77
import net.dv8tion.jda.api.entities.MessageEmbed;
8+
import net.dv8tion.jda.api.entities.Role;
89
import net.dv8tion.jda.api.entities.User;
910
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
1011
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -50,6 +51,7 @@ public final class ModMailCommand extends SlashCommandAdapter {
5051
private static final Color AMBIENT_COLOR = Color.BLACK;
5152
private final Cache<Long, Instant> authorToLastModMailInvocation = createCooldownCache();
5253
private final Predicate<String> modMailChannelNamePredicate;
54+
private final Predicate<String> configModGroupPattern;
5355
private final String configModMailChannelPattern;
5456

5557

@@ -83,6 +85,9 @@ public ModMailCommand(JDA jda, Config config) {
8385
Pattern.compile(config.getModMailChannelPattern()).asMatchPredicate();
8486

8587
configModMailChannelPattern = config.getModMailChannelPattern();
88+
89+
configModGroupPattern =
90+
Pattern.compile(config.getHeavyModerationRolePattern()).asMatchPredicate();
8691
}
8792

8893
private Cache<Long, Instant> createCooldownCache() {
@@ -148,6 +153,15 @@ private MessageCreateAction createModMessage(SlashCommandInteractionEvent event,
148153
message.addActionRow(DiscordClientAction.General.USER.asLinkButton("Author Profile",
149154
String.valueOf(userId)));
150155
}
156+
157+
Optional<Role> moderatorRole = event.getGuild()
158+
.getRoles()
159+
.stream()
160+
.filter(role -> configModGroupPattern.test(role.getName()))
161+
.findFirst();
162+
163+
moderatorRole.ifPresent(role -> message.setContent(role.getAsMention()));
164+
151165
return message;
152166
}
153167

0 commit comments

Comments
 (0)