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