[stickynotes-antispam] Delete pastes which consists of repeated string only



commit 7637bd710cc266a5717d9db64c2d64d87a749611
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Sun Apr 5 19:46:44 2020 +0200

    Delete pastes which consists of repeated string only

 stickynotes-antispam.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/stickynotes-antispam.py b/stickynotes-antispam.py
index 5a67de9..097cb38 100755
--- a/stickynotes-antispam.py
+++ b/stickynotes-antispam.py
@@ -19,23 +19,28 @@ BLACKLIST = [
 
 
 def check_if_spam(data):
-    mark_for_deletion = False
+    lines = data.splitlines()
 
     for word in BLACKLIST:
         if re.search(word, data, re.IGNORECASE):
-            mark_for_deletion = True
+            return True
 
     # Delete paste if contains more than 2 lines containing an URL
-    if not mark_for_deletion:
-        link_count = 0
-        for line in data.splitlines():
-            if re.search("http[s]?://", line, re.IGNORECASE):
-                link_count += 1
+    link_count = 0
+    for line in lines:
+        if re.search("http[s]?://", line, re.IGNORECASE):
+            link_count += 1
 
-        if link_count >= 2:
-            mark_for_deletion = True
+    if link_count >= 2:
+        return True
 
-    return mark_for_deletion
+    # Spammers tend to paste the same URL n times
+    firstline = lines[0]
+    repeat_counter = lines.count(firstline)
+    if repeat_counter > 1 and len(lines) == repeat_counter:
+        return True
+
+    return False
 
 
 def main():


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]