1
0
Fork 0

Auto init

refactor/models
Bsian 2020-01-03 15:34:31 +00:00
parent c60b3ca216
commit bdfbb94ce7
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 9 additions and 5 deletions

View File

@ -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();
}
}
}