diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 14:35:58 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 14:35:58 -0600 |
commit | 68c07e7a5ab8acf5ba7785eed594497e05467061 (patch) | |
tree | bf29688d541e817ea1d7e1dbdb0c83233a643530 /build | |
parent | f1c18020d5d86aac6119c842e6a108d99fae6e51 (diff) | |
download | skyblock-api-68c07e7a5ab8acf5ba7785eed594497e05467061.tar.gz skyblock-api-68c07e7a5ab8acf5ba7785eed594497e05467061.tar.bz2 skyblock-api-68c07e7a5ab8acf5ba7785eed594497e05467061.zip |
create member, profile, and profiles cleaners
Diffstat (limited to 'build')
-rw-r--r-- | build/cleaners/player.js | 4 | ||||
-rw-r--r-- | build/cleaners/skyblock/member.js | 40 | ||||
-rw-r--r-- | build/cleaners/skyblock/profile.js | 51 | ||||
-rw-r--r-- | build/cleaners/skyblock/profiles.js | 26 | ||||
-rw-r--r-- | build/hypixel.js | 89 |
5 files changed, 124 insertions, 86 deletions
diff --git a/build/cleaners/player.js b/build/cleaners/player.js index 25ae1f2..565ed70 100644 --- a/build/cleaners/player.js +++ b/build/cleaners/player.js @@ -1,10 +1,10 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanPlayerResponse = void 0; -const hypixel_1 = require("../hypixel"); const socialmedia_1 = require("./socialmedia"); const rank_1 = require("./rank"); 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); @@ -13,7 +13,7 @@ async function cleanPlayerResponse(data) { username: data.displayname, rank: rank_1.parseRank(data), socials: socialmedia_1.parseSocialMedia(data.socialMedia), - profiles: hypixel_1.cleanPlayerSkyblockProfiles(data.stats.SkyBlock.profiles) + profiles: profiles_1.cleanPlayerSkyblockProfiles(data.stats.SkyBlock.profiles) }; } exports.cleanPlayerResponse = cleanPlayerResponse; diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js new file mode 100644 index 0000000..b10a619 --- /dev/null +++ b/build/cleaners/skyblock/member.js @@ -0,0 +1,40 @@ +"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.cleanSkyBlockProfileMemberResponse = void 0; +const cached = __importStar(require("../../hypixelCached")); +const minions_1 = require("./minions"); +const stats_1 = require("./stats"); +/** Cleans up a member (from skyblock/profile) */ +async function cleanSkyBlockProfileMemberResponse(member, included = null) { + // profiles.members[] + const statsIncluded = included == null || included.includes('stats'); + return { + uuid: member.uuid, + username: await cached.usernameFromUser(member.uuid), + last_save: member.last_save, + first_join: member.first_join, + // last_death: ??? idk how this is formatted, + stats: statsIncluded ? stats_1.cleanProfileStats(member.stats) : undefined, + minions: statsIncluded ? minions_1.cleanMinions(member.crafted_generators) : undefined, + }; +} +exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse; diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js new file mode 100644 index 0000000..f7d9e8b --- /dev/null +++ b/build/cleaners/skyblock/profile.js @@ -0,0 +1,51 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cleanSkyblockProfileResponse = exports.cleanSkyblockProfileResponseLighter = void 0; +const member_1 = require("./member"); +const minions_1 = require("./minions"); +/** 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 + const promises = []; + for (const memberUUID in data.members) { + const memberRaw = data.members[memberUUID]; + memberRaw.uuid = memberUUID; + // we pass an empty array to make it not check stats + promises.push(member_1.cleanSkyBlockProfileMemberResponse(memberRaw, [])); + } + const cleanedMembers = await Promise.all(promises); + return { + uuid: data.profile_id, + name: data.cute_name, + members: cleanedMembers, + }; +} +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) { + const cleanedMembers = []; + for (const memberUUID in data.members) { + const memberRaw = data.members[memberUUID]; + memberRaw.uuid = memberUUID; + const member = await member_1.cleanSkyBlockProfileMemberResponse(memberRaw, ['stats']); + cleanedMembers.push(member); + } + const memberMinions = []; + for (const member of cleanedMembers) { + memberMinions.push(member.minions); + } + const minions = minions_1.combineMinionArrays(memberMinions); + // return more detailed info + return { + uuid: data.profile_id, + name: data.cute_name, + members: cleanedMembers, + bank: { + balance: data?.banking?.balance ?? 0, + // TODO: make transactions good + history: data?.banking?.transactions ?? [] + }, + minions + }; +} +exports.cleanSkyblockProfileResponse = cleanSkyblockProfileResponse; diff --git a/build/cleaners/skyblock/profiles.js b/build/cleaners/skyblock/profiles.js new file mode 100644 index 0000000..b79fc56 --- /dev/null +++ b/build/cleaners/skyblock/profiles.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cleanSkyblockProfilesResponse = exports.cleanPlayerSkyblockProfiles = void 0; +const profile_1 = require("./profile"); +function cleanPlayerSkyblockProfiles(rawProfiles) { + let profiles = []; + for (const profile of Object.values(rawProfiles)) { + profiles.push({ + uuid: profile.profile_id, + name: profile.cute_name + }); + } + console.log('cleanPlayerSkyblockProfiles', profiles); + return profiles; +} +exports.cleanPlayerSkyblockProfiles = cleanPlayerSkyblockProfiles; +/** Convert an array of raw profiles into clean profiles */ +async function cleanSkyblockProfilesResponse(data) { + const cleanedProfiles = []; + for (const profile of data) { + let cleanedProfile = await profile_1.cleanSkyblockProfileResponseLighter(profile); + cleanedProfiles.push(cleanedProfile); + } + return cleanedProfiles; +} +exports.cleanSkyblockProfilesResponse = cleanSkyblockProfilesResponse; diff --git a/build/hypixel.js b/build/hypixel.js index 0ad63f8..5dd45bb 100644 --- a/build/hypixel.js +++ b/build/hypixel.js @@ -19,12 +19,12 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.fetchMemberProfile = exports.fetchUser = exports.cleanPlayerSkyblockProfiles = exports.sendCleanApiRequest = exports.maxMinion = exports.saveInterval = void 0; -const minions_1 = require("./cleaners/skyblock/minions"); -const stats_1 = require("./cleaners/skyblock/stats"); +exports.fetchMemberProfile = exports.fetchUser = exports.sendCleanApiRequest = exports.maxMinion = exports.saveInterval = void 0; const player_1 = require("./cleaners/player"); const hypixelApi_1 = require("./hypixelApi"); const cached = __importStar(require("./hypixelCached")); +const profile_1 = require("./cleaners/skyblock/profile"); +const profiles_1 = require("./cleaners/skyblock/profiles"); // the interval at which the "last_save" parameter updates in the hypixel api, this is 3 minutes exports.saveInterval = 60 * 3 * 1000; // the highest level a minion can be @@ -52,91 +52,12 @@ async function sendCleanApiRequest({ path, args }, included, cleaned = true) { } } exports.sendCleanApiRequest = sendCleanApiRequest; -async function cleanSkyBlockProfileMemberResponse(member, included = null) { - // Cleans up a member (from skyblock/profile) - // profiles.members[] - const statsIncluded = included == null || included.includes('stats'); - return { - uuid: member.uuid, - username: await cached.usernameFromUser(member.uuid), - last_save: member.last_save, - first_join: member.first_join, - // last_death: ??? idk how this is formatted, - stats: statsIncluded ? stats_1.cleanProfileStats(member.stats) : undefined, - minions: statsIncluded ? minions_1.cleanMinions(member.crafted_generators) : undefined, - }; -} -/** 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 - const promises = []; - for (const memberUUID in data.members) { - const memberRaw = data.members[memberUUID]; - memberRaw.uuid = memberUUID; - // we pass an empty array to make it not check stats - promises.push(cleanSkyBlockProfileMemberResponse(memberRaw, [])); - } - const cleanedMembers = await Promise.all(promises); - return { - uuid: data.profile_id, - name: data.cute_name, - members: cleanedMembers, - }; -} -/** This function is very costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data */ -async function cleanSkyblockProfileResponse(data) { - const cleanedMembers = []; - for (const memberUUID in data.members) { - const memberRaw = data.members[memberUUID]; - memberRaw.uuid = memberUUID; - const member = await cleanSkyBlockProfileMemberResponse(memberRaw, ['stats']); - cleanedMembers.push(member); - } - const memberMinions = []; - for (const member of cleanedMembers) { - memberMinions.push(member.minions); - } - const minions = minions_1.combineMinionArrays(memberMinions); - // return more detailed info - return { - uuid: data.profile_id, - name: data.cute_name, - members: cleanedMembers, - bank: { - balance: data?.banking?.balance ?? 0, - // TODO: make transactions good - history: data?.banking?.transactions ?? [] - }, - minions - }; -} -function cleanPlayerSkyblockProfiles(rawProfiles) { - let profiles = []; - for (const profile of Object.values(rawProfiles)) { - profiles.push({ - uuid: profile.profile_id, - name: profile.cute_name - }); - } - console.log('cleanPlayerSkyblockProfiles', profiles); - return profiles; -} -exports.cleanPlayerSkyblockProfiles = cleanPlayerSkyblockProfiles; -/** Convert an array of raw profiles into clean profiles */ -async function cleanSkyblockProfilesResponse(data) { - const cleanedProfiles = []; - for (const profile of data) { - let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile); - cleanedProfiles.push(cleanedProfile); - } - return cleanedProfiles; -} async function cleanResponse({ path, data }, included) { // Cleans up an api response switch (path) { case 'player': return await player_1.cleanPlayerResponse(data.player); - case 'skyblock/profile': return await cleanSkyblockProfileResponse(data.profile); - case 'skyblock/profiles': return await cleanSkyblockProfilesResponse(data.profiles); + case 'skyblock/profile': return await profile_1.cleanSkyblockProfileResponse(data.profile); + case 'skyblock/profiles': return await profiles_1.cleanSkyblockProfilesResponse(data.profiles); } } /** |