module.exports = (member, db, client) => { if (!member.guild) return; // Ignore DMs if (member.user.bot) return; // Ignore bots db.get("SELECT * FROM guildConfigs WHERE guildId = ?", [member.guild.id], (err, config) => { if (err) { console.error("Database error:", err); return; } if (!config) { console.warn(`No configuration found for guild ${member.guild.id}`); return; } db.get("SELECT * FROM badActors WHERE id = ?", [member.id], (err, row) => { if (err) { console.error("Database error:", err); return; } if (row) { switch (config.mode) { case "none": return; // Literally do nothing lol break; case "warn": // Send a warning message in the logChannel break; // Just break, we send warning for everything else anyways case "kick": // Kick the user member.kick("Listed bad actor").then(() => { client.channels.fetch(config.logChannelId).then(logChan => { logChan.send({ content: `User <@${member.id}> has been kicked for being a bad actor. Reported by <@${row.reportedBy}>.` }).catch(console.error); }); } ).catch(err => { console.error("Failed to kick user:", err); }); break; case "ban": // Ban the user member.ban({ reason: "Listed bad actor" }).then(() => { client.channels.fetch(config.logChannelId).then(logChan => { logChan.send({ content: `User <@${member.id}> has been banned for being a bad actor. Reported by <@${row.reportedBy}>.` }).catch(console.error); }); }).catch(err => { console.error("Failed to ban user:", err); }); break; } client.channels.fetch(config.logChannelId).then(channel => { if (!channel) { console.warn(`Log channel ${config.logChannelId} not found in guild ${member.guild.id}`); return; } channel.send({ embeds: [{ title: "Bad Actor Detected", description: `User <@${member.id}> has joined the server and is listed as a bad actor.`, fields: [ { name: "Reported By", value: `<@${row.reportedBy}>`, inline: true }, { name: "Comment", value: row.comment || "No comment provided", inline: false }, { name: "Timestamp", value: ``, inline: true } ], color: 0xff0000 }], files: row.attachments ? JSON.parse(row.attachments).map(file => ({ attachment: path.join(__dirname, '../../storage', file), name: file })) : [] }).catch(console.error); }).catch(console.error); } }); }); }