diff options
author | mat <github@matdoes.dev> | 2022-05-19 19:09:12 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-05-19 19:09:12 +0000 |
commit | a7d20149e6cfebec77b5c0ecc95ca55d23d02e94 (patch) | |
tree | 6ca5589339fdfd6ab3c7a60457f7a513d5a98a90 | |
parent | 6dde7dcc4926288bf710bb40b6807ec596692085 (diff) | |
download | skyblock-api-a7d20149e6cfebec77b5c0ecc95ca55d23d02e94.tar.gz skyblock-api-a7d20149e6cfebec77b5c0ecc95ca55d23d02e94.tar.bz2 skyblock-api-a7d20149e6cfebec77b5c0ecc95ca55d23d02e94.zip |
fix
-rw-r--r-- | src/cleaners/achievements.ts | 28 | ||||
-rw-r--r-- | src/cleaners/skyblock/skills.ts | 22 |
2 files changed, 30 insertions, 20 deletions
diff --git a/src/cleaners/achievements.ts b/src/cleaners/achievements.ts index b2e6324..3e93532 100644 --- a/src/cleaners/achievements.ts +++ b/src/cleaners/achievements.ts @@ -1,14 +1,24 @@ import typedHypixelApi from 'typed-hypixel-api' import { fetchAchievements } from '../hypixelCached.js' -interface Achievement { +interface TieredAchievement { id: string name: string - value: number | boolean + value?: number description: string } -export type Achievements = Achievement[] +interface OneTimeAchievement { + id: string + name: string + achieved: boolean + description: string +} + +export interface Achievements { + tiered: TieredAchievement[] + oneTime: OneTimeAchievement[] +} export async function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataResponse['player']): Promise<Achievements> { const gameAchievements: typedHypixelApi.AchievementsResponse['achievements'] = await fetchAchievements() @@ -16,9 +26,9 @@ export async function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataRe for (const [gameId, achievementsData] of Object.entries(gameAchievements)) { if (gameId !== 'skyblock') continue - let tieredAchievements: Achievement[] = [] + let tieredAchievements: TieredAchievement[] = [] for (const [achievementId, achievementData] of Object.entries(achievementsData.tiered)) { - const value = data.achievements[`skyblock_${achievementId}`] ?? 0 + const value = data.achievements[`skyblock_${achievementId}`] ?? undefined tieredAchievements.push({ id: achievementId.toLowerCase(), name: achievementData.name, @@ -27,20 +37,20 @@ export async function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataRe }) } - let oneTimeAchievements: Achievement[] = [] + let oneTimeAchievements: OneTimeAchievement[] = [] for (const [achievementId, achievementData] of Object.entries(achievementsData.one_time)) { oneTimeAchievements.push({ id: achievementId.toLowerCase(), name: achievementData.name, - value: data.achievementsOneTime.includes(`skyblock_${achievementId}`), + achieved: data.achievementsOneTime.includes(`skyblock_${achievementId}`), description: achievementData.description }) } - return [...tieredAchievements, ...oneTimeAchievements] + return { tiered: tieredAchievements, oneTime: oneTimeAchievements } } // this shouldn't be possible console.debug('skyblock not found in achievements?') - return [] + return { tiered: [], oneTime: [] } } diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts index b70b2ea..9f53e5a 100644 --- a/src/cleaners/skyblock/skills.ts +++ b/src/cleaners/skyblock/skills.ts @@ -165,19 +165,19 @@ function skillFromLevel(id: string, level: number | undefined): Skill { } } -function skillsFromSkyBlockAchievements(achievements: CleanFullPlayer['achievements']['skyblock']): Skills { +function skillsFromSkyBlockAchievements(achievements: CleanFullPlayer['achievements']): Skills { return { apiEnabled: false, list: [ - skillFromLevel('fishing', achievements['angler']), - skillFromLevel('enchanting', achievements['augmentation']), - skillFromLevel('combat', achievements['combat']), - skillFromLevel('alchemy', achievements['concoctor']), - skillFromLevel('taming', achievements['domesticator']), - skillFromLevel('dungeoneering', achievements['dungeoneer']), - skillFromLevel('mining', achievements['excavator']), - skillFromLevel('foraging', achievements['gatherer']), - skillFromLevel('farming', achievements['harvester']) + skillFromLevel('fishing', achievements.tiered.find(a => a.id === 'angler')?.value ?? 0), + skillFromLevel('enchanting', achievements.tiered.find(a => a.id === 'augmentation')?.value ?? 0), + skillFromLevel('combat', achievements.tiered.find(a => a.id === 'combat')?.value ?? 0), + skillFromLevel('alchemy', achievements.tiered.find(a => a.id === 'concoctor')?.value ?? 0), + skillFromLevel('taming', achievements.tiered.find(a => a.id === 'domesticator')?.value ?? 0), + skillFromLevel('dungeoneering', achievements.tiered.find(a => a.id === 'dungeoneer')?.value ?? 0), + skillFromLevel('mining', achievements.tiered.find(a => a.id === 'excavator')?.value ?? 0), + skillFromLevel('foraging', achievements.tiered.find(a => a.id === 'gatherer')?.value ?? 0), + skillFromLevel('farming', achievements.tiered.find(a => a.id === 'harvester')?.value ?? 0) ] } } @@ -226,7 +226,7 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember, p // if the player has no skills but has kills, we can assume they have the skills api off // (we check kills to know whether the profile is actually used, this is kinda arbitrary) if (skills.length === 0 && 'stats' in data && Object.keys(data.stats).includes('kills')) { - return skillsFromSkyBlockAchievements(player.achievements.skyblock) + return skillsFromSkyBlockAchievements(player.achievements) } constants.addSkills(skillNamesFound) |