Skip to content

Commit 2a47b14

Browse files
committed
fixed stacktrace false positives
1 parent 5bf69bb commit 2a47b14

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

application/config.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"whatsapp",
4141
"crypto",
4242
"^claim",
43-
"teen",
43+
"^teen$",
4444
"adobe",
4545
"^hack$",
4646
"hacks",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import java.net.URI;
77
import java.util.Locale;
8+
import java.util.function.Predicate;
9+
import java.util.regex.Pattern;
810

911
/**
1012
* Analyzes a given text token. Populates various metrics regarding the token possibly being
@@ -14,6 +16,10 @@
1416
* {@link #analyze(String, AnalyseResults)}.
1517
*/
1618
final class TokenAnalyse {
19+
// Tokens like: "org.schema.game.common.data.world.Sector.access$200(Sector.java:120)"
20+
private static final Predicate<String> IS_STACKTRACE_TOKEN =
21+
Pattern.compile("(org|com|de|dev)(\\.[^.()]+){4,15}\\([^.()]+\\.java:\\d+\\)")
22+
.asMatchPredicate();
1723
private final ScamBlockerConfig config;
1824

1925
TokenAnalyse(ScamBlockerConfig config) {
@@ -27,7 +33,7 @@ final class TokenAnalyse {
2733
* @param results metrics representing how suspicious the token is
2834
*/
2935
void analyze(String token, AnalyseResults results) {
30-
if (token.isBlank()) {
36+
if (token.isBlank() || IS_STACKTRACE_TOKEN.test(token)) {
3137
return;
3238
}
3339

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,19 @@ public static void main(String[] args){
546546
https://learn.microsoft.com/en-us/powershell/scripting/discover-powershell?view=powershell-7.5
547547
What makes PowerShell unique is that it accepts and returns .NET objects, rather than text.
548548
because of that, but well it says that it returns .NET objects not that the commands are from .NET,
549-
but well as i said i use cmd.exe because i do not know .NET nor powershell""");
549+
but well as i said i use cmd.exe because i do not know .NET nor powershell""",
550+
"""
551+
Exception in thread "ServerEntityWriterThread"
552+
java.lang.NoSuchMethodError: org.schema.game.common.controller.rails.RailRelation.isLocked()Z
553+
at org.schema.game.common.controller.rails.RailController.getDockedTag(RailController.java:2686)
554+
at org.schema.game.common.controller.rails.RailController.getTag(RailController.java:2652)
555+
at org.schema.game.common.controller.SegmentController.toTagStructure(SegmentController.java:2813)
556+
at org.schema.game.common.data.EntityFileTools.write(EntityFileTools.java:57)
557+
at org.schema.game.server.controller.GameServerController.writeEntity(GameServerController.java:2938)
558+
at org.schema.game.common.data.world.Sector.writeSingle(Sector.java:2570)
559+
at org.schema.game.common.data.world.Sector.writeEntity(Sector.java:2546)
560+
at org.schema.game.common.data.world.Sector.access$200(Sector.java:120)
561+
at org.schema.game.common.data.world.Sector$3.run(Sector.java:2665)
562+
at org.schema.schine.network.server.ServerEntityWriterThread.run(ServerEntityWriterThread.java:74)""");
550563
}
551564
}

0 commit comments

Comments
 (0)