aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/itemList.ts
blob: a534628e13b68cc83582ab774c7a9b1dcbdbbc6d (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
50
51
52
53
54
55
56
57
58
59
60
import typedHypixelApi from 'typed-hypixel-api'

export interface ItemRequirement {
    // idk what these do
    // they'll probably be renamed at some point
    dungeon: {
        type: string
        level: number
    }
}

// based on Item from inventory.ts
export interface ItemListItem {
    id: string
    vanillaId: string
    tier: string | null
    display: {
        name: string
        glint: boolean
    }
    npc_sell_price: number | null
    requirements: ItemRequirement | null
}

export interface ItemListData {
    lastUpdated: number
    list: ItemListItem[]
}

function cleanItemRequirements(data: typedHypixelApi.SkyBlockItemsResponse['items'][number]['requirements'] & typedHypixelApi.SkyBlockItemsResponse['items'][number]['catacombs_requirements']): ItemRequirement | null {
    if (!data || !data.dungeon) return null
    return {
        dungeon: {
            type: data.dungeon.type,
            level: data.dungeon.level
        }
    }
}

function cleanItemListItem(item: typedHypixelApi.SkyBlockItemsResponse['items'][number]): ItemListItem {
    const vanillaId = item.material.toLowerCase()
    return {
        id: item.id,
        vanillaId: item.durability ? `${vanillaId}:${item.durability}` : vanillaId,
        tier: item.tier ?? null,
        display: {
            name: item.name,
            glint: item.glowing ?? false
        },
        npc_sell_price: item.npc_sell_price ?? null,
        requirements: cleanItemRequirements(item.catacombs_requirements ?? item.requirements)
    }
}

export async function cleanItemListResponse(data: typedHypixelApi.SkyBlockItemsResponse): Promise<ItemListData> {
    return {
        lastUpdated: data.lastUpdated,
        list: data.items.map(cleanItemListItem)
    }
}