import { Events } from 'discord.js'; import { withConn } from '../db/pool.js'; import { chatAnswerWithMemory } from '../ai/gemini.js'; import filter from 'leo-profanity'; filter.loadDictionary('en'); export function registerMessageCreate(client) { client.on(Events.MessageCreate, async (message) => { if (!message.guild || message.author.bot) return; const guildId = message.guild.id; const cfg = await withConn(async (conn) => { const rows = await conn.query('SELECT ai_enabled, profanity_filter_enabled FROM guild_config WHERE guild_id = ? LIMIT 1', [guildId]); return rows[0]; }); // Profanity filter if (cfg?.profanity_filter_enabled) { if (filter.check(message.content)) { await message.delete().catch(() => null); return; } } // XP system: 10 XP per message await withConn(async (conn) => { await conn.query('INSERT INTO user_xp (guild_id, user_id, xp) VALUES (?, ?, 10) ON DUPLICATE KEY UPDATE xp = xp + 10', [guildId, message.author.id]); }); // Mention AI if (cfg?.ai_enabled && message.mentions.has(client.user)) { const question = message.content.replace(/<@!?\d+>/g, '').trim(); if (!question) return; const answer = await chatAnswerWithMemory(guildId, message.author.id, question).catch(() => 'Sorry, I could not process that right now.'); await message.reply(answer); } }); }