Skip to content

Commit

Permalink
put predicate in the field instead of the pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
interacsion committed Mar 13, 2022
1 parent 2111dc8 commit cf98c4a
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.charset.StandardCharsets;
import java.time.temporal.TemporalAccessor;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;

/**
Expand All @@ -32,7 +33,7 @@ public final class ModAuditLogWriter {

private final Config config;

private final Pattern auditLogChannelNamePattern;
private final Predicate<String> auditLogChannelNamePredicate;

/**
* Creates a new instance.
Expand All @@ -41,7 +42,8 @@ public final class ModAuditLogWriter {
*/
public ModAuditLogWriter(@NotNull Config config) {
this.config = config;
auditLogChannelNamePattern = Pattern.compile(config.getModAuditLogChannelPattern());
auditLogChannelNamePredicate =
Pattern.compile(config.getModAuditLogChannelPattern()).asMatchPredicate();
}

/**
Expand Down Expand Up @@ -85,8 +87,7 @@ public void write(@NotNull String title, @NotNull String description, @NotNull U
public Optional<TextChannel> getAndHandleModAuditLogChannel(@NotNull Guild guild) {
Optional<TextChannel> auditLogChannel = guild.getTextChannelCache()
.stream()
.filter(channel -> auditLogChannelNamePattern.asMatchPredicate()
.test(channel.getName()))
.filter(channel -> auditLogChannelNamePredicate.test(channel.getName()))
.findAny();

if (auditLogChannel.isEmpty()) {
Expand Down

0 comments on commit cf98c4a

Please sign in to comment.