aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cleaners/skyblock/member.ts10
-rw-r--r--src/cleaners/skyblock/profile.ts9
-rw-r--r--src/cleaners/skyblock/profiles.ts1
-rw-r--r--src/hypixel.ts18
-rw-r--r--src/hypixelCached.ts15
5 files changed, 34 insertions, 19 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index b90d0c4..7c3ccd6 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -2,7 +2,7 @@ import { cleanCollections, Collection } from './collections.js'
import { cleanInventories, Inventories } from './inventory.js'
import { cleanFairySouls, FairySouls } from './fairysouls.js'
import { cleanObjectives, Objective } from './objectives.js'
-import { CleanFullProfileBasicMembers } from './profile.js'
+import { CleanBasicProfile, CleanFullProfileBasicMembers } from './profile.js'
import { cleanProfileStats, StatItem } from './stats.js'
import { CleanMinion, cleanMinions } from './minions.js'
import { cleanSlayers, SlayerData } from './slayers.js'
@@ -36,6 +36,8 @@ export interface CleanMember extends CleanBasicMember {
zones: Zone[]
collections: Collection[]
slayers: SlayerData
+ /** Whether the user left the coop */
+ left: boolean
}
export async function cleanSkyBlockProfileMemberResponseBasic(member: any): Promise<CleanBasicMember | null> {
@@ -51,7 +53,7 @@ export async function cleanSkyBlockProfileMemberResponseBasic(member: any): Prom
}
/** Cleans up a member (from skyblock/profile) */
-export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] | undefined = undefined): Promise<CleanMember | null> {
+export async function cleanSkyBlockProfileMemberResponse(member, profileId?: string, included: Included[] | undefined = undefined): Promise<CleanMember | null> {
// profiles.members[]
const inventoriesIncluded = included === undefined || included.includes('inventories')
const player = await cached.fetchPlayer(member.uuid)
@@ -83,7 +85,9 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
skills: await cleanSkills(member),
zones: await cleanVisitedZones(member),
collections: cleanCollections(member),
- slayers: cleanSlayers(member)
+ slayers: cleanSlayers(member),
+
+ left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false
}
}
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index a510563..ed85861 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -52,11 +52,15 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio
// We use Promise.all so it can fetch all the users at once instead of waiting for the previous promise to complete
const promises: Promise<CleanMember | null>[] = []
if (!data) return null
+
+ const profileId: string = data.profile_id
+
for (const memberUUID in data.members) {
const memberRaw = data.members[memberUUID]
memberRaw.uuid = memberUUID
promises.push(cleanSkyBlockProfileMemberResponse(
memberRaw,
+ profileId,
[
!options?.basic ? 'stats' : undefined,
options?.mainMemberUuid === memberUUID ? 'inventories' : undefined
@@ -64,11 +68,12 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio
))
}
- const cleanedMembers: CleanMember[] = (await Promise.all(promises)).filter(m => m !== null && m !== undefined) as CleanMember[]
+
+ const cleanedMembers: CleanMember[] = (await Promise.all(promises)).filter(m => m) as CleanMember[]
if (options?.basic) {
return {
- uuid: data.profile_id,
+ uuid: profileId,
name: data.cute_name,
members: cleanedMembers,
}
diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts
index ec026de..20c2104 100644
--- a/src/cleaners/skyblock/profiles.ts
+++ b/src/cleaners/skyblock/profiles.ts
@@ -21,7 +21,6 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl
export async function cleanSkyblockProfilesResponse(data: any[]): Promise<CleanProfile[]> {
const promises: Promise<CleanProfile | CleanFullProfile | null>[] = []
for (const profile of data ?? []) {
- // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile)
promises.push(cleanSkyblockProfileResponse(profile))
}
const cleanedProfiles: CleanProfile[] = (await Promise.all(promises)).filter(p => p) as CleanProfile[]
diff --git a/src/hypixel.ts b/src/hypixel.ts
index 285ac4e..6691e97 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -87,9 +87,10 @@ export interface CleanUser {
/**
- * Higher level function that requests the api for a user, and returns the cleaned response
+ * Higher level function that requests the api for a user, and returns the
+ * cleaned response. This is used by the /player/<name> route.
* This is safe to fetch many times because the results are cached!
- * @param included lets you choose what is returned, so there's less processing required on the backend
+ * @param included lets you choose what is returned, so there's less processing required on the backend.
* used inclusions: player, profiles
*/
export async function fetchUser({ user, uuid, username }: UserAny, included: Included[]=['player'], customization?: boolean): Promise<CleanUser | null> {
@@ -98,7 +99,7 @@ export async function fetchUser({ user, uuid, username }: UserAny, included: Inc
if (!username && !user) return null
uuid = await cached.uuidFromUser((user ?? username)!)
}
- if (!uuid) {
+ if (!uuid) {
// the user doesn't exist.
if (debug) console.debug('error:', user, 'doesnt exist')
return null
@@ -117,6 +118,7 @@ export async function fetchUser({ user, uuid, username }: UserAny, included: Inc
// if not including profiles, include lightweight profiles just in case
if (!includeProfiles)
basicProfilesData = playerData?.profiles
+ // we don't want the `profiles` field in `player`
if (playerData)
delete playerData.profiles
}
@@ -255,11 +257,11 @@ export async function fetchMemberProfile(user: string, profile: string, customiz
export async function fetchMemberProfilesUncached(playerUuid: string): Promise<CleanFullProfile[]> {
- const profiles: CleanFullProfile[] = await sendCleanApiRequest({
- path: 'skyblock/profiles',
- args: {
- uuid: playerUuid
- }},
+ const profiles: CleanFullProfile[] = await sendCleanApiRequest(
+ {
+ path: 'skyblock/profiles',
+ args: { uuid: playerUuid }
+ },
undefined,
{
// only the inventories for the main player are generated, this is for optimization purposes
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index 1cfc639..f9bd53e 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -182,12 +182,16 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer | null> {
if (!cleanPlayer) return null
- // clone in case it gets modified somehow later
playerCache.set(playerUuid, cleanPlayer)
usernameCache.set(playerUuid, cleanPlayer.username)
-
+
+ // clone in case it gets modified somehow later
const cleanBasicPlayer = Object.assign({}, cleanPlayer)
- delete cleanBasicPlayer.profiles
+ if (cleanBasicPlayer.profiles) {
+ // remove the names from the profiles so we only keep uuids
+ // this helps save a bit of memory since we don't care about the names
+ cleanBasicPlayer.profiles = cleanBasicPlayer.profiles.map(p => ({ uuid: p.uuid }))
+ }
basicPlayerCache.set(playerUuid, cleanBasicPlayer)
return cleanPlayer
@@ -220,7 +224,7 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanPr
if (debug) console.debug('Cache miss: fetchSkyblockProfiles', playerUuid)
- const profiles: CleanProfile[] = await hypixel.fetchMemberProfilesUncached(playerUuid)
+ const profiles: CleanFullProfile[] = await hypixel.fetchMemberProfilesUncached(playerUuid)
const basicProfiles: CleanProfile[] = []
@@ -235,7 +239,8 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanPr
username: m.username,
firstJoin: m.firstJoin,
lastSave: m.lastSave,
- rank: m.rank
+ rank: m.rank,
+ left: m.left
}
})
}