From 68a0b0778dda3d8bd8bc1763c2370273d456326c Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 20 Mar 2022 22:35:49 -0500 Subject: Add the "left" field for members who left --- src/cleaners/skyblock/member.ts | 10 +++++++--- src/cleaners/skyblock/profile.ts | 9 +++++++-- src/cleaners/skyblock/profiles.ts | 1 - 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/cleaners') 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 { @@ -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 { +export async function cleanSkyBlockProfileMemberResponse(member, profileId?: string, included: Included[] | undefined = undefined): Promise { // 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[] = [] 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 { const promises: Promise[] = [] 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[] -- cgit