community-relations/src/intervals/autoRelease.ts

25 lines
977 B
TypeScript
Raw Normal View History

2020-04-15 15:13:06 -04:00
import { Client } from '../class';
let interval: NodeJS.Timeout;
2020-05-06 19:34:00 -04:00
export default function checkLock(client: Client): NodeJS.Timeout {
2020-04-15 15:13:06 -04:00
interval = setInterval(async () => {
try {
const moderations = await client.db.Moderation.find();
2020-04-15 15:13:06 -04:00
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;
}