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

29 lines
1.3 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_remove 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_remove) {
try {
const existingBan = await db.get("SELECT * FROM bans WHERE list_id = ? AND user_id = ?", [list.id, ban.user.id]);
if (!existingBan) {
// Not banned on this list
continue;
}
await db.run("DELETE FROM bans WHERE list_id = ? AND user_id = ?", [list.id, ban.user.id]);
} catch (e) {
console.log(`[ERROR] Could not auto-remove ban for user ${ban.user.id} in guild ${guild.id}:`, e);
}
}
}
});
};