diff options
author | mat <github@matdoes.dev> | 2022-12-25 00:44:51 -0600 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-12-25 00:44:51 -0600 |
commit | 58fc378174faf11391885281759caa39d9b324cc (patch) | |
tree | 239317f402ddfe663d2f173ea9baa54110a24e3b /src/cleaners/skyblock/profile.ts | |
parent | 30299473e6b14fc3bd8254e2a71043a9151073a5 (diff) | |
download | skyblock-api-58fc378174faf11391885281759caa39d9b324cc.tar.gz skyblock-api-58fc378174faf11391885281759caa39d9b324cc.tar.bz2 skyblock-api-58fc378174faf11391885281759caa39d9b324cc.zip |
fix lastsave
hypixel moved it a while ago and i hadn't bothered fixing it
Diffstat (limited to 'src/cleaners/skyblock/profile.ts')
-rw-r--r-- | src/cleaners/skyblock/profile.ts | 18 |
1 files changed, 16 insertions, 2 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 } |