diff options
| -rw-r--r-- | packages/gateway/src/listeners/messageCreate/aiCommandHandler/index.ts | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/packages/gateway/src/listeners/messageCreate/aiCommandHandler/index.ts b/packages/gateway/src/listeners/messageCreate/aiCommandHandler/index.ts index d60547a..111c467 100644 --- a/packages/gateway/src/listeners/messageCreate/aiCommandHandler/index.ts +++ b/packages/gateway/src/listeners/messageCreate/aiCommandHandler/index.ts @@ -46,6 +46,25 @@ export const handleAICommand = async (message: Message) => { if (!content) return; + const commandKeywords = [ + "slowmode", + "slow", + "purge", + "delete", + "remove", + "clear", + "toggle", + "enable", + "disable", + "set", + "turn", + ]; + const hasCommandKeyword = commandKeywords.some((keyword) => + content.toLowerCase().includes(keyword.toLowerCase()), + ); + + if (!hasCommandKeyword) return; + try { const openai = new OpenAI({ baseURL: "https://openrouter.ai/api/v1", @@ -60,12 +79,18 @@ export const handleAICommand = async (message: Message) => { CRITICAL: Respond with ONLY valid JSON. No explanations, no markdown, no other text. +STRICT RULES: +- ONLY interpret messages that are CLEAR, EXPLICIT commands +- If the message is casual conversation, greeting, or unclear, respond with "unknown" +- The message MUST contain a clear intent to perform a moderation action +- Be VERY conservative - when in doubt, respond with "unknown" + Available commands: - slowmode: Toggle, enable, or disable slowmode in the current channel - purge: Delete messages from the current channel Respond with ONLY a JSON object in this exact format: -{"command": "slowmode|purge", "action": "toggle|enable|disable|last|from|lastfrom", "value": number, "user": "userid"} +{"command": "slowmode|purge|unknown", "action": "toggle|enable|disable|last|from|lastfrom|none", "value": number, "user": "userid"} Actions for slowmode: - "toggle" = switch current state @@ -80,7 +105,7 @@ Actions for purge: IMPORTANT: When user mentions someone with @username, use the provided user ID from the context. -Examples: +CLEAR COMMAND EXAMPLES (respond with command): "toggle slowmode" → {"command": "slowmode", "action": "toggle"} "enable slowmode" → {"command": "slowmode", "action": "enable", "value": 5} "set slowmode to 10" → {"command": "slowmode", "action": "enable", "value": 10} @@ -89,7 +114,14 @@ Examples: "purge all messages from @user" → {"command": "purge", "action": "from", "user": "userid"} "purge the last 5 messages from @user" → {"command": "purge", "action": "lastfrom", "value": 5, "user": "userid"} -If input doesn't match available commands, respond with: +UNCLEAR/CASUAL EXAMPLES (respond with unknown): +"hey bot" → {"command": "unknown", "action": "none", "value": 0} +"how are you?" → {"command": "unknown", "action": "none", "value": 0} +"thanks for helping" → {"command": "unknown", "action": "none", "value": 0} +"can you do something about the spam?" → {"command": "unknown", "action": "none", "value": 0} +"this channel is getting messy" → {"command": "unknown", "action": "none", "value": 0} + +If input doesn't match available commands or is unclear, respond with: {"command": "unknown", "action": "none", "value": 0} RESPONSE MUST BE ONLY JSON. NO OTHER TEXT.`, @@ -135,6 +167,8 @@ const executeAICommand = async ( message: Message, commandData: AICommandResponse, ) => { + if (commandData.command === "unknown") return; + if (commandData.command === "slowmode") await handleSlowmodeCommand(message, commandData); else if (commandData.command === "purge") |