diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-13 16:30:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 16:30:27 -0500 |
commit | ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f (patch) | |
tree | 600846dd4804c487d16d33dd99ad4073d815e8f3 /build/constants.js | |
parent | c0d03a8d0c1e75967f48cb27d9c55bc4707af22c (diff) | |
download | skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.tar.gz skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.tar.bz2 skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.zip |
Slayer leaderboard (#4)
* add slayers to constants
* Compiled TS into JS
* change units to also show up when only changing one constant item
* Compiled TS into JS
* add slayer leaderboards
* remove debugging stuff
Diffstat (limited to 'build/constants.js')
-rw-r--r-- | build/constants.js | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/build/constants.js b/build/constants.js index 6344a12..96ae2e7 100644 --- a/build/constants.js +++ b/build/constants.js @@ -6,7 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addZones = exports.fetchZones = exports.addSkills = exports.fetchSkills = exports.addCollections = exports.fetchCollections = exports.addStats = exports.fetchStats = exports.addJSONConstants = void 0; +exports.addSlayers = exports.fetchSlayers = exports.addZones = exports.fetchZones = exports.addSkills = exports.fetchSkills = exports.addCollections = exports.fetchCollections = exports.addStats = exports.fetchStats = exports.addJSONConstants = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); const https_1 = require("https"); const node_cache_1 = __importDefault(require("node-cache")); @@ -30,14 +30,21 @@ const queue = new queue_promise_1.default({ * @param json The JSON body, only applicable for some types of methods */ async function fetchGithubApi(method, route, headers, json) { - return await node_fetch_1.default(githubApiBase + route, { - agent: () => httpsAgent, - body: json ? JSON.stringify(json) : null, - method, - headers: Object.assign({ - 'Authorization': `token ${process.env.github_token}` - }, headers), - }); + try { + return await node_fetch_1.default(githubApiBase + route, { + agent: () => httpsAgent, + body: json ? JSON.stringify(json) : null, + method, + headers: Object.assign({ + 'Authorization': `token ${process.env.github_token}` + }, headers), + }); + } + catch { + // if there's an error, wait a second and try again + await new Promise((resolve) => setTimeout(resolve, 1000)); + return await fetchGithubApi(method, route, headers, json); + } } // cache files for an hour const fileCache = new node_cache_1.default({ @@ -95,7 +102,7 @@ async function fetchJSONConstant(filename) { } } /** Add stats to skyblock-constants. This has caching so it's fine to call many times */ -async function addJSONConstants(filename, addingValues, units = 'stats') { +async function addJSONConstants(filename, addingValues, unit = 'stat') { if (addingValues.length === 0) return; // no stats provided, just return queue.enqueue(async () => { @@ -119,7 +126,7 @@ async function addJSONConstants(filename, addingValues, units = 'stats') { // there's not actually any new stats, just return if (newStats.length === 0) return; - const commitMessage = newStats.length >= 2 ? `Add ${newStats.length} new ${units}` : `Add '${newStats[0]}'`; + const commitMessage = newStats.length >= 2 ? `Add ${newStats.length} new ${unit}s` : `Add '${newStats[0]}' ${unit}`; await editFile(file, commitMessage, JSON.stringify(updatedStats, null, 2)); }); } @@ -131,7 +138,7 @@ async function fetchStats() { exports.fetchStats = fetchStats; /** Add stats to skyblock-constants. This has caching so it's fine to call many times */ async function addStats(addingStats) { - await addJSONConstants('stats.json', addingStats, 'stats'); + await addJSONConstants('stats.json', addingStats, 'stat'); } exports.addStats = addStats; /** Fetch all the known SkyBlock collections as an array of strings */ @@ -141,7 +148,7 @@ async function fetchCollections() { exports.fetchCollections = fetchCollections; /** Add collections to skyblock-constants. This has caching so it's fine to call many times */ async function addCollections(addingCollections) { - await addJSONConstants('collections.json', addingCollections, 'collections'); + await addJSONConstants('collections.json', addingCollections, 'collection'); } exports.addCollections = addCollections; /** Fetch all the known SkyBlock collections as an array of strings */ @@ -151,7 +158,7 @@ async function fetchSkills() { exports.fetchSkills = fetchSkills; /** Add skills to skyblock-constants. This has caching so it's fine to call many times */ async function addSkills(addingSkills) { - await addJSONConstants('skills.json', addingSkills, 'skills'); + await addJSONConstants('skills.json', addingSkills, 'skill'); } exports.addSkills = addSkills; /** Fetch all the known SkyBlock collections as an array of strings */ @@ -161,6 +168,16 @@ async function fetchZones() { exports.fetchZones = fetchZones; /** Add skills to skyblock-constants. This has caching so it's fine to call many times */ async function addZones(addingZones) { - await addJSONConstants('zones.json', addingZones, 'zones'); + await addJSONConstants('zones.json', addingZones, 'zone'); } exports.addZones = addZones; +/** Fetch all the known SkyBlock slayer names as an array of strings */ +async function fetchSlayers() { + return await fetchJSONConstant('slayers.json'); +} +exports.fetchSlayers = fetchSlayers; +/** Add skills to skyblock-constants. This has caching so it's fine to call many times */ +async function addSlayers(addingSlayers) { + await addJSONConstants('slayers.json', addingSlayers, 'slayer'); +} +exports.addSlayers = addSlayers; |