aboutsummaryrefslogtreecommitdiff
path: root/refresh/pluralkit.js
diff options
context:
space:
mode:
Diffstat (limited to 'refresh/pluralkit.js')
-rw-r--r--refresh/pluralkit.js130
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)
}
});
}