Skip to content

Commit d357b6e

Browse files
authored
Improved Scam detector logic (#1213)
* more real scam * improved logic * dollar sign detection
1 parent b6cd50b commit d357b6e

File tree

3 files changed

+159
-13
lines changed

3 files changed

+159
-13
lines changed

application/config.json.template

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,62 @@
2121
"scamBlocker": {
2222
"mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE",
2323
"reportChannelPattern": "commands",
24-
"suspiciousKeywords": ["nitro", "boob", "sexy", "sexi", "esex"],
25-
"hostWhitelist": ["discord.com", "discord.gg", "discord.media", "discordapp.com", "discordapp.net", "discordstatus.com"],
26-
"hostBlacklist": ["bit.ly"],
27-
"suspiciousHostKeywords": ["discord", "nitro", "premium"],
24+
"suspiciousKeywords": [
25+
"nitro",
26+
"boob",
27+
"sexy",
28+
"sexi",
29+
"esex",
30+
"steam",
31+
"gift",
32+
"onlyfans",
33+
"bitcoin",
34+
"btc",
35+
"promo",
36+
"trader",
37+
"trading",
38+
"whatsapp",
39+
"crypto",
40+
"claim",
41+
"teen",
42+
"adobe",
43+
"hack",
44+
"steamcommunity",
45+
"freenitro",
46+
"usd",
47+
"earn",
48+
".exe"
49+
],
50+
"hostWhitelist": [
51+
"discord.com",
52+
"discord.media",
53+
"discordapp.com",
54+
"discordapp.net",
55+
"discordstatus.com"
56+
],
57+
"hostBlacklist": [
58+
"bit.ly",
59+
"discord.gg",
60+
"teletype.in",
61+
"t.me",
62+
"corematrix.us",
63+
"u.to",
64+
"steamcommunity.com",
65+
"goo.su",
66+
"telegra.ph",
67+
"shorturl.at",
68+
"cheatings.xyz",
69+
"transfer.sh"
70+
],
71+
"suspiciousHostKeywords": [
72+
"discord",
73+
"nitro",
74+
"premium",
75+
"free",
76+
"cheat",
77+
"crypto",
78+
"tele"
79+
],
2880
"isHostSimilarToKeywordDistanceThreshold": 2
2981
},
3082
"wolframAlphaAppId": "79J52T-6239TVXHR7",

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.net.URI;
88
import java.util.Locale;
99
import java.util.regex.Pattern;
10+
import java.util.stream.Stream;
1011

1112
/**
1213
* Detects whether a text message classifies as scam or not, using certain heuristics.
@@ -40,25 +41,36 @@ public boolean isScam(CharSequence message) {
4041
}
4142

4243
private boolean isScam(AnalyseResults results) {
43-
if (results.pingsEveryone && results.containsSuspiciousKeyword && results.hasUrl) {
44+
if (results.pingsEveryone && (results.containsSuspiciousKeyword || results.hasUrl
45+
|| results.containsDollarSign)) {
4446
return true;
4547
}
46-
return results.containsSuspiciousKeyword && results.hasSuspiciousUrl;
48+
49+
return Stream
50+
.of(results.containsSuspiciousKeyword, results.hasSuspiciousUrl,
51+
results.containsDollarSign)
52+
.filter(flag -> flag)
53+
.count() >= 2;
4754
}
4855

4956
private void analyzeToken(String token, AnalyseResults results) {
5057
if (token.isBlank()) {
5158
return;
5259
}
5360

54-
if (!results.pingsEveryone && "@everyone".equalsIgnoreCase(token)) {
61+
if (!results.pingsEveryone
62+
&& ("@everyone".equalsIgnoreCase(token) || "@here".equalsIgnoreCase(token))) {
5563
results.pingsEveryone = true;
5664
}
5765

5866
if (!results.containsSuspiciousKeyword && containsSuspiciousKeyword(token)) {
5967
results.containsSuspiciousKeyword = true;
6068
}
6169

70+
if (!results.containsDollarSign && token.contains("$")) {
71+
results.containsDollarSign = true;
72+
}
73+
6274
if (token.startsWith("http")) {
6375
analyzeUrl(token, results);
6476
}
@@ -131,6 +143,7 @@ private boolean isHostSimilarToKeyword(String host, String keyword) {
131143
private static class AnalyseResults {
132144
private boolean pingsEveryone;
133145
private boolean containsSuspiciousKeyword;
146+
private boolean containsDollarSign;
134147
private boolean hasUrl;
135148
private boolean hasSuspiciousUrl;
136149
}

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

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ void setUp() {
2727
when(config.getScamBlocker()).thenReturn(scamConfig);
2828

2929
when(scamConfig.getSuspiciousKeywords())
30-
.thenReturn(Set.of("nitro", "boob", "sexi", "esex"));
31-
when(scamConfig.getHostWhitelist()).thenReturn(Set.of("discord.com", "discord.gg",
32-
"discord.media", "discordapp.com", "discordapp.net", "discordstatus.com"));
33-
when(scamConfig.getHostBlacklist()).thenReturn(Set.of("bit.ly"));
30+
.thenReturn(Set.of("nitro", "boob", "sexy", "sexi", "esex", "steam", "gift", "onlyfans",
31+
"bitcoin", "btc", "promo", "trader", "trading", "whatsapp", "crypto", "claim",
32+
"teen", "adobe", "hack", "steamcommunity", "freenitro", "usd", "earn", ".exe"));
33+
when(scamConfig.getHostWhitelist()).thenReturn(Set.of("discord.com", "discord.media",
34+
"discordapp.com", "discordapp.net", "discordstatus.com"));
35+
when(scamConfig.getHostBlacklist()).thenReturn(Set.of("bit.ly", "discord.gg", "teletype.in",
36+
"t.me", "corematrix.us", "u.to", "steamcommunity.com", "goo.su", "telegra.ph",
37+
"shorturl.at", "cheatings.xyz", "transfer.sh"));
3438
when(scamConfig.getSuspiciousHostKeywords())
35-
.thenReturn(Set.of("discord", "nitro", "premium"));
39+
.thenReturn(Set.of("discord", "nitro", "premium", "free", "cheat", "crypto", "tele"));
3640
when(scamConfig.getIsHostSimilarToKeywordDistanceThreshold()).thenReturn(2);
3741

3842
scamDetector = new ScamDetector(config);
@@ -144,6 +148,83 @@ private static List<String> provideRealScamMessages() {
144148
https://discordu.gift/u1CHEX2sjpDuR3T5""",
145149
"@everyone join now https://discord.gg/boobise",
146150
"@everyone join now https://discord.gg/esexiest",
147-
"@everyone Join Now | Free All 12-18 y.o. https://discord.gg/eesexe");
151+
"@everyone Join Now | Free All 12-18 y.o. https://discord.gg/eesexe",
152+
"@everyone steam gift 50$ - steamcommunity.com/gift-card/pay/51", """
153+
@everyone
154+
20$ from steam
155+
steamcommunity.com/gift/001023
156+
""", """
157+
Free Onlyfans leaks and 18+ Content:
158+
https://discord.gg/4ue9esAuR7 🍑 @everyone
159+
""", """
160+
Bro, don't miss it:
161+
https://teletype.in/@game_insider/valve_promobo
162+
""",
163+
"Stake gives a 1500$! When you register using the promo code \"em4fh4bj67\" - Stake.com/auth/register?promo=em4fh4bj67",
164+
"""
165+
@everyone
166+
50$ from steam
167+
steamcommunity.com/gift/81237
168+
""",
169+
"""
170+
2025📊The best repacks of 24/7 only in our group📊
171+
IPTVPlayet AtlasVPN TradingView-Premium== Become a real trader with the best offers...
172+
✍️ https://t.me/repackMEMIaa ✍️
173+
""",
174+
"""
175+
Check there is btc cost 109k
176+
https://corematrix.us/eni
177+
""",
178+
"""
179+
I’ll teach 10 people to earn $30k or more within 72 hours but you will pay me 10% of your profit when you receive it. Note only interest people should apply, drop a message let's get started by asking (HOW)
180+
https://t.me/Christopher_Schwingo
181+
WhatsApp +1 (571) 598-2749
182+
""",
183+
"""
184+
I’ll teach 10 interested people on how to earn $30k or more within 24 hours from the crypto market, but you’ll promise to pay me 20% of the profit. Note only interested people should contact me (HOW) let get started
185+
👇👇👇
186+
https://t.me/Official_Nichola1o
187+
""",
188+
"""
189+
Bro steam gift 50$ - steamcommunity.com/gift-card/pay/51
190+
@here @everyone
191+
""", """
192+
Bro gift 50$ - steamcommunity.com/gift-card/pay/51
193+
@everyone
194+
""", """
195+
50$
196+
steamcommunity.com/gift/0a9zk2j1man2o
197+
""", """
198+
Hello, i found good server🔞
199+
https://discord.gg/e-womanso
200+
@everyone
201+
""", """
202+
Gift 50$ - steamcommunity.com/gift-card/51
203+
@everyone @here
204+
""", """
205+
50$ From steam
206+
steamcommunity.com/gift/7656685834763978
207+
@everyone
208+
""", "catch 25$ https://u.to/ExatIO", """
209+
STEAM 50$ GIFT, CLAIM NOW
210+
steamcommunity.com/1249349825824
211+
@everyone
212+
""",
213+
"Hot Teen & Onlyfans Leaks :underage: :peach: https://discord.gg/nudesxxxo @everyone",
214+
"""
215+
Adobe Full Espanol GRATiS 2024
216+
https://telegra.ph/Adobe-GRATIS-2024-FULL-ESPANOL-02-28
217+
Tutorial video
218+
https://www.youtube.com/watch?v=gmEZLz5xbmp
219+
@everyone
220+
""",
221+
"Get a $50 gift to your steam account balance https://shorturl.at/cpt09 Immerse yourself in the spring atmosphere now!",
222+
"#1 Free Hacks: https://cheatings.xyz/abc",
223+
"""
224+
I’ll help 10 people to earn 55k USDT within 72 hours but you will pay me 10% of your profit when you receive it. Note only interested people should apply, drop a message let’s get started by asking (How)
225+
Or via TG: https://t.me/Charlie_Adamo
226+
""",
227+
"Urgently looking for mods & collab managers https://discord.gg/cryptohireo",
228+
"Check this - https://transfer.sh/get/ajmkh3l7tzop/Setup.exe");
148229
}
149230
}

0 commit comments

Comments
 (0)