From cb6049361ebfbf36b1438f091a0d30053ad21c96 Mon Sep 17 00:00:00 2001 From: latte Date: Tue, 27 Jan 2026 19:58:40 +0100 Subject: [PATCH] feat: Add user blocklist for instant media deletion Add blocklist feature to automatically delete ALL media (images, GIFs, embeds, URLs) from specific users without AI analysis. Changes: - Add blocked_user_ids config field to config.yml - Implement blocklist check in ai_moderation.py (runs before AI checks) - Update README.md with blocklist documentation Benefits: - No AI cost (instant deletion) - Useful for known spam accounts or problematic users - Blocks all media types: attachments, embeds, URLs - Logged for moderation tracking --- README.md | 29 +++++++++++++++++++++++------ config.yml | 6 ++++++ src/guardden/cogs/ai_moderation.py | 23 ++++++++++++++++++++++- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9e8787c..b83b9e0 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,10 @@ ai_moderation: check_video_thumbnails: false # Skip video thumbnails url_image_check_enabled: false # Skip URL image downloads +# User blocklist (blocks ALL media from specific users) +blocked_user_ids: + - 123456789012345678 # Discord user ID to block + # Known NSFW video domains (auto-block) nsfw_video_domains: - pornhub.com @@ -160,6 +164,12 @@ nsfw_video_domains: - `duplicate_threshold`: How many duplicate messages trigger action - `mention_limit`: Max @mentions allowed per message +**User Blocklist:** +- `blocked_user_ids`: List of Discord user IDs to block +- Automatically deletes ALL images, GIFs, embeds, and URLs from these users +- No AI cost - instant deletion +- Useful for known problematic users or spam accounts + **Cost Controls:** The bot includes multiple layers of cost control: - Rate limiting (25 AI checks/hour/guild, 5/hour/user by default) @@ -222,6 +232,12 @@ guardden/ ## How It Works +### User Blocklist (Instant, No AI Cost) +1. Checks if message author is in `blocked_user_ids` list +2. If message contains ANY media (images, embeds, URLs), instantly deletes it +3. No AI analysis needed - immediate action +4. Useful for known spam accounts or problematic users + ### Spam Detection 1. Bot monitors message rate per user 2. Detects duplicate messages @@ -229,12 +245,13 @@ guardden/ 4. Violations result in message deletion + timeout ### NSFW Image Detection -1. Bot checks attachments and embeds for images -2. Applies rate limiting and deduplication -3. Downloads image and sends to AI provider -4. AI analyzes for NSFW content categories -5. Violations result in message deletion + timeout -6. Optionally checks known NSFW video domain links +1. Checks user blocklist first (instant deletion if matched) +2. Checks NSFW video domain blocklist (instant deletion) +3. Bot checks attachments and embeds for images +4. Applies rate limiting and deduplication +5. Downloads image and sends to AI provider +6. AI analyzes for NSFW content categories +7. Violations result in message deletion + timeout ### Cost Management The bot includes aggressive cost controls for AI usage: diff --git a/config.yml b/config.yml index 3d9cc12..82cf76c 100644 --- a/config.yml +++ b/config.yml @@ -36,6 +36,12 @@ ai_moderation: check_video_thumbnails: false # Skip video thumbnails (disabled per user request) url_image_check_enabled: false # Skip URL image downloads (disabled per user request) +# User Blocklist (No AI cost) +# Block all images, GIFs, embeds, and URLs from these users +# Add Discord user IDs here +blocked_user_ids: + # Example: - 123456789012345678 + # NSFW Video Domain Blocklist (No AI cost) # These domains are blocked instantly without AI analysis nsfw_video_domains: diff --git a/src/guardden/cogs/ai_moderation.py b/src/guardden/cogs/ai_moderation.py index 8fe782c..49acba8 100644 --- a/src/guardden/cogs/ai_moderation.py +++ b/src/guardden/cogs/ai_moderation.py @@ -92,7 +92,28 @@ class AIModeration(commands.Cog): if not config.get_setting("ai_moderation.enabled", True): return - # Check NSFW video domain blocklist first (no AI cost) + # Check user blocklist first (blocks ALL media from specific users) + blocked_users = config.get_setting("blocked_user_ids", []) + if message.author.id in blocked_users: + # Check if message has any media content (images, embeds, URLs) + has_media = ( + bool(message.attachments) or + bool(message.embeds) or + bool(URL_PATTERN.search(message.content)) + ) + + if has_media: + try: + await message.delete() + logger.info( + f"Deleted media content from blocked user {message.author} " + f"({message.author.id}) in {message.guild.name}" + ) + except (discord.Forbidden, discord.NotFound): + logger.warning(f"Failed to delete message from blocked user {message.author.id}") + return + + # Check NSFW video domain blocklist (no AI cost) if self._has_nsfw_video_link(message.content): try: await message.delete()