diff options
author | mat <github@matdoes.dev> | 2022-05-18 15:44:44 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-05-18 15:44:44 +0000 |
commit | bdfd50bd56a2441a4a2421f8163423d3091ca4e9 (patch) | |
tree | fb46e428e0927a0cca4233dbdb440b4ed1e29257 /src/hypixel.ts | |
parent | 9defd9b01b3c733c2e423f32e92c748d70765c87 (diff) | |
download | skyblock-api-bdfd50bd56a2441a4a2421f8163423d3091ca4e9.tar.gz skyblock-api-bdfd50bd56a2441a4a2421f8163423d3091ca4e9.tar.bz2 skyblock-api-bdfd50bd56a2441a4a2421f8163423d3091ca4e9.zip |
split enchanted books into their own auction items
Diffstat (limited to 'src/hypixel.ts')
-rw-r--r-- | src/hypixel.ts | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/hypixel.ts b/src/hypixel.ts index 929c700..c614c1c 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -331,9 +331,19 @@ export async function fetchAuctionUncached(uuid: string) { ) } -function createAuctionItemId(item: Item) { +/** + * Create an id that we use to differenciate between different items that are sold in auctions. This can also be used to filter out specific items by returning undefined. + */ +function createAuctionItemId(item: Item): string | undefined { if (item.id === 'PET' && item.petInfo?.id) return `${item.petInfo.id}_${item.id}` + if (item.id === 'ENCHANTED_BOOK') { + if (Object.keys(item.enchantments ?? {}).length !== 1) + // we only care about enchanted books that have a single enchantment + return + const [[enchantName, enchantValue]] = Object.entries(item.enchantments ?? {}) + return `${item.id}_${enchantName.toUpperCase()}_${enchantValue}` + } return item.id } @@ -354,8 +364,11 @@ export async function periodicallyFetchRecentlyEndedAuctions() { for (const auction of endedAuctions.auctions) { if (previousAuctionIds.has(auction.id)) continue + const auctionItemId = createAuctionItemId(auction.item) + if (!auctionItemId) continue + newAuctionUuids.add(auction.id) - newAuctionItemIds.add(createAuctionItemId(auction.item)) + newAuctionItemIds.add(auctionItemId) } let updatedDatabaseAuctionItems: Map<string, ItemAuctionsSchema> = new Map() @@ -368,6 +381,7 @@ export async function periodicallyFetchRecentlyEndedAuctions() { if (previousAuctionIds.has(auction.id)) continue const auctionItemId = createAuctionItemId(auction.item) + if (!auctionItemId) continue let auctions: SimpleAuctionSchema[] if (!updatedDatabaseAuctionItems.has(auctionItemId)) { |