Skip to content

Bot-Trap Channel for Scam Detection #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scamBlocker": {
"mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE",
"reportChannelPattern": "commands",
"botTrapChannelPattern": "bot-trap",
"suspiciousKeywords": [
"nitro",
"boob",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public final class ScamBlockerConfig {
private final Mode mode;
private final String reportChannelPattern;
private final String botTrapChannelPattern;
private final Set<String> suspiciousKeywords;
private final Set<String> hostWhitelist;
private final Set<String> hostBlacklist;
Expand All @@ -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<String> suspiciousKeywords,
@JsonProperty(value = "hostWhitelist", required = true) Set<String> hostWhitelist,
Expand All @@ -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));
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextChannel> isReportChannel;
private final Predicate<TextChannel> isBotTrapChannel;
private final ScamDetector scamDetector;
private final Config config;
private final ModerationActionsStore actionsStore;
Expand Down Expand Up @@ -92,6 +94,12 @@ public ScamBlocker(ModerationActionsStore actionsStore, ScamHistoryStore scamHis
Predicate<String> isReportChannelName =
Pattern.compile(reportChannelPattern).asMatchPredicate();
isReportChannel = channel -> isReportChannelName.test(channel.getName());

botTrapChannelPattern = config.getScamBlocker().getBotTrapChannelPattern();
Predicate<String> isBotTrapChannelName =
Pattern.compile(botTrapChannelPattern).asMatchPredicate();
isBotTrapChannel = channel -> isBotTrapChannelName.test(channel.getName());

hasRequiredRole = Pattern.compile(config.getSoftModerationRolePattern()).asMatchPredicate();

componentIdInteractor = new ComponentIdInteractor(getInteractionType(), getName());
Expand Down Expand Up @@ -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;
}

Expand Down
Loading