aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/player.ts
blob: f49d72c2c9f3db11a46191f50518b899514f7f40 (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
import { CleanSocialMedia, parseSocialMedia } from './socialmedia'
import { CleanRank, parseRank } from './rank'
import { HypixelPlayer } from '../hypixelApi'
import { undashUuid } from '../util'
import { CleanBasicProfile } from './skyblock/profile'
import { cleanPlayerSkyblockProfiles } from './skyblock/profiles'

export interface CleanBasicPlayer {
    uuid: string
    username: string
}

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

export async function cleanPlayerResponse(data: HypixelPlayer): Promise<CleanPlayer> {
    // Cleans up a 'player' api response
    return {
        uuid: undashUuid(data.uuid),
        username: data.displayname,
        rank: parseRank(data),
        socials: parseSocialMedia(data.socialMedia),
        profiles: cleanPlayerSkyblockProfiles(data.stats.SkyBlock.profiles)
    }
}