improve chatfilter
All checks were successful
/ Build BaseBand (push) Successful in 2m48s

This commit is contained in:
Daniella / Tove 2024-10-07 07:41:22 +02:00
parent 7f168ca5e8
commit 66b9298f61
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -125,11 +125,11 @@ public class ChatFilter extends Feature {
} }
public boolean containsWord(String s, String word) { public boolean containsWord(String s, String word) {
return Pattern.compile("(?<=[  ](§.)?(§.)?(§.)?)" + word + "(?=\\W|$)", Pattern.CASE_INSENSITIVE).matcher(s).find(); return Pattern.compile("(?<=[  ](§.)?(§.)?(§.)?)" + word + "(?=[^a-z]|$)", Pattern.CASE_INSENSITIVE).matcher(s).find();
} }
public String filter(String s, String word, String type) { public String filter(String s, String word, String type) {
Pattern pat = Pattern.compile("(?<=[  ](§.)?(§.)?(§.)?)" + word + "(?=\\W|$)", Pattern.CASE_INSENSITIVE); Pattern pat = Pattern.compile("(?<=[  ](§.)?(§.)?(§.)?)" + word + "(?=[^a-z]|$)", Pattern.CASE_INSENSITIVE);
Matcher matcher = pat.matcher(s); Matcher matcher = pat.matcher(s);
StringBuilder result = new StringBuilder(s.length()); StringBuilder result = new StringBuilder(s.length());
int last = 0; int last = 0;
@ -137,7 +137,7 @@ public class ChatFilter extends Feature {
result.append(s, last, matcher.start()); result.append(s, last, matcher.start());
switch (mode) { switch (mode) {
case Censor: case Censor:
result.append(matcher.group().replaceFirst("[aeiou]", "*")); result.append(matcher.group().replaceAll("[aeiou]", "*"));
break; break;
case Replace: case Replace:
result.append("[").append(type).append(" removed]"); result.append("[").append(type).append(" removed]");
@ -155,14 +155,14 @@ public class ChatFilter extends Feature {
// TODO expand // TODO expand
public static final String[] ETHNIC_SLURS = new String[] { public static final String[] ETHNIC_SLURS = new String[] {
"nig+a?e?h?r*", "[a-z]*nig+a?e?h?r*[a-z]*",
"negr+o(id)?", "negr+o(id)?",
}; };
public static final String[] QUEERPHOBIC_SLURS = new String[] { public static final String[] QUEERPHOBIC_SLURS = new String[] {
"trann\\w*", "[a-z]*trann[a-z]*",
"shemale", "shemale",
"hon", "hon[a-z]*",
"subnormal", "subnormal",
"troon", "troon",
}; };