aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners
diff options
context:
space:
mode:
Diffstat (limited to 'src/cleaners')
-rw-r--r--src/cleaners/skyblock/auctions.ts42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/cleaners/skyblock/auctions.ts b/src/cleaners/skyblock/auctions.ts
index 2d50111..f48d422 100644
--- a/src/cleaners/skyblock/auctions.ts
+++ b/src/cleaners/skyblock/auctions.ts
@@ -1,12 +1,13 @@
import typedHypixelApi from 'typed-hypixel-api'
-import { cleanInventory, headIdFromBase64, Item } from './inventory.js'
-
+import { cleanInventory, Item } from './inventory.js'
+import * as cached from '../../hypixelCached.js'
+import { CleanPlayer } from '../player.js'
export interface Auction {
id: string
sellerUuid: string
sellerProfileUuid: string
- buyerUuid: string | null
+ buyer: CleanPlayer | null
creationTimestamp: number
boughtTimestamp: number
coins: number
@@ -14,25 +15,34 @@ export interface Auction {
item: Item
}
+
export async function cleanAuctions(data: typedHypixelApi.SkyBlockRequestAuctionResponse): Promise<Auction[]> {
- const auctions: Auction[] = []
+ const auctionPromises: Promise<Auction>[] = []
for (const auction of data.auctions) {
- auctions.push({
- id: auction.uuid,
- sellerUuid: auction.auctioneer,
- sellerProfileUuid: auction.profile_id,
- creationTimestamp: auction.start,
- buyerUuid: auction.end ? auction.bids[auction.bids.length - 1].bidder : null,
- boughtTimestamp: auction.end,
- coins: auction.highest_bid_amount,
- bin: auction.bin ?? false,
- item: (await cleanInventory(typeof auction.item_bytes === 'string' ? auction.item_bytes : auction.item_bytes.data))[0]
- })
+ auctionPromises.push(cleanAuction(auction))
}
+ const auctions = await Promise.all(auctionPromises)
+
// sort by newer first
auctions.sort((a, b) => a.creationTimestamp - b.creationTimestamp)
return auctions
-} \ No newline at end of file
+}
+
+async function cleanAuction(auction: typedHypixelApi.SkyBlockRequestAuctionResponse['auctions'][number]): Promise<Auction> {
+ const buyerUuid = auction.end ? auction.bids[auction.bids.length - 1].bidder : null
+ const buyer = buyerUuid ? await cached.fetchPlayer(buyerUuid, false) : null
+ return {
+ id: auction.uuid,
+ sellerUuid: auction.auctioneer,
+ sellerProfileUuid: auction.profile_id,
+ creationTimestamp: auction.start,
+ buyer,
+ boughtTimestamp: auction.end,
+ coins: auction.highest_bid_amount,
+ bin: auction.bin ?? false,
+ item: (await cleanInventory(typeof auction.item_bytes === 'string' ? auction.item_bytes : auction.item_bytes.data))[0]
+ }
+}