aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r--src/cleaners/skyblock/election.ts2
-rw-r--r--src/cleaners/skyblock/member.ts5
-rw-r--r--src/cleaners/skyblock/profile.ts15
-rw-r--r--src/cleaners/skyblock/profiles.ts13
4 files changed, 22 insertions, 13 deletions
diff --git a/src/cleaners/skyblock/election.ts b/src/cleaners/skyblock/election.ts
index a773f4a..9094e2d 100644
--- a/src/cleaners/skyblock/election.ts
+++ b/src/cleaners/skyblock/election.ts
@@ -39,7 +39,7 @@ function cleanCandidate(data: any, index: number): Candidate {
}
}
-export function cleanElectionResponse(data: any): ElectionData {
+export async function cleanElectionResponse(data: any): Promise<ElectionData> {
const previousCandidates = data.mayor.election.candidates.map(cleanCandidate)
return {
lastUpdated: data.lastUpdated,
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index 3430eac..e187beb 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -1,8 +1,9 @@
+import { ProfileMember as HypixelApiProfileMember } from 'typed-hypixel-api/build/responses/skyblock/_profile_member'
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 { CleanBasicProfile, CleanFullProfileBasicMembers } from './profile.js'
+import { CleanFullProfileBasicMembers } from './profile.js'
import { cleanProfileStats, StatItem } from './stats.js'
import { CleanMinion, cleanMinions } from './minions.js'
import { cleanSlayers, SlayerData } from './slayers.js'
@@ -53,7 +54,7 @@ export async function cleanSkyBlockProfileMemberResponseBasic(member: any): Prom
}
/** Cleans up a member (from skyblock/profile) */
-export async function cleanSkyBlockProfileMemberResponse(member, profileId?: string, included: Included[] | undefined = undefined): Promise<CleanMember | null> {
+export async function cleanSkyBlockProfileMemberResponse(member: HypixelApiProfileMember & { uuid: string }, 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)
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index ed85861..03ff2eb 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -1,4 +1,5 @@
import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse, cleanSkyBlockProfileMemberResponseBasic } from './member.js'
+import { SkyBlockProfilesResponse as HypixelApiSkyBlockProfilesResponse } from 'typed-hypixel-api/build/responses/skyblock/profiles'
import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions.js'
import * as constants from '../../constants.js'
import { ApiOptions } from '../../hypixel.js'
@@ -48,7 +49,7 @@ 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, options?: ApiOptions): Promise<CleanFullProfile | CleanProfile | null> {
+export async function cleanSkyblockProfileResponse<O extends ApiOptions>(data: HypixelApiSkyBlockProfilesResponse['profiles'][number], options?: O): Promise<(O['basic'] extends true ? CleanProfile : CleanFullProfile) | null> {
// 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
@@ -57,9 +58,9 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio
for (const memberUUID in data.members) {
const memberRaw = data.members[memberUUID]
- memberRaw.uuid = memberUUID
+ const memberRawWithUuid = { ...memberRaw, uuid: memberUUID }
promises.push(cleanSkyBlockProfileMemberResponse(
- memberRaw,
+ memberRawWithUuid,
profileId,
[
!options?.basic ? 'stats' : undefined,
@@ -72,11 +73,13 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio
const cleanedMembers: CleanMember[] = (await Promise.all(promises)).filter(m => m) as CleanMember[]
if (options?.basic) {
- return {
+ const cleanProfile: CleanProfile = {
uuid: profileId,
name: data.cute_name,
members: cleanedMembers,
}
+ // we have to do this because of the basic checking typing
+ return cleanProfile as any
}
const memberMinions: CleanMinion[][] = []
@@ -93,7 +96,7 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio
await constants.setConstantValues({ max_minions: uniqueMinions })
// return more detailed info
- return {
+ const cleanFullProfile: CleanFullProfile = {
uuid: data.profile_id,
name: data.cute_name,
members: cleanedMembers,
@@ -102,6 +105,8 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio
minionCount: uniqueMinions,
maxUniqueMinions: maxUniqueMinions ?? 0,
}
+ // we have to do this because of the basic checking typing
+ return cleanFullProfile as any
}
/** A basic profile that only includes the profile uuid and name */
diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts
index 20c2104..ddab078 100644
--- a/src/cleaners/skyblock/profiles.ts
+++ b/src/cleaners/skyblock/profiles.ts
@@ -5,8 +5,11 @@ import {
CleanProfile,
cleanSkyblockProfileResponse
} from './profile.js'
+import { SkyBlockProfilesResponse } from 'typed-hypixel-api/build/responses/skyblock/profiles'
+
+export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles | undefined): CleanBasicProfile[] {
+ if (!rawProfiles) return []
-export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles): CleanBasicProfile[] {
let profiles: CleanBasicProfile[] = []
for (const profile of Object.values(rawProfiles ?? {})) {
profiles.push({
@@ -18,11 +21,11 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl
}
/** Convert an array of raw profiles into clean profiles */
-export async function cleanSkyblockProfilesResponse(data: any[]): Promise<CleanProfile[]> {
- const promises: Promise<CleanProfile | CleanFullProfile | null>[] = []
- for (const profile of data ?? []) {
+export async function cleanSkyblockProfilesResponse(data: SkyBlockProfilesResponse['profiles']): Promise<CleanFullProfile[]> {
+ const promises: Promise<CleanFullProfile | null>[] = []
+ for (const profile of data) {
promises.push(cleanSkyblockProfileResponse(profile))
}
- const cleanedProfiles: CleanProfile[] = (await Promise.all(promises)).filter(p => p) as CleanProfile[]
+ const cleanedProfiles: CleanFullProfile[] = (await Promise.all(promises)).filter((p): p is CleanFullProfile => p !== null)
return cleanedProfiles
}