From 93c5cd0df94aedaeade5b7f689dea2f1da9d760a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 26 Oct 2019 00:01:49 -0400 Subject: [PATCH] Add interval func to check lock expirations --- src/functions/checkLock.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/functions/checkLock.ts diff --git a/src/functions/checkLock.ts b/src/functions/checkLock.ts new file mode 100644 index 0000000..da83f11 --- /dev/null +++ b/src/functions/checkLock.ts @@ -0,0 +1,35 @@ +import Client from '../Client'; +import { RichEmbed } from '../class'; + +export default function checkLock(client: Client) { + setTimeout(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}`); + const embed = new RichEmbed(); + embed.setTitle('Cloud Infraction | Unlock'); + 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 }); + } + }); + } catch (error) { + await client.util.handleError(error); + } + }); +}