1
0
Fork 0
cloudservices/src/functions/checkLock.ts

25 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-10-26 13:07:05 -04:00
import { Client } from '..';
2019-11-16 14:19:24 -05:00
export default function checkLock(client: Client): void {
2019-10-28 16:21:04 -04:00
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) {
const account = await client.db.Account.findOne({ username: moderation.username });
if (!account) return;
await client.util.exec(`unlock ${account.username}`);
2019-10-28 16:21:04 -04:00
await moderation.updateOne({ 'expiration.processed': true });
await account.updateOne({ locked: false });
2019-10-29 14:20:51 -04:00
await client.util.createModerationLog(account.userID, client.user, 3, 'Auto');
2019-10-28 16:21:04 -04:00
client.signale.complete(`Unlocked account ${account.username} | Queue date at ${moderation.expiration.date.toLocaleString('en-us')}`);
}
});
} catch (error) {
await client.util.handleError(error);
}
2019-10-28 16:21:04 -04:00
}, 10000);
}