aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/player.ts
blob: c6d975968f2d249d32f238e06de8cc9c397b9be5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { cleanSocialMedia, CleanSocialMedia } from './socialmedia.js'
import { cleanPlayerSkyblockProfiles } from './skyblock/profiles.js'
import { cleanPlayerSkyblockClaimed } from './skyblock/claimed.js'
import { cleanPlayerAchievements, Achievements } from './achievements.js'
import { CleanBasicProfile } from './skyblock/profile.js'
import { cleanRank, CleanRank } from './rank.js'
import typedHypixelApi from 'typed-hypixel-api'
import { undashUuid } from '../util.js'

export interface CleanBasicPlayer {
    uuid: string
    username: string
}

export interface ClaimedSkyBlockItem {
    /**
     * name is kept for backwards compatibility, it will be changed to a more
     * human readable name later
     */
    name: string
    id: string
    timestamp: number
}

export interface CleanPlayer extends CleanBasicPlayer {
    rank: CleanRank
    socials: CleanSocialMedia
    profiles?: CleanBasicProfile[]
}

export interface CleanFullPlayer extends CleanPlayer {
    achievements: Achievements
    claimed: ClaimedSkyBlockItem[]
}

export async function cleanPlayerResponse(data: typedHypixelApi.PlayerDataResponse['player']): Promise<CleanFullPlayer | null> {
    // Cleans up a 'player' api response
    if (!data)
        return null
    return {
        uuid: undashUuid(data.uuid),
        username: data.displayname,
        rank: cleanRank(data),
        socials: cleanSocialMedia(data),
        profiles: cleanPlayerSkyblockProfiles(data.stats?.SkyBlock?.profiles),
        claimed: cleanPlayerSkyblockClaimed(data),
        achievements: await cleanPlayerAchievements(data)
    }
}