Skip to content

Commit

Permalink
fix: Added a cached Flood Pattern limit
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed May 18, 2023
1 parent 2c50e86 commit fc787ac
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github._4drian3d.chatregulator.api.enums.InfractionType;
import io.github._4drian3d.chatregulator.api.result.CheckResult;
import net.kyori.adventure.builder.AbstractBuilder;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Matcher;
Expand All @@ -19,6 +20,8 @@
*/
public final class FloodCheck implements Check {
private static final LoadingCache<Integer, Pattern> floodPatternCache = Caffeine.newBuilder()
.maximumSize(3)
.initialCapacity(1)
.build(length -> Pattern.compile(
"(\\w)\\1{"+length+",}|(\\w{28,})|([^\\wñ]{20,})|(^.{220,}$)",
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
Expand Down Expand Up @@ -67,7 +70,7 @@ public static class Builder implements AbstractBuilder<FloodCheck> {

Builder() {}

public Builder limit(int limit){
public Builder limit(@NonNegative int limit){
this.pattern = floodPatternCache.get(limit);
return this;
}
Expand Down

0 comments on commit fc787ac

Please sign in to comment.