aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/endedAuctions.ts
blob: 0c61c6c39a27ee5dd2ddab2bdb34eae9e8014a54 (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
import typedHypixelApi from 'typed-hypixel-api'
import { cleanInventory, headIdFromBase64, Item } from './inventory.js'
import { cleanItemId } from './itemId.js'


interface EndedAuction {
    id: string
    sellerUuid: string
    sellerProfileUuid: string
    buyerUuid: string
    timestamp: number
    coins: number
    bin: boolean
    item: Item
}

export interface EndedAuctions {
    lastUpdated: number
    auctions: EndedAuction[]
}

export async function cleanEndedAuctions(data: typedHypixelApi.SkyBlockRecentlyEndedAuctionsResponse): Promise<EndedAuctions> {
    const auctions: EndedAuction[] = []
    for (const auction of data.auctions) {
        auctions.push({
            id: auction.auction_id,
            sellerUuid: auction.seller,
            sellerProfileUuid: auction.seller_profile,
            buyerUuid: auction.buyer,
            timestamp: auction.timestamp,
            coins: auction.price,
            bin: auction.bin,
            item: (await cleanInventory(auction.item_bytes))[0]
        })
    }

    return {
        lastUpdated: data.lastUpdated,
        auctions
    }
}