Theoretically removes spam content.

Lololol
This commit is contained in:
red 2025-08-20 14:02:17 +01:00
parent d10af24384
commit 966d1edab4
6 changed files with 65 additions and 33 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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()

View File

@ -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.
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 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
"""
If there any questions, problems, or concerns please contact @username
"""
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)
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 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.
Your most recent post titled '{post_to_analyse.post_name}' was removed automatically as it was detected to have spam content.
*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

View File

@ -4,3 +4,4 @@ python-dotenv~=1.0.0
websockets~=11.0.3
beautifulsoup4~=4.12.2
aiohttp
akismet

1
var.py
View File

@ -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