Auto init
parent
c60b3ca216
commit
bdfbb94ce7
|
@ -7,21 +7,25 @@ export default function checkSS(client: Client) {
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const accounts = await client.db.Account.find();
|
const accounts = await client.db.Account.find();
|
||||||
const hashes = accounts.filter((h) => h.hash);
|
for (const { userID, homepath, hash } of accounts) {
|
||||||
for (const { userID, homepath } of hashes) {
|
|
||||||
try {
|
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');
|
if (hash === null) throw new Error('Unable to locate auth file, homepath is probably incorrect');
|
||||||
await axios({
|
await axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: 'https://api.securesign.org/account/details',
|
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) {
|
} catch (error) {
|
||||||
|
if (!hash) return;
|
||||||
const { status } = error.response;
|
const { status } = error.response;
|
||||||
if (status === 400 || status === 401 || status === 403 || status === 404) {
|
if (status === 400 || status === 401 || status === 403 || status === 404) {
|
||||||
await client.db.Account.updateOne({ userID }, { $set: { hash: false } });
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue