Initial commit
This commit is contained in:
31
dist/events/guildBanKickLog.js
vendored
Normal file
31
dist/events/guildBanKickLog.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Events } from 'discord.js';
|
||||
import { withConn } from '../db/pool.js';
|
||||
async function getLogsChannelId(guildId) {
|
||||
const row = await withConn(async (conn) => {
|
||||
const rows = await conn.query('SELECT logs_enabled, logs_channel_id FROM guild_config WHERE guild_id = ? LIMIT 1', [guildId]);
|
||||
return rows[0];
|
||||
});
|
||||
if (!row?.logs_enabled || !row.logs_channel_id)
|
||||
return null;
|
||||
return row.logs_channel_id;
|
||||
}
|
||||
export function registerModerationLogs(client) {
|
||||
client.on(Events.GuildBanAdd, async (ban) => {
|
||||
const channelId = await getLogsChannelId(ban.guild.id);
|
||||
if (!channelId)
|
||||
return;
|
||||
const channel = ban.guild.channels.cache.get(channelId);
|
||||
if (!channel || !('send' in channel))
|
||||
return;
|
||||
await channel.send(`User banned: <@${ban.user.id}>`);
|
||||
});
|
||||
client.on(Events.GuildMemberRemove, async (member) => {
|
||||
const channelId = await getLogsChannelId(member.guild.id);
|
||||
if (!channelId)
|
||||
return;
|
||||
const channel = member.guild.channels.cache.get(channelId);
|
||||
if (!channel || !('send' in channel))
|
||||
return;
|
||||
await channel.send(`Member left or was kicked: <@${member.id}>`);
|
||||
});
|
||||
}
|
||||
35
dist/events/messageCreate.js
vendored
Normal file
35
dist/events/messageCreate.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user