aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cleaners/player.ts1
-rw-r--r--src/cleaners/rank.ts1
-rw-r--r--src/cleaners/skyblock/inventory.ts1
-rw-r--r--src/cleaners/skyblock/member.ts3
-rw-r--r--src/cleaners/skyblock/profile.ts16
-rw-r--r--src/hypixel.ts26
-rw-r--r--src/hypixelCached.ts7
7 files changed, 31 insertions, 24 deletions
diff --git a/src/cleaners/player.ts b/src/cleaners/player.ts
index 02eed90..f49d72c 100644
--- a/src/cleaners/player.ts
+++ b/src/cleaners/player.ts
@@ -18,7 +18,6 @@ export interface CleanPlayer extends CleanBasicPlayer {
export async function cleanPlayerResponse(data: HypixelPlayer): Promise<CleanPlayer> {
// Cleans up a 'player' api response
- console.log('cleanPlayerResponse', data.stats.SkyBlock.profiles)
return {
uuid: undashUuid(data.uuid),
username: data.displayname,
diff --git a/src/cleaners/rank.ts b/src/cleaners/rank.ts
index 928373a..49520a9 100644
--- a/src/cleaners/rank.ts
+++ b/src/cleaners/rank.ts
@@ -52,7 +52,6 @@ export function parseRank({
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/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts
index ac36d88..ea115e5 100644
--- a/src/cleaners/skyblock/inventory.ts
+++ b/src/cleaners/skyblock/inventory.ts
@@ -28,6 +28,7 @@ export const INVENTORIES = {
}
export async function cleanInventories(data: any): Promise<typeof INVENTORIES> {
+ console.log('cleanInventories', data.uuid)
const cleanInventories: any = {}
for (const cleanInventoryName in INVENTORIES) {
const hypixelInventoryName = INVENTORIES[cleanInventoryName]
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index febb9c2..d7d0cd1 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -28,6 +28,7 @@ export interface CleanMember extends CleanBasicMember {
export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> {
// 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),
@@ -37,7 +38,7 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
stats: statsIncluded ? cleanProfileStats(member?.stats) : undefined,
minions: statsIncluded ? cleanMinions(member) : undefined,
fairy_souls: statsIncluded ? cleanFairySouls(member) : undefined,
- inventories: statsIncluded ? await cleanInventories(member) : undefined,
+ inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
}
}
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index 742c9ed..b4a8574 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -1,8 +1,7 @@
-import { CleanBasicMember, CleanMember, CleanMemberProfile, cleanSkyBlockProfileMemberResponse } from './member'
+import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse } from './member'
import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions'
-import * as cached from '../../hypixelCached'
import { Bank, cleanBank } from './bank'
-import { cleanFairySouls, FairySouls } from './fairysouls'
+import { ApiOptions } from '../../hypixel'
export interface CleanProfile extends CleanBasicProfile {
members?: CleanBasicMember[]
@@ -36,14 +35,19 @@ export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanPr
}
}
-/** 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> {
+/**
+ * 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, { mainMemberUuid }: ApiOptions): 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'])
+ const member: CleanMember = await cleanSkyBlockProfileMemberResponse(
+ memberRaw,
+ ['stats', mainMemberUuid === memberUUID ? 'inventories' : undefined]
+ )
cleanedMembers.push(member)
}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index bbfc7d2..cc01478 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -9,7 +9,7 @@ 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'
+export type Included = 'profiles' | 'player' | 'stats' | 'inventories'
// the interval at which the "last_save" parameter updates in the hypixel api, this is 3 minutes
export const saveInterval = 60 * 3 * 1000
@@ -20,32 +20,32 @@ export const maxMinion = 11
/**
* Send a request to api.hypixel.net using a random key, clean it up to be more useable, and return it
*/
-export async function sendCleanApiRequest({ path, args }, included?: Included[], cleaned=true) {
+
+export interface ApiOptions {
+ mainMemberUuid?: string
+}
+
+export async function sendCleanApiRequest({ path, args }, included?: Included[], options?: ApiOptions) {
const key = await chooseApiKey()
const rawResponse = await 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 ?? {})
}
-async function cleanResponse({ path, data }: { path: string, data: HypixelResponse }, included?: Included[]) {
+async function cleanResponse({ path, data }: { path: string, data: HypixelResponse }, options: ApiOptions) {
// Cleans up an api response
switch (path) {
case 'player': return await cleanPlayerResponse(data.player)
- case 'skyblock/profile': return await cleanSkyblockProfileResponse(data.profile)
+ case 'skyblock/profile': return await cleanSkyblockProfileResponse(data.profile, options)
case 'skyblock/profiles': return await cleanSkyblockProfilesResponse(data.profiles)
}
}
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index 74b1366..33d33eb 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -116,6 +116,11 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanPr
args: {
uuid: playerUuid
}},
+ null,
+ {
+ // only the inventories for the main player are generated, this is for optimization purposes
+ mainMemberUuid: playerUuid
+ }
)
const basicProfiles: CleanProfile[] = []
@@ -154,8 +159,6 @@ async function fetchBasicProfiles(user: string): Promise<CleanBasicProfile[]> {
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)