diff options
author | Minteck <contact@minteck.org> | 2022-05-27 15:11:35 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-05-27 15:11:35 +0200 |
commit | 02d6c9e573f4827940b688d9320bbde4e481ea77 (patch) | |
tree | a4f639afc2a2be0a1e74b83165f87dc29f3a8ca3 /refresh | |
parent | 006aaff302a0e4027f7daff5f5fa732b2dae686e (diff) | |
download | vaportrail-02d6c9e573f4827940b688d9320bbde4e481ea77.tar.gz vaportrail-02d6c9e573f4827940b688d9320bbde4e481ea77.tar.bz2 vaportrail-02d6c9e573f4827940b688d9320bbde4e481ea77.zip |
Enable PluralKit
Diffstat (limited to 'refresh')
-rw-r--r-- | refresh/pluralkit.js | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/refresh/pluralkit.js b/refresh/pluralkit.js index a0786e3..9f248d5 100644 --- a/refresh/pluralkit.js +++ b/refresh/pluralkit.js @@ -45,76 +45,80 @@ module.exports = () => { switches: null } - superagent.get(`https://api.pluralkit.me/v2/systems/${system}`) - .timeout({ - response: 5000, - }) - .then(data => data = data.body) - .then(data => { - status.general = data; - superagent.get(`https://api.pluralkit.me/v2/systems/${system}/members`) - .timeout({ - response: 5000, - }) - .then(data => data = data.body) - .then(data => { - status.members = data; - superagent.get(`https://api.pluralkit.me/v2/systems/${system}/fronters`) - .timeout({ - response: 5000, - }) - .then(data => data = data.body) - .then(data => { - status.fronters = data; - }) - .catch(reason => { - if (reason.timeout) { - // We timed out. - status.available = false; - } else { - if(reason.code === "ECONNREFUSED") { - status.available = false; - console.warn("Error querying PluralKit API.") - } else { - console.error(reason); - } - } - }) - .finally(() => { - stats[system] = status; + setTimeout(() => { + superagent.get(`https://api.pluralkit.me/v2/systems/${system}`) + .timeout({ + response: 5000, + }) + .then(data => data = data.body) + .then(data => { + status.general = data; + superagent.get(`https://api.pluralkit.me/v2/systems/${system}/members`) + .timeout({ + response: 5000, + }) + .then(data => data = data.body) + .then(data => { + status.members = data; + setTimeout(() => { + superagent.get(`https://api.pluralkit.me/v2/systems/${system}/fronters`) + .timeout({ + response: 5000, + }) + .then(data => data = data.body) + .then(data => { + status.fronters = data; + }) + .catch(reason => { + if (reason.timeout) { + // We timed out. + status.available = false; + } else { + if(reason.code === "ECONNREFUSED") { + status.available = false; + console.warn("Error querying PluralKit API.") + } else { + console.error(reason); + } + } + }) + .finally(() => { + stats[system] = status; - if(Object.keys(stats).length === systems.length) { - res(stats); - } - }); - }) - .catch(reason => { - if (reason.timeout) { - // We timed out. - status.available = false; - } else { - if(reason.code === "ECONNREFUSED") { + if(Object.keys(stats).length === systems.length) { + res(stats); + } + }); + }, 1000) + }) + .catch(reason => { + if (reason.timeout) { + // We timed out. status.available = false; - console.warn("Error querying PluralKit API.") } else { - console.error(reason); + if(reason.code === "ECONNREFUSED") { + status.available = false; + console.warn("Error querying PluralKit API.") + } else { + console.error(reason); + } } - } - }) - }) - .catch(reason => { - if (reason.timeout) { - // We timed out. - status.available = false; - } else { - if(reason.code === "ECONNREFUSED") { + }) + }) + .catch(reason => { + if (reason.timeout) { + // We timed out. status.available = false; - console.warn("Error querying PluralKit API.") } else { - console.error(reason); + if(reason.code === "ECONNREFUSED") { + status.available = false; + console.warn("Error querying PluralKit API.") + } else { + console.error(reason); + } } - } - }) + }) + }, 1000) } }); } |