2020-07-06 03:15:06 -04:00
|
|
|
import { Client } from '../class';
|
|
|
|
|
|
|
|
let interval: NodeJS.Timeout;
|
|
|
|
|
|
|
|
export default function checkLock(client: Client): NodeJS.Timeout {
|
|
|
|
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 });
|
2020-07-09 04:41:29 -04:00
|
|
|
// const moderator = client.guilds.get(client.config.guildID).members.get(moderation.moderatorID);
|
|
|
|
const system = client.guilds.get(client.config.guildID).members.get(client.user.id);
|
|
|
|
switch (moderation.type) {
|
|
|
|
case 5:
|
|
|
|
await client.util.moderation.unban(moderation.userID, system);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (await client.db.local.get<boolean>(`muted-${moderation.userID}`) === true) {
|
|
|
|
await client.util.moderation.unmute(moderation.userID, system);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-07-06 03:15:06 -04:00
|
|
|
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;
|
|
|
|
}
|