aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-07-01 16:02:39 -0500
committermat <github@matdoes.dev>2022-07-01 16:02:39 -0500
commit9661f44e2eff4a3564d2a651bea1434d9cadf067 (patch)
tree70f0c899b85effcfaca0791a2575ace638af2b88 /src/cleaners/skyblock
parentb4a1f93bbc6479982b0d16437af0f29e0a924c8d (diff)
downloadskyblock-api-9661f44e2eff4a3564d2a651bea1434d9cadf067.tar.gz
skyblock-api-9661f44e2eff4a3564d2a651bea1434d9cadf067.tar.bz2
skyblock-api-9661f44e2eff4a3564d2a651bea1434d9cadf067.zip
Return auction buyer in playerauctions
Diffstat (limited to 'src/cleaners/skyblock')
-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]
+ }
+}