aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cleaners/skyblock/coopInvitation.ts9
-rw-r--r--src/cleaners/skyblock/member.ts22
-rw-r--r--src/database.ts7
-rw-r--r--src/hypixelCached.ts12
4 files changed, 31 insertions, 19 deletions
diff --git a/src/cleaners/skyblock/coopInvitation.ts b/src/cleaners/skyblock/coopInvitation.ts
index 80c92bb..6aa8803 100644
--- a/src/cleaners/skyblock/coopInvitation.ts
+++ b/src/cleaners/skyblock/coopInvitation.ts
@@ -1,18 +1,21 @@
import typedHypixelApi from 'typed-hypixel-api'
+import { CleanPlayer } from '../player'
+import * as cached from '../../hypixelCached.js'
+
export interface CoopInvitation {
invitedTimestamp: number
- invitedByUuid: string
+ invitedBy: CleanPlayer | null
accepted: boolean
acceptedTimestamp: number | null
}
-export function cleanCoopInvitation(data: typedHypixelApi.SkyBlockProfileMember): null | CoopInvitation {
+export async function cleanCoopInvitation(data: typedHypixelApi.SkyBlockProfileMember): Promise<CoopInvitation | null> {
if (!data.coop_invitation)
return null
return {
invitedTimestamp: data.coop_invitation.timestamp,
- invitedByUuid: data.coop_invitation.invited_by,
+ invitedBy: await cached.fetchBasicPlayer(data.coop_invitation.invited_by, false),
accepted: data.coop_invitation.confirmed,
acceptedTimestamp: data.coop_invitation.confirmed_timestamp ?? null
}
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index 9306c59..9231456 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -72,6 +72,14 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi
if (fairySouls.total > (maxFairySouls ?? 0))
await constants.setConstantValues({ max_fairy_souls: fairySouls.total })
+ const coopInvitationPromise = cleanCoopInvitation(member)
+ const minionsPromise = cleanMinions(member)
+ const skillsPromise = cleanSkills(member)
+ const zonesPromise = cleanVisitedZones(member)
+ const petsPromise = cleanPets(member)
+ const harpPromise = cleanHarp(member)
+ const inventoriesPromise = inventoriesIncluded ? cleanInventories(member) : Promise.resolve(undefined)
+
return {
uuid: member.uuid,
username: player.username,
@@ -87,17 +95,17 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi
// this is used for leaderboards
rawHypixelStats: member.stats ?? {},
- minions: await cleanMinions(member),
+ minions: await minionsPromise,
fairySouls: fairySouls,
- inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
+ inventories: inventoriesPromise ? await inventoriesPromise : undefined,
objectives: cleanObjectives(member),
- skills: await cleanSkills(member),
- zones: await cleanVisitedZones(member),
+ skills: await skillsPromise,
+ zones: await zonesPromise,
collections: cleanCollections(member),
slayers: cleanSlayers(member),
- pets: await cleanPets(member),
- harp: await cleanHarp(member),
- coopInvitation: cleanCoopInvitation(member),
+ pets: await petsPromise,
+ harp: await harpPromise,
+ coopInvitation: await coopInvitationPromise,
farmingContests: cleanFarmingContests(member),
left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false
diff --git a/src/database.ts b/src/database.ts
index f6de171..08413af 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -440,12 +440,7 @@ export async function fetchMemberLeaderboard(name: string): Promise<MemberLeader
const leaderboardRaw = await fetchMemberLeaderboardRaw(name)
const fetchLeaderboardPlayer = async (i: memberRawLeaderboardItem): Promise<MemberLeaderboardItem> => {
- const player = await cached.fetchBasicPlayer(i.uuid)
-
- if (player) {
- // we don't need this in leaderboards
- delete player.claimed
- }
+ const player = await cached.fetchBasicPlayer(i.uuid, false)
return {
player,
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index 6e634ef..3c703f6 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -198,13 +198,17 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer | null> {
}
/** Fetch a player without their profiles. This is heavily cached. */
-export async function fetchBasicPlayer(user: string): Promise<CleanPlayer | null> {
+export async function fetchBasicPlayer(user: string, includeClaimed: boolean = true): Promise<CleanPlayer | null> {
const playerUuid = await uuidFromUser(user)
if (!playerUuid) return null
- if (basicPlayerCache.has(playerUuid))
- return basicPlayerCache.get(playerUuid)!
+ if (basicPlayerCache.has(playerUuid)) {
+ const player = basicPlayerCache.get(playerUuid)!
+ if (!includeClaimed)
+ delete player.claimed
+ return player
+ }
const player = await fetchPlayer(playerUuid)
if (!player) {
@@ -213,6 +217,8 @@ export async function fetchBasicPlayer(user: string): Promise<CleanPlayer | null
}
delete player.profiles
+ if (!includeClaimed)
+ delete player.claimed
return player
}