aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/achievements.ts
diff options
context:
space:
mode:
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
}