aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-28 01:23:18 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-28 01:23:18 -0600
commit6dadf95683a8b8574976c9d024b0b148521012f7 (patch)
treeedd88502959e8b74c76d47a82a5b98a646b26eb4 /src/cleaners/skyblock
parent78198ac4812f6f33f412bdc62216567aa08d8199 (diff)
downloadskyblock-api-6dadf95683a8b8574976c9d024b0b148521012f7.tar.gz
skyblock-api-6dadf95683a8b8574976c9d024b0b148521012f7.tar.bz2
skyblock-api-6dadf95683a8b8574976c9d024b0b148521012f7.zip
Add leaderboards
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r--src/cleaners/skyblock/member.ts9
-rw-r--r--src/cleaners/skyblock/profile.ts25
-rw-r--r--src/cleaners/skyblock/profiles.ts5
3 files changed, 27 insertions, 12 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index 154ff22..a4ca053 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -5,7 +5,7 @@ import { cleanObjectives, Objective } from './objectives'
import { CleanMinion, cleanMinions } from './minions'
import { cleanSkills, Skill } from './skills'
import * as cached from '../../hypixelCached'
-import { CleanFullProfile } from './profile'
+import { CleanFullProfile, CleanFullProfileBasicMembers } from './profile'
import { Included } from '../../hypixel'
import { CleanPlayer } from '../player'
import { Bank } from './bank'
@@ -25,6 +25,7 @@ export interface CleanBasicMember {
export interface CleanMember extends CleanBasicMember {
purse: number
stats: CleanProfileStats
+ rawHypixelStats?: { [ key: string ]: number }
minions: CleanMinion[]
fairy_souls: FairySouls
inventories: Inventories
@@ -61,6 +62,10 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
purse: member.coin_purse,
stats: cleanProfileStats(member),
+
+ // this is used for leaderboards
+ rawHypixelStats: member.stats ?? {},
+
minions: cleanMinions(member),
fairy_souls: cleanFairySouls(member),
inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
@@ -83,5 +88,5 @@ export interface CleanMemberProfilePlayer extends CleanPlayer {
export interface CleanMemberProfile {
member: CleanMemberProfilePlayer
- profile: CleanFullProfile
+ profile: CleanFullProfileBasicMembers
}
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index 2b092a1..6e98f8f 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -8,7 +8,14 @@ export interface CleanProfile extends CleanBasicProfile {
}
export interface CleanFullProfile extends CleanProfile {
- members: (CleanMember|CleanBasicMember)[]
+ members: CleanMember[]
+ bank: Bank
+ minions: CleanMinion[]
+ minion_count: number
+}
+
+export interface CleanFullProfileBasicMembers extends CleanProfile {
+ members: CleanBasicMember[]
bank: Bank
minions: CleanMinion[]
minion_count: number
@@ -38,19 +45,21 @@ 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, { mainMemberUuid }: ApiOptions): Promise<CleanFullProfile> {
- const cleanedMembers: CleanMember[] = []
-
+export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptions): Promise<CleanFullProfile> {
+ // 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>[] = []
+
for (const memberUUID in data.members) {
const memberRaw = data.members[memberUUID]
memberRaw.uuid = memberUUID
- const member: CleanMember = await cleanSkyBlockProfileMemberResponse(
+ promises.push(cleanSkyBlockProfileMemberResponse(
memberRaw,
- ['stats', mainMemberUuid === memberUUID ? 'inventories' : undefined]
- )
- cleanedMembers.push(member)
+ ['stats', options?.mainMemberUuid === memberUUID ? 'inventories' : undefined]
+ ))
}
+ const cleanedMembers: CleanMember[] = await Promise.all(promises)
+
const memberMinions: CleanMinion[][] = []
for (const member of cleanedMembers) {
diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts
index ea290f6..c9f5628 100644
--- a/src/cleaners/skyblock/profiles.ts
+++ b/src/cleaners/skyblock/profiles.ts
@@ -1,5 +1,5 @@
import { HypixelPlayerStatsSkyBlockProfiles } from "../../hypixelApi"
-import { CleanBasicProfile, CleanProfile, cleanSkyblockProfileResponseLighter } from "./profile"
+import { CleanBasicProfile, CleanProfile, cleanSkyblockProfileResponse, cleanSkyblockProfileResponseLighter } from "./profile"
export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles): CleanBasicProfile[] {
let profiles: CleanBasicProfile[] = []
@@ -16,7 +16,8 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl
export async function cleanSkyblockProfilesResponse(data: any[]): Promise<CleanProfile[]> {
const cleanedProfiles: CleanProfile[] = []
for (const profile of data ?? []) {
- let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile)
+ // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile)
+ let cleanedProfile = await cleanSkyblockProfileResponse(profile)
cleanedProfiles.push(cleanedProfile)
}
return cleanedProfiles