update
This commit is contained in:
@@ -163,23 +163,35 @@ class AIModeration(commands.Cog):
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message) -> None:
|
||||
"""Analyze messages with AI moderation."""
|
||||
print(f"[AI_MOD] Received message from {message.author}", flush=True)
|
||||
|
||||
# Skip bot messages early
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
if not message.guild:
|
||||
return
|
||||
|
||||
logger.info(f"AI mod checking message from {message.author} in {message.guild.name}")
|
||||
|
||||
# Check if AI moderation is enabled for this guild
|
||||
config = await self.bot.guild_config.get_config(message.guild.id)
|
||||
if not config or not config.ai_moderation_enabled:
|
||||
logger.debug(f"AI moderation disabled for guild {message.guild.id}")
|
||||
return
|
||||
|
||||
# Skip users with manage_messages permission
|
||||
if isinstance(message.author, discord.Member):
|
||||
if message.author.guild_permissions.manage_messages:
|
||||
return
|
||||
# Skip users with manage_messages permission (disabled for testing)
|
||||
# if isinstance(message.author, discord.Member):
|
||||
# if message.author.guild_permissions.manage_messages:
|
||||
# logger.debug(f"Skipping message from privileged user {message.author}")
|
||||
# return
|
||||
|
||||
if not self._should_analyze(message):
|
||||
logger.debug(f"Message {message.id} skipped by _should_analyze")
|
||||
return
|
||||
|
||||
self._track_message(message.id)
|
||||
logger.info(f"Analyzing message {message.id} from {message.author}")
|
||||
|
||||
# Analyze text content
|
||||
if message.content and len(message.content) >= 20:
|
||||
@@ -195,16 +207,21 @@ class AIModeration(commands.Cog):
|
||||
|
||||
# Analyze images if NSFW detection is enabled (limit to 3 per message)
|
||||
if config.nsfw_detection_enabled and message.attachments:
|
||||
logger.info(f"Checking {len(message.attachments)} attachments for NSFW content")
|
||||
images_analyzed = 0
|
||||
for attachment in message.attachments:
|
||||
if images_analyzed >= 3:
|
||||
break
|
||||
if attachment.content_type and attachment.content_type.startswith("image/"):
|
||||
images_analyzed += 1
|
||||
logger.info(f"Analyzing image: {attachment.url[:80]}...")
|
||||
image_result = await self.bot.ai_provider.analyze_image(
|
||||
image_url=attachment.url,
|
||||
sensitivity=config.ai_sensitivity,
|
||||
)
|
||||
logger.info(
|
||||
f"Image result: nsfw={image_result.is_nsfw}, violent={image_result.is_violent}, conf={image_result.confidence}"
|
||||
)
|
||||
|
||||
if (
|
||||
image_result.is_nsfw
|
||||
|
||||
Reference in New Issue
Block a user