Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -53,8 +53,8 @@ public final class ReportCommand extends BotCommandAdapter implements MessageCon
private static final Color AMBIENT_COLOR = Color.BLACK;
private final Cache<Long, Instant> authorToLastReportInvocation = createCooldownCache();
private final Predicate<String> modMailChannelNamePredicate;
private final Predicate<String> configModGroupPattern;
private final String configModMailChannelPattern;
private final String configModGroupPattern;

/**
* Creates a new instance.
Expand All @@ -69,7 +69,8 @@ public ReportCommand(Config config) {

configModMailChannelPattern = config.getModMailChannelPattern();

configModGroupPattern = config.getHeavyModerationRolePattern();
configModGroupPattern =
Pattern.compile(config.getSoftModerationRolePattern()).asMatchPredicate();
}

private Cache<Long, Instant> createCooldownCache() {
Expand Down Expand Up @@ -188,9 +189,13 @@ private MessageCreateAction createModMessage(String reportReason,
"Go to Message", guild.getId(), reportedMessage.channelID,
reportedMessage.id));

Optional<Role> moderatorRole =
guild.getRolesByName(configModGroupPattern, true).stream().findFirst();
moderatorRole.ifPresent(role -> message.setContent(role.getAsMention()));
Optional<String> roleName = guild.getRoles()
.stream()
.map(Role::getName)
.filter(configModGroupPattern)
.findFirst();
roleName.ifPresent(
s -> message.setContent(guild.getRolesByName(s, false).get(0).getAsMention()));

return message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public final class ModMailCommand extends SlashCommandAdapter {
private static final Color AMBIENT_COLOR = Color.BLACK;
private final Cache<Long, Instant> authorToLastModMailInvocation = createCooldownCache();
private final Predicate<String> modMailChannelNamePredicate;
private final Predicate<String> configModGroupPattern;
private final String configModMailChannelPattern;
private final String configModGroupPattern;


/**
Expand Down Expand Up @@ -86,7 +86,8 @@ public ModMailCommand(JDA jda, Config config) {

configModMailChannelPattern = config.getModMailChannelPattern();

configModGroupPattern = config.getHeavyModerationRolePattern();
configModGroupPattern =
Pattern.compile(config.getSoftModerationRolePattern()).asMatchPredicate();
}

private Cache<Long, Instant> createCooldownCache() {
Expand Down Expand Up @@ -153,9 +154,14 @@ private MessageCreateAction createModMessage(SlashCommandInteractionEvent event,
String.valueOf(userId)));
}

Optional<Role> moderatorRole =
event.getGuild().getRolesByName(configModGroupPattern, true).stream().findFirst();
moderatorRole.ifPresent(role -> message.setContent(role.getAsMention()));
Optional<String> roleName = event.getGuild()
.getRoles()
.stream()
.map(Role::getName)
.filter(configModGroupPattern)
.findFirst();
roleName.ifPresent(s -> message
.setContent(event.getGuild().getRolesByName(s, false).get(0).getAsMention()));

return message;
}
Expand Down