aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cleaners/skyblock/auctions.ts42
-rw-r--r--src/hypixel.ts3
2 files changed, 27 insertions, 18 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]
+ }
+}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index 944206d..8080a4f 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -23,7 +23,7 @@ import {
updateItemAuction
} from './database.js'
import { cleanElectionResponse, ElectionData } from './cleaners/skyblock/election.js'
-import { cleanItemListResponse, ItemListData } from './cleaners/skyblock/itemList.js'
+import { cleanItemListResponse } from './cleaners/skyblock/itemList.js'
import { CleanBasicMember, CleanMemberProfile } from './cleaners/skyblock/member.js'
import { cleanSkyblockProfilesResponse } from './cleaners/skyblock/profiles.js'
import { CleanPlayer, cleanPlayerResponse } from './cleaners/player.js'
@@ -34,7 +34,6 @@ import { debug } from './index.js'
import { WithId } from 'mongodb'
import { cleanEndedAuctions } from './cleaners/skyblock/endedAuctions.js'
import { Auction, cleanAuctions } from './cleaners/skyblock/auctions.js'
-import { string } from 'prismarine-nbt'
import { withCache } from './util.js'
import { Item } from './cleaners/skyblock/inventory.js'