2019-10-26 13:07:05 -04:00
|
|
|
import uuid from 'uuid/v4';
|
|
|
|
import { Client } from '..';
|
2019-10-26 00:01:49 -04:00
|
|
|
import { RichEmbed } from '../class';
|
|
|
|
|
|
|
|
export default function checkLock(client: Client) {
|
2019-10-28 16:21:04 -04:00
|
|
|
setInterval(async () => {
|
2019-10-26 00:01:49 -04:00
|
|
|
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-26 13:07:05 -04:00
|
|
|
const mod = new client.db.Moderation({
|
|
|
|
username: account.username,
|
|
|
|
userID: account.userID,
|
|
|
|
logID: uuid(),
|
|
|
|
moderatorID: client.user.id,
|
|
|
|
reason: 'Auto',
|
|
|
|
type: 3,
|
|
|
|
date: new Date(),
|
|
|
|
});
|
|
|
|
await mod.save();
|
2019-10-26 00:01:49 -04:00
|
|
|
const embed = new RichEmbed();
|
2019-10-26 13:07:05 -04:00
|
|
|
embed.setTitle('Account Infraction | Unlock');
|
2019-10-26 00:01:49 -04:00
|
|
|
embed.setColor(3066993);
|
|
|
|
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
|
|
|
|
embed.addField('Supervisor', 'SYSTEM', true);
|
|
|
|
embed.addField('Reason', 'Auto', true);
|
|
|
|
embed.setFooter(client.user.username, client.user.avatarURL);
|
|
|
|
embed.setTimestamp();
|
|
|
|
client.getDMChannel(account.userID).then((user) => {
|
|
|
|
// @ts-ignore
|
|
|
|
user.createMessage({ embed });
|
|
|
|
});
|
|
|
|
// @ts-ignore
|
|
|
|
client.createMessage('580950455581147146', { embed });
|
2019-10-28 16:21:04 -04:00
|
|
|
client.signale.complete(`Unlocked account ${account.username} | Queue date at ${moderation.expiration.date.toLocaleString('en-us')}`);
|
2019-10-26 00:01:49 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
await client.util.handleError(error);
|
|
|
|
}
|
2019-10-28 16:21:04 -04:00
|
|
|
}, 10000);
|
2019-10-26 00:01:49 -04:00
|
|
|
}
|