Skip to content

Commit c162581

Browse files
committed
added extra "trustedUserRolePattern" config entry
1 parent 8977d77 commit c162581

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

application/config.json.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE",
2323
"reportChannelPattern": "commands",
2424
"botTrapChannelPattern": "bot-trap",
25+
"trustedUserRolePattern": "Top Helpers .+|Moderator|Community Ambassador|Expert",
2526
"suspiciousKeywords": [
2627
"nitro",
2728
"boob",

application/src/main/java/org/togetherjava/tjbot/config/ScamBlockerConfig.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class ScamBlockerConfig {
1818
private final Mode mode;
1919
private final String reportChannelPattern;
2020
private final String botTrapChannelPattern;
21+
private final String trustedUserRolePattern;
2122
private final Set<String> suspiciousKeywords;
2223
private final Set<String> hostWhitelist;
2324
private final Set<String> hostBlacklist;
@@ -32,6 +33,8 @@ private ScamBlockerConfig(@JsonProperty(value = "mode", required = true) Mode mo
3233
required = true) String reportChannelPattern,
3334
@JsonProperty(value = "botTrapChannelPattern",
3435
required = true) String botTrapChannelPattern,
36+
@JsonProperty(value = "trustedUserRolePattern",
37+
required = true) String trustedUserRolePattern,
3538
@JsonProperty(value = "suspiciousKeywords",
3639
required = true) Set<String> suspiciousKeywords,
3740
@JsonProperty(value = "hostWhitelist", required = true) Set<String> hostWhitelist,
@@ -47,6 +50,7 @@ private ScamBlockerConfig(@JsonProperty(value = "mode", required = true) Mode mo
4750
this.mode = Objects.requireNonNull(mode);
4851
this.reportChannelPattern = Objects.requireNonNull(reportChannelPattern);
4952
this.botTrapChannelPattern = Objects.requireNonNull(botTrapChannelPattern);
53+
this.trustedUserRolePattern = Objects.requireNonNull(trustedUserRolePattern);
5054
this.suspiciousKeywords = new HashSet<>(Objects.requireNonNull(suspiciousKeywords));
5155
this.hostWhitelist = new HashSet<>(Objects.requireNonNull(hostWhitelist));
5256
this.hostBlacklist = new HashSet<>(Objects.requireNonNull(hostBlacklist));
@@ -86,6 +90,15 @@ public String getBotTrapChannelPattern() {
8690
return botTrapChannelPattern;
8791
}
8892

93+
/**
94+
* Gets the REGEX pattern used to identify roles that will be ignored for scam detection.
95+
*
96+
* @return the REGEX pattern
97+
*/
98+
public String getTrustedUserRolePattern() {
99+
return trustedUserRolePattern;
100+
}
101+
89102
/**
90103
* Gets the set of keywords that are considered suspicious if they appear in a message.
91104
*

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public ScamDetector(Config config) {
3737
this.config = config.getScamBlocker();
3838

3939
isSuspiciousAttachmentName =
40-
Pattern.compile(config.getScamBlocker().getSuspiciousAttachmentNamePattern())
40+
Pattern.compile(this.config.getSuspiciousAttachmentNamePattern())
4141
.asMatchPredicate();
42-
hasTrustedRole = Pattern.compile(config.getSoftModerationRolePattern()).asMatchPredicate();
42+
hasTrustedRole =
43+
Pattern.compile(this.config.getTrustedUserRolePattern()).asMatchPredicate();
4344
}
4445

4546
/**

application/src/test/java/org/togetherjava/tjbot/features/moderation/scam/ScamDetectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void setUp() {
5151
when(scamConfig.getSuspiciousAttachmentNamePattern())
5252
.thenReturn(SUSPICIOUS_ATTACHMENT_NAME);
5353

54-
when(config.getSoftModerationRolePattern()).thenReturn("Moderator|Community Ambassador");
54+
when(scamConfig.getTrustedUserRolePattern()).thenReturn("Moderator");
5555

5656
scamDetector = new ScamDetector(config);
5757
}

0 commit comments

Comments
 (0)