From 966d1edab409f7ad5851b2bc0d010b05919032a2 Mon Sep 17 00:00:00 2001 From: red Date: Wed, 20 Aug 2025 14:02:17 +0100 Subject: [PATCH] Theoretically removes spam content. Lololol --- classes/post.py | 6 ++- functions/check_users.py | 7 +-- functions/get_user_details.py | 2 +- functions/scan_posts.py | 81 ++++++++++++++++++++++++----------- requirements.txt | 1 + var.py | 1 + 6 files changed, 65 insertions(+), 33 deletions(-) diff --git a/classes/post.py b/classes/post.py index 86acca5..6ef0fca 100755 --- a/classes/post.py +++ b/classes/post.py @@ -115,7 +115,11 @@ class Post: var.most_recently_deleted_post_id = self.post_id self.deletion_status = False if self.post_will_be_deleted: - logger.info(f"Attempting to delete a post {self.post_id} for {await self.get_ratings_string()}") + ratings_string = await self.get_ratings_string() + if self.ratings: + logger.info(f"Attempting to delete a post {self.post_id} for {ratings_string}") + else: + logger.info(f"Attempting to delete a post {self.post_id} for spam reasons...") self.deletion_status = await delete_post(self.post_id) if self.deletion_status == 200: diff --git a/functions/check_users.py b/functions/check_users.py index d4c18a9..f449d2f 100755 --- a/functions/check_users.py +++ b/functions/check_users.py @@ -16,12 +16,7 @@ forbidden_strings = [ 'yahir' ] -forbidden_strings_username = [ - 'ken', - 'rack', - 'sjb', - 'yahir' -] +forbidden_strings_username = [] async def check_users(): user_details = await get_user_details(var.current_user_id+1) diff --git a/functions/get_user_details.py b/functions/get_user_details.py index c0761e7..90bacdc 100755 --- a/functions/get_user_details.py +++ b/functions/get_user_details.py @@ -12,7 +12,7 @@ async def get_user_details(user_id): async with aiohttp.ClientSession() as session: async with session.get(url, headers=headers) as response: if response.status != 200: - print(f"Failed to fetch data: {response.status}") + #print(f"Failed to fetch data for {url}: {response.status}") return None data = await response.json() diff --git a/functions/scan_posts.py b/functions/scan_posts.py index f117410..bdd8b5e 100755 --- a/functions/scan_posts.py +++ b/functions/scan_posts.py @@ -2,9 +2,12 @@ import functions.get_newest_count import var from classes import post from datetime import datetime, timedelta + +from functions.delete_post import delete_post from functions.send_message import send_message from functions.suspend_user import suspend_user_for_post from beloved_logger import logger +import akismet async def scan_posts(): @@ -14,6 +17,7 @@ async def scan_posts(): current_posts_now = var.current_posts_at_start_time new_posts = await functions.get_newest_count.get_newest_count() + post_deleted = False if new_posts != 0: current_posts_now = new_posts @@ -31,37 +35,64 @@ async def scan_posts(): if len(post_to_analyse.infringing_words) > 0: await send_message(await post_to_analyse.get_as_text_detection_text()) - if var.image_scanning_is_running: - if var.scan_new_users_only: - cut_off_date = datetime.now() - timedelta(days=3) - current_date = datetime.strptime(post_to_analyse.poster_sign_up_time, "%Y-%m-%d %H:%M:%S") + if var.image_scanning_is_running: + if var.scan_new_users_only and post_to_analyse.poster_sign_up_time: + cut_off_date = datetime.now() - timedelta(days=3) + current_date = datetime.strptime(post_to_analyse.poster_sign_up_time, "%Y-%m-%d %H:%M:%S") - logger.debug(f"User signed up at {current_date}, we are checking for " - f"users that signed up after {cut_off_date}") + logger.debug(f"User signed up at {current_date}, we are checking for " + f"users that signed up after {cut_off_date}") - if current_date < cut_off_date: - logger.info(f"User was signed up before {cut_off_date}, so checks won't occur") - var.most_recently_deleted_post_id = i - return - else: - logger.info(f"User was signed up after {cut_off_date}, so checks will occur") + if current_date < cut_off_date: + logger.info(f"User was signed up before {cut_off_date}, so checks won't occur") + var.most_recently_deleted_post_id = i + else: + logger.info(f"User was signed up after {cut_off_date}, so checks will occur") - logger.info(f"Analysing {i} for image") - await post_to_analyse.analyse_image() - if post_to_analyse.ratings: - if post_to_analyse.deletion_status: - message_string = f"""👋 Hello, I am an automatic moderation bot for Sketchers United. + logger.info(f"Analysing {i} for image") + await post_to_analyse.analyse_image() + if post_to_analyse.ratings: + if post_to_analyse.deletion_status: + message_string = f"""👋 Hello, I am an automatic moderation bot for Sketchers United. + + Your most recent post titled '{post_to_analyse.post_name}' was removed automatically as it was detected to have inappropriate content. + As a result, your account was suspended for one day. + + *If this was a mistake don't worry, all deletions and suspensions are subject to human review and corrections to automatic moderation actions (removal of suspensions and restoration of deleted posts) will be made as soon as possible if they are not warranted.* + + ❓ If there any questions, problems, or concerns please contact @username + """ - Your most recent post titled '{post_to_analyse.post_name}' was removed automatically as it was detected to have inappropriate content. - As a result, your account was suspended for one day. + await suspend_user_for_post(post_to_analyse) + await send_message(await post_to_analyse.get_as_image_deletion_text()) + await send_message(message_string, post_to_analyse.poster_username) - *If this was a mistake don't worry, all deletions and suspensions are subject to human review and corrections to automatic moderation actions (removal of suspensions and restoration of deleted posts) will be made as soon as possible if they are not warranted.* + if var.spam_scanning_is_running and post_to_analyse.poster_sign_up_time: + cut_off_date = datetime.now() - timedelta(days=3) + current_date = datetime.strptime(post_to_analyse.poster_sign_up_time, + "%Y-%m-%d %H:%M:%S") + if current_date > cut_off_date: + akismet_client = await akismet.AsyncClient.validated_client() + if await akismet_client.comment_check( + comment_content=post_to_analyse.post_description, + comment_type="comment", + comment_author=post_to_analyse.poster_username, + user_ip="0.0.0.0" + ): + message_string = f"""👋 Hello, I am an automatic moderation bot for Sketchers United. - ❓ If there any questions, problems, or concerns please contact @username - """ + Your most recent post titled '{post_to_analyse.post_name}' was removed automatically as it was detected to have spam content. - await suspend_user_for_post(post_to_analyse) - await send_message(await post_to_analyse.get_as_image_deletion_text()) - await send_message(message_string, post_to_analyse.poster_username) + *If this was a mistake don't worry, your post will be subject to human review and your post will be restored as soon possible if it is not spam.* + + ❓ If there any questions, problems, or concerns please contact @username + """ + + spam_string = f"""A post made by @{post_to_analyse.poster_username} was deleted for tripping the spam filter. +"{post_to_analyse.post_name}" at https://{var.site}/admin/posts/{post_to_analyse.post_id}""" + post_to_analyse.post_will_be_deleted = True + await delete_post(post_to_analyse.post_id) + await send_message(spam_string) + await send_message(message_string, post_to_analyse.poster_username) var.current_posts_at_start_time = current_posts_now diff --git a/requirements.txt b/requirements.txt index b973c10..485aad2 100755 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ python-dotenv~=1.0.0 websockets~=11.0.3 beautifulsoup4~=4.12.2 aiohttp +akismet \ No newline at end of file diff --git a/var.py b/var.py index 7946899..9653ae3 100755 --- a/var.py +++ b/var.py @@ -24,6 +24,7 @@ old_chat = {} scan_new_users_only = True image_scanning_is_running = True text_scanning_is_running = True +spam_scanning_is_running = True most_recently_deleted_post_id = 0 current_posts_at_start_time = None bot_started_at = None