diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/harp.ts | 59 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 4 | ||||
-rw-r--r-- | src/constants.ts | 10 | ||||
-rw-r--r-- | src/database.ts | 1 |
4 files changed, 74 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 { diff --git a/src/constants.ts b/src/constants.ts index ddc9bc3..1371250 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -243,6 +243,16 @@ export async function addPets(addingPets: string[]): Promise<void> { await constants.addJSONConstants('pets.json', addingPets, 'pet') } +/** Fetch all the known SkyBlock harp songs as an array of strings */ +export async function fetchHarpSongs(): Promise<string[]> { + return await constants.fetchJSONConstant('harp_songs.json') +} + +/** Add harp songs to skyblock-constants. This has caching so it's fine to call many times */ +export async function addHarpSongs(addingSongs: string[]): Promise<void> { + await constants.addJSONConstants('harp_songs.json', addingSongs, 'harp song') +} + interface constantValues { max_minions?: number diff --git a/src/database.ts b/src/database.ts index 8f5d9d7..a822112 100644 --- a/src/database.ts +++ b/src/database.ts @@ -621,6 +621,7 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu await constants.addZones(member.zones.map(zone => zone.name)) await constants.addSlayers(member.slayers.bosses.map(s => s.rawName)) await constants.addPets(member.pets.list.map(s => s.id)) + await constants.addHarpSongs(member.harp.songs.map(s => s.id)) if (debug) console.debug('done constants..') |