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 var.most_recently_deleted_post_id = self.post_id
self.deletion_status = False self.deletion_status = False
if self.post_will_be_deleted: 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) self.deletion_status = await delete_post(self.post_id)
if self.deletion_status == 200: if self.deletion_status == 200:

View File

@ -16,12 +16,7 @@ forbidden_strings = [
'yahir' 'yahir'
] ]
forbidden_strings_username = [ forbidden_strings_username = []
'ken',
'rack',
'sjb',
'yahir'
]
async def check_users(): async def check_users():
user_details = await get_user_details(var.current_user_id+1) 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 aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as response: async with session.get(url, headers=headers) as response:
if response.status != 200: if response.status != 200:
print(f"Failed to fetch data: {response.status}") #print(f"Failed to fetch data for {url}: {response.status}")
return None return None
data = await response.json() data = await response.json()

View File

@ -2,9 +2,12 @@ import functions.get_newest_count
import var import var
from classes import post from classes import post
from datetime import datetime, timedelta from datetime import datetime, timedelta
from functions.delete_post import delete_post
from functions.send_message import send_message from functions.send_message import send_message
from functions.suspend_user import suspend_user_for_post from functions.suspend_user import suspend_user_for_post
from beloved_logger import logger from beloved_logger import logger
import akismet
async def scan_posts(): async def scan_posts():
@ -14,6 +17,7 @@ async def scan_posts():
current_posts_now = var.current_posts_at_start_time current_posts_now = var.current_posts_at_start_time
new_posts = await functions.get_newest_count.get_newest_count() new_posts = await functions.get_newest_count.get_newest_count()
post_deleted = False
if new_posts != 0: if new_posts != 0:
current_posts_now = new_posts current_posts_now = new_posts
@ -32,7 +36,7 @@ async def scan_posts():
await send_message(await post_to_analyse.get_as_text_detection_text()) await send_message(await post_to_analyse.get_as_text_detection_text())
if var.image_scanning_is_running: if var.image_scanning_is_running:
if var.scan_new_users_only: if var.scan_new_users_only and post_to_analyse.poster_sign_up_time:
cut_off_date = datetime.now() - timedelta(days=3) 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") current_date = datetime.strptime(post_to_analyse.poster_sign_up_time, "%Y-%m-%d %H:%M:%S")
@ -42,7 +46,6 @@ async def scan_posts():
if current_date < 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") logger.info(f"User was signed up before {cut_off_date}, so checks won't occur")
var.most_recently_deleted_post_id = i var.most_recently_deleted_post_id = i
return
else: else:
logger.info(f"User was signed up after {cut_off_date}, so checks will occur") logger.info(f"User was signed up after {cut_off_date}, so checks will occur")
@ -64,4 +67,32 @@ async def scan_posts():
await send_message(await post_to_analyse.get_as_image_deletion_text()) await send_message(await post_to_analyse.get_as_image_deletion_text())
await send_message(message_string, post_to_analyse.poster_username) 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 var.current_posts_at_start_time = current_posts_now

View File

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

1
var.py
View File

@ -24,6 +24,7 @@ old_chat = {}
scan_new_users_only = True scan_new_users_only = True
image_scanning_is_running = True image_scanning_is_running = True
text_scanning_is_running = True text_scanning_is_running = True
spam_scanning_is_running = True
most_recently_deleted_post_id = 0 most_recently_deleted_post_id = 0
current_posts_at_start_time = None current_posts_at_start_time = None
bot_started_at = None bot_started_at = None