From 2f57178a51c7a9b25e5d338daddf2fbd109f5fb8 Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 30 Nov 2024 18:02:25 +0100 Subject: [PATCH] Added sus content checker for comments --- src/ragnar/bot.py | 29 +++++++++++++++--- .../tests/__pycache__/bot.cpython-312.pyc | Bin 2050 -> 2979 bytes src/ragnar/tests/bot.py | 4 +++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ragnar/bot.py b/src/ragnar/bot.py index deac5c7..14c1a5d 100644 --- a/src/ragnar/bot.py +++ b/src/ragnar/bot.py @@ -47,7 +47,8 @@ class Bot: "leading", "helping", "quality", - "unqiue" + "unqiue", + "@ragnar" ] self.api = Api(username=self.username, password=self.password) @@ -66,9 +67,9 @@ class Bot: def clean_rant_text(self, rant_text): return rant_text.replace(" ", "").lower() - @method_cache - def is_sus_rant(self, rant_id, rant_text): - clean_text = self.clean_rant_text(rant_text) + @method_cache + def is_sus_content(self, content): + clean_text = self.clean_rant_text(content) for trigger in self.triggers: if type(trigger) == dict: if trigger.get("regex"): @@ -81,6 +82,10 @@ class Bot: return True return False + @method_cache + def is_sus_rant(self, rant_id, rant_text): + return self.is_sus_content(rant_text) + def is_flagged_as_sus(self, rant_id, num_comments): if not num_comments: return False @@ -104,6 +109,17 @@ class Bot: else: return False + def is_comments_sus(self, rant_id): + log.info("Checking if comments are sus of rant {}.".format(rant_id)) + rant = self.api.get_rant(rant_id) + if rant.get("num_comments", 0) == 0: + return False + for comment in rant.get("comments", []): + if self.is_sus_content(comment.get("body", "")): + return True + return False + + def mark_as_sus(self, rant): self.rsleepii() self.api.post_comment(rant["id"], self.mark_text) @@ -122,7 +138,10 @@ class Bot: "{}: User {} is trusted.".format(self.name, rant["user_username"]) ) continue - if not self.is_sus_rant(rant["id"], rant["text"]): + elif self.is_comments_sus(rant["id"]): + + log.info("Comments of rant are sus + user sus. Will flag as spam.") + elif not self.is_sus_rant(rant["id"], rant["text"]): log.info( "{}: Rant by {} is not sus.".format( self.name, rant["user_username"] diff --git a/src/ragnar/tests/__pycache__/bot.cpython-312.pyc b/src/ragnar/tests/__pycache__/bot.cpython-312.pyc index 4fa27e8aa659c93db95762ca74edfbe8a4e5d795..d722b73b7aea3944266f958577ef20338709425b 100644 GIT binary patch delta 974 zcmY*Y&ubGw6rN3+Gzm5-6=|$UU#SHnO@j1RQ^7+IK@`D)P=qqsOm>Iv?yNJjsaup3 zEm9AnH6HBAgGVp=S9lN)MWmv5>0eOl5A^1nO>;1?lg*p=zVCbAdwDSSdZO@QbTm)! zQ(U_0T+Zwi9$NLC=NHFXnJu!C-6nUfmE28I9(niiLZ)|Pcr>5J+#!5^-0rM)?5hebj$XfaK>r_4n}y{;Emp#hTFEYQe-@KUoDM2ZIv0)-yc zZ6STI5dq^(rZi9vTJq3b1_6`cY8|SDT8&W^n~N&tH83)dMKu`<5X+%HtJp3L9IQc5 z@MGv=2OZ}1p^&l)%Pv=NrBMmRI+Mt#nCx&HI|!&3Z!iV1h-9B%vO5u%%tz@e;d6MW zpMY$}ILTZVC=4d}u+FucSeJBx%z^5LLh8gr5TUVBRpFM)&|hhY&{N646JpKSVKgVs zQ>Bd$>ohhN_gk1tu6%)Ug=TUaq=+zW4zNlIA2AJv(ZG!xDr7cqcQLOSwH&7BU@^rDu;asr2Gec5wX0w|ei< r$hBGpGtGZXoyFsD$g-?&r1+go{>)5R^=Iez$7lA&XMPd~ delta 138 zcmZ21-Xy?xnwOW00SGiaJ<|P|C-OBjnoXQ!$koA6!5GC6%%I7(@v;^hlP2fn30$_5 zFL4!i=^PG_DINUldaQ$^hgP@dH%=0MmCLuK)l5 diff --git a/src/ragnar/tests/bot.py b/src/ragnar/tests/bot.py index cbd67e9..0d796c1 100644 --- a/src/ragnar/tests/bot.py +++ b/src/ragnar/tests/bot.py @@ -22,3 +22,7 @@ class BotTestCase(unittest.TestCase): def test_is_sus_rant_regex_url_match_http_or_www(self): rant_text = "http:// www . google . nl" self.assertTrue(self.bot.is_sus_rant(42, rant_text)) + + def test_is_sus_content(self): + rant_text = "I completely understand the frustration—it’s such a hassle to manage all those details manually. I recently started using a platform called best ai trip planner https://easytrip.ai/ and it’s been a game-changer for my travel planning. This AI-powered service analyzes your trip requirements and gives you a comprehensive plan with the best transportation options. Whether you’re looking for the fastest way to travel, the most scenic routes, or something within a specific budget, EasyTrip.ai does all the heavy lifting for you. It’s also great for last-minute plans because it quickly pulls together all the available options!" + self.assertTrue(self.bot.is_sus_content(rant_text)) \ No newline at end of file