diff --git a/application/config.json.template b/application/config.json.template index 17582ad39c..8f64df1a15 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -21,6 +21,7 @@ "scamBlocker": { "mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE", "reportChannelPattern": "commands", + "botTrapChannelPattern": "bot-trap", "suspiciousKeywords": [ "nitro", "boob", diff --git a/application/src/main/java/org/togetherjava/tjbot/config/ScamBlockerConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/ScamBlockerConfig.java index c322fa5ce5..d95d9f9cce 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/ScamBlockerConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/ScamBlockerConfig.java @@ -17,6 +17,7 @@ public final class ScamBlockerConfig { private final Mode mode; private final String reportChannelPattern; + private final String botTrapChannelPattern; private final Set suspiciousKeywords; private final Set hostWhitelist; private final Set hostBlacklist; @@ -27,6 +28,8 @@ public final class ScamBlockerConfig { private ScamBlockerConfig(@JsonProperty(value = "mode", required = true) Mode mode, @JsonProperty(value = "reportChannelPattern", required = true) String reportChannelPattern, + @JsonProperty(value = "botTrapChannelPattern", + required = true) String botTrapChannelPattern, @JsonProperty(value = "suspiciousKeywords", required = true) Set suspiciousKeywords, @JsonProperty(value = "hostWhitelist", required = true) Set hostWhitelist, @@ -37,6 +40,7 @@ private ScamBlockerConfig(@JsonProperty(value = "mode", required = true) Mode mo required = true) int isHostSimilarToKeywordDistanceThreshold) { this.mode = Objects.requireNonNull(mode); this.reportChannelPattern = Objects.requireNonNull(reportChannelPattern); + this.botTrapChannelPattern = Objects.requireNonNull(botTrapChannelPattern); this.suspiciousKeywords = new HashSet<>(Objects.requireNonNull(suspiciousKeywords)); this.hostWhitelist = new HashSet<>(Objects.requireNonNull(hostWhitelist)); this.hostBlacklist = new HashSet<>(Objects.requireNonNull(hostBlacklist)); @@ -63,6 +67,16 @@ public String getReportChannelPattern() { return reportChannelPattern; } + /** + * Gets the REGEX pattern used to identify the channel that is used to as bot-trap. Sending + * messages in this channel identifies the author as bot. + * + * @return the channel name pattern + */ + public String getBotTrapChannelPattern() { + return botTrapChannelPattern; + } + /** * Gets the set of keywords that are considered suspicious if they appear in a message. * diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java index 5330ffd351..f8b06f7eb6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java @@ -64,7 +64,9 @@ public final class ScamBlocker extends MessageReceiverAdapter implements UserInt private final ScamBlockerConfig.Mode mode; private final String reportChannelPattern; + private final String botTrapChannelPattern; private final Predicate isReportChannel; + private final Predicate isBotTrapChannel; private final ScamDetector scamDetector; private final Config config; private final ModerationActionsStore actionsStore; @@ -92,6 +94,12 @@ public ScamBlocker(ModerationActionsStore actionsStore, ScamHistoryStore scamHis Predicate isReportChannelName = Pattern.compile(reportChannelPattern).asMatchPredicate(); isReportChannel = channel -> isReportChannelName.test(channel.getName()); + + botTrapChannelPattern = config.getScamBlocker().getBotTrapChannelPattern(); + Predicate isBotTrapChannelName = + Pattern.compile(botTrapChannelPattern).asMatchPredicate(); + isBotTrapChannel = channel -> isBotTrapChannelName.test(channel.getName()); + hasRequiredRole = Pattern.compile(config.getSoftModerationRolePattern()).asMatchPredicate(); componentIdInteractor = new ComponentIdInteractor(getInteractionType(), getName()); @@ -122,9 +130,15 @@ public void onMessageReceived(MessageReceivedEvent event) { return; } + boolean isSafe = !isBotTrapChannel.test(event.getChannel().asTextChannel()); + Message message = event.getMessage(); String content = message.getContentDisplay(); - if (!scamDetector.isScam(content)) { + if (isSafe && scamDetector.isScam(content)) { + isSafe = false; + } + + if (isSafe) { return; }