From 7a38e68048df8730f0ae58b4be22e6379f7c5060 Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 3 Jan 2020 15:55:23 +0000 Subject: [PATCH] Allow clearing of function --- src/functions/checkLock.ts | 11 +++++++++-- src/functions/checkSS.ts | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/functions/checkLock.ts b/src/functions/checkLock.ts index 8ef6313..da8d33f 100644 --- a/src/functions/checkLock.ts +++ b/src/functions/checkLock.ts @@ -1,7 +1,9 @@ import { Client } from '..'; -export default function checkLock(client: Client): void { - setInterval(async () => { +let interval: NodeJS.Timeout; + +export default function checkLock(client: Client) { + interval = setInterval(async () => { try { const moderations = await client.db.Moderation.find(); moderations.forEach(async (moderation) => { @@ -21,4 +23,9 @@ export default function checkLock(client: Client): void { await client.util.handleError(error); } }, 10000); + return interval; +} + +export function clear() { + clearInterval(interval); } diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 0367324..3a8e75e 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -3,8 +3,9 @@ import axios from 'axios'; import { inspect } from 'util'; import { Client } from '..'; +let interval: NodeJS.Timeout; export default function checkSS(client: Client) { - setInterval(async () => { + interval = setInterval(async () => { try { const accounts = await client.db.Account.find(); for (const { userID, homepath, hash } of accounts) { @@ -33,4 +34,9 @@ export default function checkSS(client: Client) { client.util.handleError(error); } }, 60000); + return interval; +} + +export function clear() { + clearTimeout(interval); }