Skip to content

Commit a207331

Browse files
committed
CR improvement
1 parent 3f63a65 commit a207331

File tree

1 file changed

+6
-3
lines changed
  • application/src/main/java/org/togetherjava/tjbot/features/moderation/scam

1 file changed

+6
-3
lines changed

application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamDetector.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,10 @@ private boolean containsSuspiciousKeyword(String token) {
116116
.map(keyword -> keyword.toLowerCase(Locale.US))
117117
.anyMatch(keyword -> {
118118
// Simple regex-inspired syntax "^foo"
119-
if (!keyword.isEmpty() && keyword.charAt(0) == '^') {
119+
if (startsWith(keyword, '^')) {
120120
return preparedToken.startsWith(keyword.substring(1));
121-
} else {
122-
return preparedToken.contains(keyword);
123121
}
122+
return preparedToken.contains(keyword);
124123
});
125124
}
126125

@@ -147,6 +146,10 @@ private boolean isHostSimilarToKeyword(String host, String keyword) {
147146
return false;
148147
}
149148

149+
private static boolean startsWith(CharSequence text, char prefixToTest) {
150+
return !text.isEmpty() && text.charAt(0) == prefixToTest;
151+
}
152+
150153
private static class AnalyseResults {
151154
private boolean pingsEveryone;
152155
private boolean containsSuspiciousKeyword;

0 commit comments

Comments
 (0)