From 8582958e7f3764e47a49667c57805400643b005c Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 21 May 2022 16:20:17 -0500 Subject: add essence --- src/cleaners/skyblock/essence.ts | 28 ++++++++++++++++++++++++++++ src/cleaners/skyblock/member.ts | 31 ++++++++++--------------------- 2 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 src/cleaners/skyblock/essence.ts (limited to 'src/cleaners/skyblock') diff --git a/src/cleaners/skyblock/essence.ts b/src/cleaners/skyblock/essence.ts new file mode 100644 index 0000000..4af94fb --- /dev/null +++ b/src/cleaners/skyblock/essence.ts @@ -0,0 +1,28 @@ +import typedHypixelApi from 'typed-hypixel-api' +import * as constants from '../../constants.js' + +interface EssenceType { + id: string + value: number +} + +export interface Essence { + types: EssenceType[] +} + +export function cleanEssence(data: typedHypixelApi.SkyBlockProfileMember): Essence { + const essences: EssenceType[] = [] + + for (const [id, value] of Object.entries(data ?? {})) { + if (id.startsWith('essence_')) { + essences.push({ + id: id.replace(/^essence_/, ''), + value: value ?? 0, + }) + } + } + + return { + types: essences, + } +} \ No newline at end of file diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index f2526d2..d69295e 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -20,6 +20,7 @@ import { Included } from '../../hypixel.js' import { CleanPlayer } from '../player.js' import { CleanRank } from '../rank.js' import { AccessoryBagUpgrades, cleanAccessoryBagUpgrades } from './accessoryBagUpgrades.js' +import { cleanEssence, Essence } from './essence.js' export interface CleanBasicMember { uuid: string @@ -30,7 +31,7 @@ export interface CleanBasicMember { left?: boolean } -export interface CleanMember extends CleanBasicMember { +interface ExtraCleanMemberFields { purse: number stats: StatItem[] rawHypixelStats: { [key: string]: number } @@ -47,10 +48,13 @@ export interface CleanMember extends CleanBasicMember { coopInvitation: CoopInvitation | null farmingContests: FarmingContests accessoryBagUpgrades: AccessoryBagUpgrades - /** Whether the user left the coop */ + essence: Essence + /** Whether the member left the coop. */ left: boolean } +export type CleanMember = CleanBasicMember & ExtraCleanMemberFields + export async function cleanSkyBlockProfileMemberResponseBasic(member: typedHypixelApi.SkyBlockProfileMember & { uuid: string }): Promise { const player = await cached.fetchPlayer(member.uuid, false) if (!player) return null @@ -70,6 +74,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi if (!player) return null const fairySouls = await cleanFairySouls(member) + const { max_fairy_souls: maxFairySouls } = await constants.fetchConstantValues() if (fairySouls.total > (maxFairySouls ?? 0)) await constants.setConstantValues({ max_fairy_souls: fairySouls.total }) @@ -113,35 +118,19 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi coopInvitation: await coopInvitationPromise, farmingContests: await farmingContestsPromise, accessoryBagUpgrades: cleanAccessoryBagUpgrades(member), + essence: cleanEssence(member), left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false } } -export interface CleanMemberProfilePlayer extends CleanPlayer { +export type CleanMemberProfilePlayer = CleanPlayer & { // The profile name may be different for each player, so we put it here profileName: string firstJoin: number | null lastSave: number | null - purse: number - stats: StatItem[] - rawHypixelStats: { [key: string]: number } - minions: CleanMinion[] - fairySouls: FairySouls - inventories?: Inventories - objectives: Objective[] - skills: Skills - zones: Zone[] - collections: Collection[] - slayers: SlayerData - pets: PetsData - harp: HarpData - coopInvitation: CoopInvitation | null - farmingContests: FarmingContests - accessoryBagUpgrades: AccessoryBagUpgrades - left: boolean -} +} & ExtraCleanMemberFields export interface CleanMemberProfile { member: CleanMemberProfilePlayer -- cgit