diff options
-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 | ||||
-rw-r--r-- | src/cleaners/player.ts | 3 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 52 | ||||
-rw-r--r-- | src/cleaners/skyblock/profile.ts | 79 | ||||
-rw-r--r-- | src/cleaners/skyblock/profiles.ts | 24 | ||||
-rw-r--r-- | src/hypixel.ts | 144 | ||||
-rw-r--r-- | src/hypixelCached.ts | 2 |
11 files changed, 285 insertions, 229 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); } } /** diff --git a/src/cleaners/player.ts b/src/cleaners/player.ts index c3afd6f..02eed90 100644 --- a/src/cleaners/player.ts +++ b/src/cleaners/player.ts @@ -1,8 +1,9 @@ -import { CleanBasicProfile, cleanPlayerSkyblockProfiles, Included } from '../hypixel' import { CleanSocialMedia, parseSocialMedia } from './socialmedia' import { CleanRank, parseRank } from './rank' import { HypixelPlayer } from '../hypixelApi' import { undashUuid } from '../util' +import { CleanBasicProfile } from './skyblock/profile' +import { cleanPlayerSkyblockProfiles } from './skyblock/profiles' export interface CleanBasicPlayer { uuid: string diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts new file mode 100644 index 0000000..774dace --- /dev/null +++ b/src/cleaners/skyblock/member.ts @@ -0,0 +1,52 @@ +import { Included } from '../../hypixel' +import * as cached from '../../hypixelCached' +import { CleanPlayer } from '../player' +import { CleanMinion, cleanMinions } from './minions' +import { CleanProfileStats, cleanProfileStats } from './stats' + +export interface CleanBasicMember { + uuid: string + username: string + last_save: number + first_join: number +} + +export interface CleanMember extends CleanBasicMember { + stats?: CleanProfileStats + minions?: CleanMinion[] +} + + +/** Cleans up a member (from skyblock/profile) */ +export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> { + // 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 ? cleanProfileStats(member.stats) : undefined, + minions: statsIncluded ? cleanMinions(member.crafted_generators) : undefined, + } +} + + +export interface CleanMemberProfilePlayer extends CleanPlayer { + // The profile name may be different for each player, so we put it here + profileName: string + first_join: number + last_save: number + bank?: { + balance: number + history: any[] + } +} + +export interface CleanMemberProfile { + member: CleanMemberProfilePlayer + profile: { + + } +} diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts new file mode 100644 index 0000000..8b59a9d --- /dev/null +++ b/src/cleaners/skyblock/profile.ts @@ -0,0 +1,79 @@ +import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse } from './member' +import { CleanMinion, combineMinionArrays } from './minions' + + +export interface CleanProfile extends CleanBasicProfile { + members?: CleanBasicMember[] +} + +export interface CleanFullProfile extends CleanProfile { + members: CleanMember[] + bank?: { + balance: number + history: any[] + } + minions: CleanMinion[] +} + +/** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */ +export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanProfile> { + // We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete + const promises: Promise<CleanMember>[] = [] + + 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: CleanMember[] = await Promise.all(promises) + + return { + uuid: data.profile_id, + name: data.cute_name, + members: cleanedMembers, + } +} + +/** This function is somewhat costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data */ +export async function cleanSkyblockProfileResponse(data: any): Promise<CleanFullProfile> { + const cleanedMembers: CleanMember[] = [] + + for (const memberUUID in data.members) { + const memberRaw = data.members[memberUUID] + memberRaw.uuid = memberUUID + const member: CleanMember = await cleanSkyBlockProfileMemberResponse(memberRaw, ['stats']) + cleanedMembers.push(member) + } + + const memberMinions: CleanMinion[][] = [] + + for (const member of cleanedMembers) { + memberMinions.push(member.minions) + } + const minions: CleanMinion[] = 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 + } +} + +/** A basic profile that only includes the profile uuid and name */ +export interface CleanBasicProfile { + uuid: string + + // the name depends on the user, so its sometimes not included + name?: string +} + diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts new file mode 100644 index 0000000..c942a14 --- /dev/null +++ b/src/cleaners/skyblock/profiles.ts @@ -0,0 +1,24 @@ +import { HypixelPlayerStatsSkyBlockProfiles } from "../../hypixelApi" +import { CleanBasicProfile, CleanProfile, cleanSkyblockProfileResponseLighter } from "./profile" + +export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles): CleanBasicProfile[] { + let profiles: CleanBasicProfile[] = [] + for (const profile of Object.values(rawProfiles)) { + profiles.push({ + uuid: profile.profile_id, + name: profile.cute_name + }) + } + console.log('cleanPlayerSkyblockProfiles', profiles) + return profiles +} + +/** Convert an array of raw profiles into clean profiles */ +export async function cleanSkyblockProfilesResponse(data: any[]): Promise<CleanProfile[]> { + const cleanedProfiles: CleanProfile[] = [] + for (const profile of data) { + let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) + cleanedProfiles.push(cleanedProfile) + } + return cleanedProfiles +} diff --git a/src/hypixel.ts b/src/hypixel.ts index f17dc9e..105e627 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -3,6 +3,9 @@ import { CleanProfileStats, cleanProfileStats } from './cleaners/skyblock/stats' import { CleanPlayer, cleanPlayerResponse } from './cleaners/player' import { chooseApiKey, HypixelPlayerStatsSkyBlockProfiles, HypixelResponse, sendApiRequest } from './hypixelApi' import * as cached from './hypixelCached' +import { CleanMemberProfile } from './cleaners/skyblock/member' +import { cleanSkyblockProfileResponse, CleanProfile, CleanBasicProfile } from './cleaners/skyblock/profile' +import { cleanSkyblockProfilesResponse } from './cleaners/skyblock/profiles' export type Included = 'profiles' | 'player' | 'stats' @@ -34,148 +37,7 @@ export async function sendCleanApiRequest({ path, args }, included?: Included[], } } -export interface CleanBasicMember { - uuid: string - username: string - last_save: number - first_join: number -} - -interface CleanMember extends CleanBasicMember { - stats?: CleanProfileStats - minions?: CleanMinion[] -} - -async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> { - // 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 ? cleanProfileStats(member.stats) : undefined, - minions: statsIncluded ? cleanMinions(member.crafted_generators) : undefined, - } -} - - -export interface CleanMemberProfilePlayer extends CleanPlayer { - // The profile name may be different for each player, so we put it here - profileName: string - first_join: number - last_save: number - bank?: { - balance: number - history: any[] - } -} - -export interface CleanMemberProfile { - member: CleanMemberProfilePlayer - profile: { - - } -} - -export interface CleanProfile extends CleanBasicProfile { - members?: CleanBasicMember[] -} - -export interface CleanFullProfile extends CleanProfile { - members: CleanMember[] - bank?: { - balance: number - history: any[] - } - minions: CleanMinion[] -} - -/** 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): Promise<CleanProfile> { - // We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete - const promises: Promise<CleanMember>[] = [] - - 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: CleanMember[] = 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: any): Promise<CleanFullProfile> { - const cleanedMembers: CleanMember[] = [] - - for (const memberUUID in data.members) { - const memberRaw = data.members[memberUUID] - memberRaw.uuid = memberUUID - const member: CleanMember = await cleanSkyBlockProfileMemberResponse(memberRaw, ['stats']) - cleanedMembers.push(member) - } - - const memberMinions: CleanMinion[][] = [] - - for (const member of cleanedMembers) { - memberMinions.push(member.minions) - } - const minions: CleanMinion[] = 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 - } -} - -/** A basic profile that only includes the profile uuid and name */ -export interface CleanBasicProfile { - uuid: string - - // the name depends on the user, so its sometimes not included - name?: string -} - -export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles): CleanBasicProfile[] { - let profiles: CleanBasicProfile[] = [] - for (const profile of Object.values(rawProfiles)) { - profiles.push({ - uuid: profile.profile_id, - name: profile.cute_name - }) - } - console.log('cleanPlayerSkyblockProfiles', profiles) - return profiles -} - -/** Convert an array of raw profiles into clean profiles */ -async function cleanSkyblockProfilesResponse(data: any[]): Promise<CleanProfile[]> { - const cleanedProfiles: CleanProfile[] = [] - for (const profile of data) { - let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) - cleanedProfiles.push(cleanedProfile) - } - return cleanedProfiles -} async function cleanResponse({ path, data }: { path: string, data: HypixelResponse }, included?: Included[]) { // Cleans up an api response diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index 5fe65a3..7f0305e 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -2,8 +2,8 @@ import NodeCache from 'node-cache' import * as mojang from './mojang' import * as hypixel from './hypixel' import { CleanPlayer } from './cleaners/player' -import { CleanBasicProfile, CleanFullProfile, CleanProfile } from './hypixel' import { undashUuid } from './util' +import { CleanProfile, CleanFullProfile, CleanBasicProfile } from './cleaners/skyblock/profile' /** Hypixel... but with caching |