Add files via upload
This commit is contained in:
33
functions/moderation/autoUnban.js
Normal file
33
functions/moderation/autoUnban.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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);
|
||||
};
|
||||
Reference in New Issue
Block a user