diff options
author | mat <github@matdoes.dev> | 2022-05-15 22:37:22 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-05-15 22:37:22 -0500 |
commit | a206dee8301e5a8723daab819f175d7ab01f9029 (patch) | |
tree | 303fc991d9b3dfd67e1c4ebc2249401d01074658 /src/cleaners/skyblock | |
parent | 74ccbaef865f328283f91533b9c26daed6cff006 (diff) | |
download | skyblock-api-a206dee8301e5a8723daab819f175d7ab01f9029.tar.gz skyblock-api-a206dee8301e5a8723daab819f175d7ab01f9029.tar.bz2 skyblock-api-a206dee8301e5a8723daab819f175d7ab01f9029.zip |
add very basic auctionprices endpoint
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/endedAuctions.ts | 41 | ||||
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 17 |
2 files changed, 48 insertions, 10 deletions
diff --git a/src/cleaners/skyblock/endedAuctions.ts b/src/cleaners/skyblock/endedAuctions.ts new file mode 100644 index 0000000..0dfa0ab --- /dev/null +++ b/src/cleaners/skyblock/endedAuctions.ts @@ -0,0 +1,41 @@ +import typedHypixelApi from 'typed-hypixel-api' +import { cleanInventory, headIdFromBase64, Item } from './inventory.js' +import { cleanItemId } from './itemId.js' + + +interface Auction { + id: string + sellerUuid: string + sellerProfileUuid: string + buyerUuid: string + timestamp: number + coins: number + bin: boolean + item: Item +} + +export interface EndedAuctions { + lastUpdated: number + auctions: Auction[] +} + +export async function cleanEndedAuctions(data: typedHypixelApi.SkyBlockRecentlyEndedAuctionsResponse): Promise<EndedAuctions> { + const auctions: Auction[] = [] + 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 + } +}
\ No newline at end of file diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts index c5ab952..df30be3 100644 --- a/src/cleaners/skyblock/inventory.ts +++ b/src/cleaners/skyblock/inventory.ts @@ -6,7 +6,7 @@ function base64decode(base64: string): Buffer { return Buffer.from(base64, 'base64') } -interface Item { +export interface Item { id: string count: number vanillaId: string @@ -79,15 +79,12 @@ function cleanItems(rawItems): Inventory { return rawItems.map(cleanItem) } -export function cleanInventory(encodedNbt: string): Promise<Inventory> { - return new Promise(resolve => { - const base64Data = base64decode(encodedNbt) - nbt.parse(base64Data, false, (err, value) => { - const simplifiedNbt = nbt.simplify(value) - // do some basic cleaning on the items and return - resolve(cleanItems(simplifiedNbt.i)) - }) - }) +export async function cleanInventory(encodedNbt: string): Promise<Inventory> { + const base64Data = base64decode(encodedNbt) + const value: any = await new Promise((resolve, reject) => nbt.parse(base64Data, false, (err, value) => { if (err) reject(err); else resolve(value) })) + const simplifiedNbt = nbt.simplify(value) + // do some basic cleaning on the items and return + return cleanItems(simplifiedNbt.i) } export const INVENTORIES = { |