add autorelease interval func

merge-requests/5/head
Matthew 2020-04-15 15:13:06 -04:00
parent 14711de6de
commit bfe4c06835
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import { Client } from '../class';
let interval: NodeJS.Timeout;
export default function checkLock(client: Client) {
interval = setInterval(async () => {
try {
const moderations = await client.db.moderation.find();
moderations.forEach(async (moderation) => {
if (!moderation.expiration) return;
if (moderation.expiration.processed) return;
if (new Date() > moderation.expiration.date) {
await moderation.updateOne({ 'expiration.processed': true });
const moderator = client.guilds.get(client.config.guildID).members.get(moderation.moderatorID);
await client.util.moderation.unban(moderation.userID, moderator);
client.util.signale.complete(`Released member ${moderation.userID} | Queue date at ${moderation.expiration.date.toLocaleString('en-us')}`);
}
});
} catch (error) {
await client.util.handleError(error);
}
}, 10000);
return interval;
}