Files
Femboy-Croissant-Bot/functions/moderation/autoUnban.js
2025-08-30 18:05:01 +02:00

34 lines
1.3 KiB
JavaScript

// functions/moderation/autoUnban.js
module.exports = (client, db) => {
setInterval(async () => {
try {
const now = Date.now();
const [expiredBans] = await db.query(
'SELECT * FROM bans WHERE type = ? AND unbanDate <= ?',
['Temporary', now]
);
for (const ban of expiredBans) {
for (const guild of client.guilds.cache.values()) {
try {
await guild.members.unban(ban.userId, 'Temporary ban expired');
console.log(`Auto-unbanned ${ban.userId} from guild ${guild.id}`);
} catch (err) {
console.error(`Failed to unban ${ban.userId} from guild ${guild.id}`, err);
}
}
await db.query('DELETE FROM bans WHERE userId = ?', [ban.userId]);
await db.query(
`INSERT INTO logs (userId, userTag, modId, modTag, action, reason, type, timestamp)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[ban.userId, null, null, null, 'auto-unban', 'Temporary ban expired', null, Date.now()]
);
}
} catch (err) {
console.error('Error during auto-unban:', err);
}
}, 60_000);
};