diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 19:02:49 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 19:02:49 -0600 |
commit | 9b2856303374521b315759500cf594ec7f22d293 (patch) | |
tree | f1439e79f6b79ac2f32cfa08e58124bff553b502 | |
parent | 728994f435e781eeffcba739698a1c21bba76a83 (diff) | |
download | skyblock-api-9b2856303374521b315759500cf594ec7f22d293.tar.gz skyblock-api-9b2856303374521b315759500cf594ec7f22d293.tar.bz2 skyblock-api-9b2856303374521b315759500cf594ec7f22d293.zip |
fix some stats cutting off at the wrong place
-rw-r--r-- | build/cleaners/player.js | 1 | ||||
-rw-r--r-- | build/cleaners/rank.js | 1 | ||||
-rw-r--r-- | build/cleaners/skyblock/member.js | 3 | ||||
-rw-r--r-- | build/cleaners/skyblock/profile.js | 8 | ||||
-rw-r--r-- | build/cleaners/skyblock/stats.js | 6 | ||||
-rw-r--r-- | build/hypixel.js | 22 | ||||
-rw-r--r-- | build/hypixelCached.js | 13 | ||||
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 6 |
8 files changed, 26 insertions, 34 deletions
diff --git a/build/cleaners/player.js b/build/cleaners/player.js index 565ed70..ab1bea7 100644 --- a/build/cleaners/player.js +++ b/build/cleaners/player.js @@ -7,7 +7,6 @@ const util_1 = require("../util"); const profiles_1 = require("./skyblock/profiles"); async function cleanPlayerResponse(data) { // Cleans up a 'player' api response - console.log('cleanPlayerResponse', data.stats.SkyBlock.profiles); return { uuid: util_1.undashUuid(data.uuid), username: data.displayname, diff --git a/build/cleaners/rank.js b/build/cleaners/rank.js index 875d2db..2287d18 100644 --- a/build/cleaners/rank.js +++ b/build/cleaners/rank.js @@ -40,7 +40,6 @@ function parseRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo const rankColorPrefix = rankColors[name] ? '§' + rankColors[name] : ''; const nameWithoutPlus = name.split('+')[0]; const plusesInName = '+'.repeat(name.split('+').length - 1); - console.log(plusColor, nameWithoutPlus, plusesInName); if (plusColor && plusesInName.length >= 1) colored = `${rankColorPrefix}[${nameWithoutPlus}§${plusColor}${plusesInName}${rankColorPrefix}]`; else diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js index 74da48a..4cd0425 100644 --- a/build/cleaners/skyblock/member.js +++ b/build/cleaners/skyblock/member.js @@ -29,6 +29,7 @@ const stats_1 = require("./stats"); async function cleanSkyBlockProfileMemberResponse(member, included = null) { // profiles.members[] const statsIncluded = included == null || included.includes('stats'); + const inventoriesIncluded = included == null || included.includes('inventories'); return { uuid: member.uuid, username: await cached.usernameFromUser(member.uuid), @@ -38,7 +39,7 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) { stats: statsIncluded ? stats_1.cleanProfileStats(member === null || member === void 0 ? void 0 : member.stats) : undefined, minions: statsIncluded ? minions_1.cleanMinions(member) : undefined, fairy_souls: statsIncluded ? fairysouls_1.cleanFairySouls(member) : undefined, - inventories: statsIncluded ? await inventory_1.cleanInventories(member) : undefined, + inventories: inventoriesIncluded ? await inventory_1.cleanInventories(member) : undefined, }; } exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse; diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js index 5804bb5..7ef57ef 100644 --- a/build/cleaners/skyblock/profile.js +++ b/build/cleaners/skyblock/profile.js @@ -22,13 +22,15 @@ async function cleanSkyblockProfileResponseLighter(data) { }; } exports.cleanSkyblockProfileResponseLighter = cleanSkyblockProfileResponseLighter; -/** This function is somewhat costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data */ -async function cleanSkyblockProfileResponse(data) { +/** + * This function is somewhat costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data + */ +async function cleanSkyblockProfileResponse(data, { mainMemberUuid }) { const cleanedMembers = []; for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID]; memberRaw.uuid = memberUUID; - const member = await member_1.cleanSkyBlockProfileMemberResponse(memberRaw, ['stats']); + const member = await member_1.cleanSkyBlockProfileMemberResponse(memberRaw, ['stats', mainMemberUuid === memberUUID ? 'inventories' : undefined]); cleanedMembers.push(member); } const memberMinions = []; diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js index 81f5544..aa026db 100644 --- a/build/cleaners/skyblock/stats.js +++ b/build/cleaners/skyblock/stats.js @@ -23,8 +23,8 @@ function categorizeStat(statNameRaw) { } for (const categoryMatch of statCategoryMatchers) { // ['deaths_'] - let trailingEnd = categoryMatch[0] == '_'; - let trailingStart = categoryMatch.substr(-1) == '_'; + let trailingEnd = categoryMatch[0] === '_'; + let trailingStart = categoryMatch.substr(-1) === '_'; if (trailingStart && statNameRaw.startsWith(categoryMatch)) { return { category: statCategory, @@ -34,7 +34,7 @@ function categorizeStat(statNameRaw) { else if (trailingEnd && statNameRaw.endsWith(categoryMatch)) { return { category: statCategory, - name: statNameRaw.substr(0, categoryMatch.length) + name: statNameRaw.substr(0, statNameRaw.length - categoryMatch.length) }; } else if (statNameRaw == categoryMatch) { diff --git a/build/hypixel.js b/build/hypixel.js index 847fbdb..9c67fe6 100644 --- a/build/hypixel.js +++ b/build/hypixel.js @@ -32,34 +32,24 @@ const profiles_1 = require("./cleaners/skyblock/profiles"); exports.saveInterval = 60 * 3 * 1000; // the highest level a minion can be exports.maxMinion = 11; -/** - * Send a request to api.hypixel.net using a random key, clean it up to be more useable, and return it - */ -async function sendCleanApiRequest({ path, args }, included, cleaned = true) { +async function sendCleanApiRequest({ path, args }, included, options) { const key = await hypixelApi_1.chooseApiKey(); const rawResponse = await hypixelApi_1.sendApiRequest({ path, key, args }); if (rawResponse.throttled) { // if it's throttled, wait a second and try again console.log('throttled :/'); await new Promise(resolve => setTimeout(resolve, 1000)); - return await sendCleanApiRequest({ path, args }, included, cleaned); - } - if (cleaned) { - // if it needs to clean the response, call cleanResponse - return await cleanResponse({ path, data: rawResponse }, included = included); - } - else { - // this is provided in case the caller wants to do the cleaning itself - // used in skyblock/profile, as cleaning the entire profile would use too much cpu - return rawResponse; + return await sendCleanApiRequest({ path, args }, included, options); } + // clean the response + return await cleanResponse({ path, data: rawResponse }, options !== null && options !== void 0 ? options : {}); } exports.sendCleanApiRequest = sendCleanApiRequest; -async function cleanResponse({ path, data }, included) { +async function cleanResponse({ path, data }, options) { // Cleans up an api response switch (path) { case 'player': return await player_1.cleanPlayerResponse(data.player); - case 'skyblock/profile': return await profile_1.cleanSkyblockProfileResponse(data.profile); + case 'skyblock/profile': return await profile_1.cleanSkyblockProfileResponse(data.profile, options); case 'skyblock/profiles': return await profiles_1.cleanSkyblockProfilesResponse(data.profiles); } } diff --git a/build/hypixelCached.js b/build/hypixelCached.js index 9c63558..bf01171 100644 --- a/build/hypixelCached.js +++ b/build/hypixelCached.js @@ -121,6 +121,9 @@ async function fetchSkyblockProfiles(playerUuid) { args: { uuid: playerUuid } + }, null, { + // only the inventories for the main player are generated, this is for optimization purposes + mainMemberUuid: playerUuid }); const basicProfiles = []; // create the basicProfiles array @@ -154,7 +157,6 @@ async function fetchBasicProfiles(user) { const player = await fetchPlayer(playerUuid); const profiles = player.profiles; basicProfilesCache.set(playerUuid, profiles); - console.log(player); // cache the profile names and uuids to profileNameCache because we can for (const profile of profiles) profileNameCache.set(`${playerUuid}.${profile.uuid}`, profile.name); @@ -182,7 +184,8 @@ exports.fetchProfileUuid = fetchProfileUuid; * @param profile A profile name or profile uuid */ async function fetchProfile(user, profile) { - const profileUuid = await fetchProfileUuid(user, profile); + const playerUuid = await uuidFromUser(user); + const profileUuid = await fetchProfileUuid(playerUuid, profile); if (profileCache.has(profileUuid)) { console.log('cache hit! fetchProfile'); // we have the profile cached, return it :) @@ -191,10 +194,8 @@ async function fetchProfile(user, profile) { const profileName = await fetchProfileName(user, profile); const cleanProfile = await hypixel.sendCleanApiRequest({ path: 'skyblock/profile', - args: { - profile: profileUuid - } - }); + args: { profile: profileUuid } + }, null, { mainMemberUuid: playerUuid }); // we know the name from fetchProfileName, so set it here cleanProfile.name = profileName; profileCache.set(profileUuid, cleanProfile); diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index c4ff545..1222582 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -26,8 +26,8 @@ function categorizeStat(statNameRaw: string): statCategory { } for (const categoryMatch of statCategoryMatchers) { // ['deaths_'] - let trailingEnd = categoryMatch[0] == '_' - let trailingStart = categoryMatch.substr(-1) == '_' + let trailingEnd = categoryMatch[0] === '_' + let trailingStart = categoryMatch.substr(-1) === '_' if (trailingStart && statNameRaw.startsWith(categoryMatch)) { return { category: statCategory, @@ -36,7 +36,7 @@ function categorizeStat(statNameRaw: string): statCategory { } else if (trailingEnd && statNameRaw.endsWith(categoryMatch)) { return { category: statCategory, - name: statNameRaw.substr(0, categoryMatch.length) + name: statNameRaw.substr(0, statNameRaw.length - categoryMatch.length) } } else if (statNameRaw == categoryMatch) { // if it matches exactly, we don't know the name. will be defaulted to category later on |