diff options
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/harp.ts | 59 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 4 |
2 files changed, 63 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 diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 161f5cc..99a4376 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -16,6 +16,7 @@ import { Included } from '../../hypixel.js' import { CleanPlayer } from '../player.js' import { CleanRank } from '../rank.js' import { cleanPets, Pet, PetsData } from './pets.js' +import { cleanHarp, HarpData } from './harp.js' export interface CleanBasicMember { uuid: string @@ -39,6 +40,7 @@ export interface CleanMember extends CleanBasicMember { collections: Collection[] slayers: SlayerData pets: PetsData + harp: HarpData /** Whether the user left the coop */ left: boolean } @@ -90,6 +92,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi collections: cleanCollections(member), slayers: cleanSlayers(member), pets: await cleanPets(member), + harp: await cleanHarp(member), left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false } @@ -113,6 +116,7 @@ export interface CleanMemberProfilePlayer extends CleanPlayer { collections: Collection[] slayers: SlayerData pets: PetsData + harp: HarpData } export interface CleanMemberProfile { |