diff options
author | mat-1 <github@matdoes.dev> | 2021-05-03 01:38:56 +0000 |
---|---|---|
committer | mat-1 <github@matdoes.dev> | 2021-05-03 01:38:56 +0000 |
commit | 0a1fc6998a7f0c0cdb7c48ce5ad024ac30490de2 (patch) | |
tree | f06f88744f91b016efaa31e4c33860036657ed9b | |
parent | fbd9446806ad3535435729179276ecca4df319d5 (diff) | |
download | skyblock-api-0a1fc6998a7f0c0cdb7c48ce5ad024ac30490de2.tar.gz skyblock-api-0a1fc6998a7f0c0cdb7c48ce5ad024ac30490de2.tar.bz2 skyblock-api-0a1fc6998a7f0c0cdb7c48ce5ad024ac30490de2.zip |
Compiled TS into JS
-rw-r--r-- | build/cleaners/skyblock/member.js | 7 | ||||
-rw-r--r-- | build/cleaners/skyblock/profile.js | 27 | ||||
-rw-r--r-- | build/constants.js | 30 | ||||
-rw-r--r-- | build/index.js | 23 |
4 files changed, 84 insertions, 3 deletions
diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js index 218518d..a9a419a 100644 --- a/build/cleaners/skyblock/member.js +++ b/build/cleaners/skyblock/member.js @@ -30,6 +30,7 @@ const slayers_1 = require("./slayers"); const zones_1 = require("./zones"); const skills_1 = require("./skills"); const cached = __importStar(require("../../hypixelCached")); +const constants = __importStar(require("../../constants")); async function cleanSkyBlockProfileMemberResponseBasic(member, included = null) { const player = await cached.fetchPlayer(member.uuid); return { @@ -49,6 +50,10 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) { const player = await cached.fetchPlayer(member.uuid); if (!player) return; + const fairySouls = fairysouls_1.cleanFairySouls(member); + const { max_fairy_souls: maxFairySouls } = await constants.fetchConstantValues(); + if (fairySouls.total > (maxFairySouls !== null && maxFairySouls !== void 0 ? maxFairySouls : 0)) + await constants.setConstantValues({ max_fairy_souls: fairySouls.total }); return { uuid: member.uuid, username: player.username, @@ -60,7 +65,7 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) { // this is used for leaderboards rawHypixelStats: (_a = member.stats) !== null && _a !== void 0 ? _a : {}, minions: await minions_1.cleanMinions(member), - fairy_souls: fairysouls_1.cleanFairySouls(member), + fairy_souls: fairySouls, inventories: inventoriesIncluded ? await inventory_1.cleanInventories(member) : undefined, objectives: objectives_1.cleanObjectives(member), skills: skills_1.cleanSkills(member), diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js index ba2c030..2ddcb83 100644 --- a/build/cleaners/skyblock/profile.js +++ b/build/cleaners/skyblock/profile.js @@ -1,9 +1,29 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanSkyblockProfileResponse = exports.cleanSkyblockProfileResponseLighter = void 0; const member_1 = require("./member"); const minions_1 = require("./minions"); const bank_1 = require("./bank"); +const constants = __importStar(require("../../constants")); /** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */ async function cleanSkyblockProfileResponseLighter(data) { // We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete @@ -49,6 +69,11 @@ async function cleanSkyblockProfileResponse(data, options) { memberMinions.push(member.minions); } const minions = minions_1.combineMinionArrays(memberMinions); + const { max_minions: maxUniqueMinions } = await constants.fetchConstantValues(); + const uniqueMinions = minions_1.countUniqueMinions(minions); + console.log(uniqueMinions, (maxUniqueMinions !== null && maxUniqueMinions !== void 0 ? maxUniqueMinions : 0), uniqueMinions > (maxUniqueMinions !== null && maxUniqueMinions !== void 0 ? maxUniqueMinions : 0)); + if (uniqueMinions > (maxUniqueMinions !== null && maxUniqueMinions !== void 0 ? maxUniqueMinions : 0)) + await constants.setConstantValues({ max_minions: uniqueMinions }); // return more detailed info return { uuid: data.profile_id, @@ -56,7 +81,7 @@ async function cleanSkyblockProfileResponse(data, options) { members: cleanedMembers, bank: bank_1.cleanBank(data), minions: minions, - minion_count: minions_1.countUniqueMinions(minions) + minion_count: uniqueMinions }; } exports.cleanSkyblockProfileResponse = cleanSkyblockProfileResponse; diff --git a/build/constants.js b/build/constants.js index 91c862c..3c0c7e9 100644 --- a/build/constants.js +++ b/build/constants.js @@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addMinions = exports.fetchMinions = exports.addSlayers = exports.fetchSlayers = exports.addZones = exports.fetchZones = exports.addSkills = exports.fetchSkills = exports.addCollections = exports.fetchCollections = exports.addStats = exports.fetchStats = exports.addJSONConstants = exports.fetchJSONConstant = void 0; +exports.setConstantValues = exports.fetchConstantValues = exports.addMinions = exports.fetchMinions = exports.addSlayers = exports.fetchSlayers = exports.addZones = exports.fetchZones = exports.addSkills = exports.fetchSkills = exports.addCollections = exports.fetchCollections = exports.addStats = exports.fetchStats = exports.addJSONConstants = exports.fetchJSONConstant = void 0; // we have to do this so we can mock the function from the tests properly const constants = __importStar(require("./constants")); const node_cache_1 = __importDefault(require("node-cache")); @@ -225,3 +225,31 @@ async function addMinions(addingMinions) { await constants.addJSONConstants('minions.json', addingMinions, 'minion'); } exports.addMinions = addMinions; +async function fetchConstantValues() { + return await constants.fetchJSONConstant('values.json'); +} +exports.fetchConstantValues = fetchConstantValues; +async function setConstantValues(newValues) { + let file = await fetchFile('values.json'); + if (!file.path) + return; + let oldValues; + try { + oldValues = JSON.parse(file.content); + } + catch { + // invalid json, set it as an empty array + oldValues = {}; + } + const updatedStats = { ...oldValues, ...newValues }; + // there's not actually any new stats, just return + // TODO: optimize this? might be fine already though, idk + if (JSON.stringify(updatedStats) === JSON.stringify(oldValues)) + return; + const commitMessage = 'Update values'; + try { + await editFile(file, commitMessage, JSON.stringify(updatedStats, null, 2)); + } + catch { } +} +exports.setConstantValues = setConstantValues; diff --git a/build/index.js b/build/index.js index f499c21..c7f1385 100644 --- a/build/index.js +++ b/build/index.js @@ -1,4 +1,23 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -7,6 +26,7 @@ exports.debug = void 0; const database_1 = require("./database"); const hypixel_1 = require("./hypixel"); const express_rate_limit_1 = __importDefault(require("express-rate-limit")); +const constants = __importStar(require("./constants")); const express_1 = __importDefault(require("express")); const app = express_1.default(); exports.debug = false; @@ -51,6 +71,9 @@ app.get('/leaderboard/:name', async (req, res) => { app.get('/leaderboards', async (req, res) => { res.json(await database_1.fetchAllLeaderboardsCategorized()); }); +app.get('/constants', async (req, res) => { + res.json(await constants.fetchConstantValues()); +}); // only run the server if it's not doing tests if (!globalThis.isTest) app.listen(8080, () => console.log('App started :)')); |