aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/achievements.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-19 18:55:26 +0000
committermat <github@matdoes.dev>2022-05-19 18:55:35 +0000
commit6cb86433e0190cdead1e213fa3d11391ba9c56e4 (patch)
tree062340dcd41dd9ebd79928e879665f77986d3139 /src/cleaners/achievements.ts
parent11e18feb755488cfb8f65fcf7db0204b997e41c9 (diff)
downloadskyblock-api-6cb86433e0190cdead1e213fa3d11391ba9c56e4.tar.gz
skyblock-api-6cb86433e0190cdead1e213fa3d11391ba9c56e4.tar.bz2
skyblock-api-6cb86433e0190cdead1e213fa3d11391ba9c56e4.zip
better achievements
Diffstat (limited to 'src/cleaners/achievements.ts')
-rw-r--r--src/cleaners/achievements.ts48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/cleaners/achievements.ts b/src/cleaners/achievements.ts
index 9e4c7ae..d556f74 100644
--- a/src/cleaners/achievements.ts
+++ b/src/cleaners/achievements.ts
@@ -1,18 +1,50 @@
import typedHypixelApi from 'typed-hypixel-api'
+import { fetchAchievements } from '../hypixelCached.js'
+
+interface Achievement {
+ id: string
+ name: string
+ value: number | boolean
+ description: string
+}
export interface Achievements {
- skyblock: Record<string, number>
+ skyblock: Achievement[]
}
-export function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataResponse['player']): Achievements {
- const achievements: Achievements = {
- skyblock: {}
+export async function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataResponse['player']): Promise<Achievements> {
+ const playerAchievements: Achievements = {
+ skyblock: []
}
- for (const [id, value] of Object.entries(data.achievements)) {
- if (id.startsWith('skyblock_'))
- achievements.skyblock[id.substring(9)] = value
+ const gameAchievements: typedHypixelApi.AchievementsResponse['achievements'] = await fetchAchievements()
+
+ for (const [gameId, achievementsData] of Object.entries(gameAchievements)) {
+ if (gameId !== 'skyblock') continue
+
+ let tieredAchievements: Achievement[] = []
+ for (const [achievementId, achievementData] of Object.entries(achievementsData.tiered)) {
+ const value = data.achievements[`skyblock_${achievementId}`] ?? 0
+ tieredAchievements.push({
+ id: achievementId.toLowerCase(),
+ name: achievementData.name,
+ value,
+ description: achievementData.description.replace(/%s/g, value.toString())
+ })
+ }
+
+ let oneTimeAchievements: Achievement[] = []
+ for (const [achievementId, achievementData] of Object.entries(achievementsData.one_time)) {
+ oneTimeAchievements.push({
+ id: achievementId.toLowerCase(),
+ name: achievementData.name,
+ value: data.achievementsOneTime.includes(`skyblock_${achievementId}`),
+ description: achievementData.description
+ })
+ }
+
+ playerAchievements[gameId] = [...tieredAchievements, ...oneTimeAchievements]
}
- return achievements
+ return playerAchievements
}