bansync/banHandler.js
2026-01-17 16:05:33 -07:00

29 lines
1.4 KiB
JavaScript

const colors = require('colors');
module.exports = async (ban, db, client) => {
// Fetch perms this guild has
const guild = await client.guilds.fetch(ban.guild.id);
db.all("SELECT list_id, auto_add FROM perms WHERE entity_id = ? AND entity_type = 'guild'", [ban.guild.id], async (err, lists) => {
;
for (const entry of lists) {
const list = await db.get("SELECT * FROM lists WHERE id = ?", [entry.list_id]);
if (!list) {
console.log(`${colors.red('[ERROR]')} List not found for id ${entry.list_id}. How'd we get here?`);
continue;
}
if (entry.auto_add) {
try {
const existingBan = await db.get("SELECT * FROM bans WHERE list_id = ? AND user_id = ?", [list.id, ban.user.id]);
if (existingBan) {
// Already banned on this list
continue;
}
await db.run("INSERT INTO bans (list_id, user_id, reason, banned_by) VALUES (?, ?, ?, ?)", [list.id, ban.user.id, `${ban.reason || 'No reason provided'} | Sync from ${guild.id}`, `${ban.guild.id} (Auto-add)`]);
} catch (e) {
console.log(`[ERROR] Could not auto-add ban for user ${ban.user.id} in guild ${guild.id}:`, e);
}
}
}
});
};