aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-03-20 22:35:49 -0500
committermat <github@matdoes.dev>2022-03-20 22:35:49 -0500
commit68a0b0778dda3d8bd8bc1763c2370273d456326c (patch)
tree25fdbc058f76ad6daaa55c7b466d45d625804465 /src/cleaners
parentc467866d8eb9634f2cc7c441ee3735c49e6970d2 (diff)
downloadskyblock-api-68a0b0778dda3d8bd8bc1763c2370273d456326c.tar.gz
skyblock-api-68a0b0778dda3d8bd8bc1763c2370273d456326c.tar.bz2
skyblock-api-68a0b0778dda3d8bd8bc1763c2370273d456326c.zip
Add the "left" field for members who left
Diffstat (limited to 'src/cleaners')
-rw-r--r--src/cleaners/skyblock/member.ts10
-rw-r--r--src/cleaners/skyblock/profile.ts9
-rw-r--r--src/cleaners/skyblock/profiles.ts1
3 files changed, 14 insertions, 6 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[]