From 6051cdb9b211fc02c919da4f33b64a50c87cb705 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 26 Sep 2025 23:30:44 -0700 Subject: feat(gateway:moderationAgent): Update agent context --- .../gateway/src/listeners/moderationAgent/constants.ts | 2 +- .../gateway/src/listeners/moderationAgent/utilities.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'packages/gateway') diff --git a/packages/gateway/src/listeners/moderationAgent/constants.ts b/packages/gateway/src/listeners/moderationAgent/constants.ts index b33f1b5..d01e751 100644 --- a/packages/gateway/src/listeners/moderationAgent/constants.ts +++ b/packages/gateway/src/listeners/moderationAgent/constants.ts @@ -7,7 +7,7 @@ export const MODERATION_LOG_CHANNEL_ID = "1406422619934167106"; export const MIN_MESSAGE_LENGTH = 15; export const MAX_SYMBOL_DENSITY = 0.6; export const MAX_COMPLETION_TOKENS = 2000; -export const MESSAGE_HISTORY_SIZE = 0; +export const MESSAGE_HISTORY_SIZE = 3; export const MODEL = "mistralai/mistral-nemo"; export const SAFE_WORDS = new Set([ "hello", diff --git a/packages/gateway/src/listeners/moderationAgent/utilities.ts b/packages/gateway/src/listeners/moderationAgent/utilities.ts index d2d0a06..aa0cbbc 100644 --- a/packages/gateway/src/listeners/moderationAgent/utilities.ts +++ b/packages/gateway/src/listeners/moderationAgent/utilities.ts @@ -77,6 +77,15 @@ export const analyzeMessageWithAI = async ( const member = guild?.members.cache.get(authorId); const authorRoles = member?.roles.cache.map(role => role.name).join(', ') || 'No roles'; const authorJoinedAt = member?.joinedAt?.toISOString() || 'Unknown'; + let repliedToMessage = null; + + if (message.reference && message.reference.messageId) + try { + repliedToMessage = await message.channel.messages.fetch(message.reference.messageId); + } catch (error) { + console.error("Error fetching replied-to message:", error); + } + const fullContext = ` === SERVER CONTEXT === Server: ${guildName} (ID: ${guildId}) @@ -92,6 +101,14 @@ Timestamp: ${message.createdAt.toISOString()} Length: ${messageLength} characters Has Attachments: ${hasAttachments} (${message.attachments.size} files) Has Embeds: ${hasEmbeds} (${message.embeds.length} embeds) +${repliedToMessage ? `Is Reply: Yes (replying to message from ${repliedToMessage.author.username})` : 'Is Reply: No'} + +${repliedToMessage ? `=== REPLIED-TO MESSAGE === +Replied-to Author: ${repliedToMessage.author.username} +Replied-to Message ID: ${repliedToMessage.id} +Replied-to Timestamp: ${repliedToMessage.createdAt.toISOString()} +Replied-to Content: "${repliedToMessage.content || '[No text content]'}" +` : ''} === AUTHOR CONTEXT === Username: ${author.username} @@ -201,6 +218,7 @@ ANALYSIS GUIDELINES: - Read the SERVER_RULES section carefully and only enforce those specific rules - Consider the channel context (NSFW vs SFW, channel purpose, etc.) - Look at the message history for additional context +- If this is a reply, consider the replied-to message context for better understanding - Be aware of the author's roles and server tenure - Consider cultural context and intent, not just literal text - Distinguish between serious violations and casual/joking content -- cgit v1.2.3