Skip to content

Commit cf98c4a

Browse files
committed
put predicate in the field instead of the pattern
1 parent 2111dc8 commit cf98c4a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

application/src/main/java/org/togetherjava/tjbot/moderation/ModAuditLogWriter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.nio.charset.StandardCharsets;
1717
import java.time.temporal.TemporalAccessor;
1818
import java.util.Optional;
19+
import java.util.function.Predicate;
1920
import java.util.regex.Pattern;
2021

2122
/**
@@ -32,7 +33,7 @@ public final class ModAuditLogWriter {
3233

3334
private final Config config;
3435

35-
private final Pattern auditLogChannelNamePattern;
36+
private final Predicate<String> auditLogChannelNamePredicate;
3637

3738
/**
3839
* Creates a new instance.
@@ -41,7 +42,8 @@ public final class ModAuditLogWriter {
4142
*/
4243
public ModAuditLogWriter(@NotNull Config config) {
4344
this.config = config;
44-
auditLogChannelNamePattern = Pattern.compile(config.getModAuditLogChannelPattern());
45+
auditLogChannelNamePredicate =
46+
Pattern.compile(config.getModAuditLogChannelPattern()).asMatchPredicate();
4547
}
4648

4749
/**
@@ -85,8 +87,7 @@ public void write(@NotNull String title, @NotNull String description, @NotNull U
8587
public Optional<TextChannel> getAndHandleModAuditLogChannel(@NotNull Guild guild) {
8688
Optional<TextChannel> auditLogChannel = guild.getTextChannelCache()
8789
.stream()
88-
.filter(channel -> auditLogChannelNamePattern.asMatchPredicate()
89-
.test(channel.getName()))
90+
.filter(channel -> auditLogChannelNamePredicate.test(channel.getName()))
9091
.findAny();
9192

9293
if (auditLogChannel.isEmpty()) {

0 commit comments

Comments
 (0)