aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners
diff options
context:
space:
mode:
Diffstat (limited to 'src/cleaners')
-rw-r--r--src/cleaners/achievements.ts48
-rw-r--r--src/cleaners/player.ts2
-rw-r--r--src/cleaners/skyblock/stats.ts1
-rw-r--r--src/cleaners/skyblock/zones.ts1
4 files changed, 41 insertions, 11 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
}
diff --git a/src/cleaners/player.ts b/src/cleaners/player.ts
index 8facdad..5de65de 100644
--- a/src/cleaners/player.ts
+++ b/src/cleaners/player.ts
@@ -44,6 +44,6 @@ export async function cleanPlayerResponse(data: typedHypixelApi.PlayerDataRespon
socials: cleanSocialMedia(data),
profiles: cleanPlayerSkyblockProfiles(data.stats?.SkyBlock?.profiles),
claimed: cleanPlayerSkyblockClaimed(data),
- achievements: cleanPlayerAchievements(data)
+ achievements: await cleanPlayerAchievements(data)
}
}
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts
index fc55577..8105f26 100644
--- a/src/cleaners/skyblock/stats.ts
+++ b/src/cleaners/skyblock/stats.ts
@@ -102,7 +102,6 @@ export function getStatUnit(name: string): string | null {
export function cleanProfileStats(data: typedHypixelApi.SkyBlockProfileMember): StatItem[] {
- // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there)
const stats: StatItem[] = []
const rawStats = data?.stats ?? {}
diff --git a/src/cleaners/skyblock/zones.ts b/src/cleaners/skyblock/zones.ts
index 92f4e81..6d75cec 100644
--- a/src/cleaners/skyblock/zones.ts
+++ b/src/cleaners/skyblock/zones.ts
@@ -17,7 +17,6 @@ export async function cleanVisitedZones(data: typedHypixelApi.SkyBlockProfileMem
constants.addZones(rawZones)
- // TODO: store all the zones that exist in SkyBlock, add add those to the array with visited being false
const zones: Zone[] = []
const knownZones = await constants.fetchZones()