diff options
author | mat <github@matdoes.dev> | 2022-03-27 17:04:47 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-27 17:04:47 -0500 |
commit | b9053538aee604b62ae54538320f930c2c96e0aa (patch) | |
tree | 0bff78af3acb122e0d895f05383f1a08d55ab189 /src/cleaners/skyblock/harp.ts | |
parent | e01d991d518fc6b3f060d805175b6b8631a2b8ed (diff) | |
download | skyblock-api-b9053538aee604b62ae54538320f930c2c96e0aa.tar.gz skyblock-api-b9053538aee604b62ae54538320f930c2c96e0aa.tar.bz2 skyblock-api-b9053538aee604b62ae54538320f930c2c96e0aa.zip |
Add harp stats
Diffstat (limited to 'src/cleaners/skyblock/harp.ts')
-rw-r--r-- | src/cleaners/skyblock/harp.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/harp.ts b/src/cleaners/skyblock/harp.ts new file mode 100644 index 0000000..aea1212 --- /dev/null +++ b/src/cleaners/skyblock/harp.ts @@ -0,0 +1,59 @@ +import typedHypixelApi from 'typed-hypixel-api' +import { fetchHarpSongs } from '../../constants.js' + +export interface HarpSong { + id: string + /** A number between 0 and 1 representing the user's best completion */ + progress: number + completions: number + perfectCompletions: number +} + +export interface HarpData { + selected: { + name: string + timestamp: number + } | null + claimedMelodysHair: boolean + songs: HarpSong[] +} + +export async function cleanHarp(data: typedHypixelApi.SkyBlockProfileMember): Promise<HarpData> { + const harpQuestData = data.harp_quest ?? {} + const songs: HarpSong[] = [] + + const allHarpSongNames = await fetchHarpSongs() + + for (const item in data.harp_quest) { + if (item.startsWith('song_') && item.endsWith('_best_completion')) { + const songName = item.slice('song_'.length, -'_best_completion'.length) + songs.push({ + id: songName, + completions: data.harp_quest[`song_${songName}_completions`], + perfectCompletions: data.harp_quest[`song_${songName}_perfect_completions`], + progress: data.harp_quest[`song_${songName}_best_completion`] + }) + } + } + + const missingHarpSongNames = allHarpSongNames.filter(songName => !songs.find(song => song.id === songName)) + for (const songName of missingHarpSongNames) { + songs.push({ + id: songName, + completions: 0, + perfectCompletions: 0, + progress: 0 + }) + } + + + return { + selected: harpQuestData?.selected_song ? { + name: harpQuestData.selected_song, + // i'm pretty sure the epoch is always there if the name is + timestamp: harpQuestData.selected_song_epoch ?? 0 + } : null, + claimedMelodysHair: harpQuestData?.claimed_talisman ?? false, + songs + } +}
\ No newline at end of file |