From bdfbb94ce79d03aba28e3c7de82d0cf034dd8925 Mon Sep 17 00:00:00 2001 From: Bsian Date: Fri, 3 Jan 2020 15:34:31 +0000 Subject: [PATCH] Auto init --- src/functions/checkSS.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 0b132d6..0367324 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -7,21 +7,25 @@ export default function checkSS(client: Client) { setInterval(async () => { try { const accounts = await client.db.Account.find(); - const hashes = accounts.filter((h) => h.hash); - for (const { userID, homepath } of hashes) { + for (const { userID, homepath, hash } of accounts) { try { - const hash = client.util.getAcctHash(homepath); + const Authorization = client.util.getAcctHash(homepath); if (hash === null) throw new Error('Unable to locate auth file, homepath is probably incorrect'); await axios({ method: 'get', url: 'https://api.securesign.org/account/details', - headers: { Authorization: hash }, + headers: { Authorization }, }); + if (!hash) { + await client.db.Account.updateOne({ userID }, { $set: { hash: true } }); + client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign account has been automatically initialized via the SecureSign CLI.')).catch(); + } } catch (error) { + if (!hash) return; const { status } = error.response; if (status === 400 || status === 401 || status === 403 || status === 404) { await client.db.Account.updateOne({ userID }, { $set: { hash: false } }); - client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); + client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account. Run `=securesign init` for more information')).catch(); } } }