aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-05-27 15:11:35 +0200
committerMinteck <contact@minteck.org>2022-05-27 15:11:35 +0200
commit02d6c9e573f4827940b688d9320bbde4e481ea77 (patch)
treea4f639afc2a2be0a1e74b83165f87dc29f3a8ca3
parent006aaff302a0e4027f7daff5f5fa732b2dae686e (diff)
downloadvaportrail-02d6c9e573f4827940b688d9320bbde4e481ea77.tar.gz
vaportrail-02d6c9e573f4827940b688d9320bbde4e481ea77.tar.bz2
vaportrail-02d6c9e573f4827940b688d9320bbde4e481ea77.zip
Enable PluralKit
-rw-r--r--index.js4
-rw-r--r--refresh/pluralkit.js130
2 files changed, 69 insertions, 65 deletions
diff --git a/index.js b/index.js
index 7c54827..826e55e 100644
--- a/index.js
+++ b/index.js
@@ -67,10 +67,10 @@ function cacheReload() {
refresh().then(data => {
console.log("Refresh halfway done!");
serverCache = data;
- /*pkRefresh().then(data => {
+ pkRefresh().then(data => {
console.log("Refresh totally done!");
pluralCache = data;
- });*/
+ });
});
}
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)
}
});
}