diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/profile.ts | 18 | ||||
-rw-r--r-- | src/cleaners/skyblock/profiles.ts | 8 | ||||
-rw-r--r-- | src/hypixel.ts | 2 |
3 files changed, 23 insertions, 5 deletions
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts index ebe5c47..725b8b9 100644 --- a/src/cleaners/skyblock/profile.ts +++ b/src/cleaners/skyblock/profile.ts @@ -78,12 +78,22 @@ export async function cleanSkyblockProfileResponse<O extends ApiOptions>( const cleanedMembers: CleanMember[] = (await Promise.all(promises)).filter(m => m) as CleanMember[] + // sometimes it's ms since epoch and sometimes it's a string, so we + // just throw it into new Date() and js will figure it out for us + const lastSave = data.last_save ? (new Date(data.last_save).getTime()) : undefined + // also set the lastSave in the member if options.mainMemberUuid matches + if (options?.mainMemberUuid) { + const mainMember = cleanedMembers.find(m => m.uuid === options.mainMemberUuid) + if (mainMember) mainMember.lastSave = lastSave ?? null + } + if (options?.basic) { const cleanProfile: CleanProfile = { uuid: profileId, name: 'cute_name' in data ? data.cute_name : undefined, members: cleanedMembers, - mode: cleanGameMode(data) + mode: cleanGameMode(data), + lastSave } // we have to do this because of the basic checking typing return cleanProfile as any @@ -111,7 +121,8 @@ export async function cleanSkyblockProfileResponse<O extends ApiOptions>( minions: minions, minionCount: uniqueMinions, maxUniqueMinions: maxUniqueMinions ?? 0, - mode: cleanGameMode(data) + mode: cleanGameMode(data), + lastSave } return cleanFullProfile } @@ -122,5 +133,8 @@ export interface CleanBasicProfile { // the name depends on the user, so its sometimes not included name?: string + + /** Timestamp for when the profile was last saved for the user. */ + lastSave?: number } diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts index 4e9400b..da40ee3 100644 --- a/src/cleaners/skyblock/profiles.ts +++ b/src/cleaners/skyblock/profiles.ts @@ -5,6 +5,7 @@ import { cleanSkyblockProfileResponse } from './profile.js' import typedHypixelApi from 'typed-hypixel-api' +import { ApiOptions } from '../../hypixel.js' export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles | undefined): CleanBasicProfile[] { if (!rawProfiles) return [] @@ -20,12 +21,15 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl } /** Convert an array of raw profiles into clean profiles */ -export async function cleanSkyblockProfilesResponse(data: typedHypixelApi.SkyBlockProfilesResponse['profiles']): Promise<CleanFullProfile[] | null> { +export async function cleanSkyblockProfilesResponse( + data: typedHypixelApi.SkyBlockProfilesResponse['profiles'], + options: ApiOptions +): Promise<CleanFullProfile[] | null> { if (!data) return null const promises: Promise<CleanFullProfile | null>[] = [] for (const profile of data) { - promises.push(cleanSkyblockProfileResponse(profile)) + promises.push(cleanSkyblockProfileResponse(profile, options)) } const cleanedProfiles: CleanFullProfile[] = (await Promise.all(promises)).filter((p): p is CleanFullProfile => p !== null) return cleanedProfiles diff --git a/src/hypixel.ts b/src/hypixel.ts index 95e4432..6fa544c 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -72,7 +72,7 @@ export async function sendCleanApiRequest<P extends keyof typeof cleanResponseFu const cleanResponseFunctions = { 'player': (data, options) => cleanPlayerResponse(data.player), 'skyblock/profile': (data: typedHypixelApi.SkyBlockProfileResponse, options) => cleanSkyblockProfileResponse(data.profile, options), - 'skyblock/profiles': (data, options) => cleanSkyblockProfilesResponse(data.profiles), + 'skyblock/profiles': (data, options) => cleanSkyblockProfilesResponse(data.profiles, options), 'skyblock/auctions_ended': (data, options) => cleanEndedAuctions(data), 'skyblock/auction': (data, options) => cleanAuctions(data, options.page ?? 0), 'resources/skyblock/election': (data, options) => cleanElectionResponse(data), |