diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 7 | ||||
-rw-r--r-- | src/database.ts | 4 | ||||
-rw-r--r-- | src/hypixel.ts | 20 |
3 files changed, 26 insertions, 5 deletions
diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts index df30be3..b5c85e2 100644 --- a/src/cleaners/skyblock/inventory.ts +++ b/src/cleaners/skyblock/inventory.ts @@ -21,6 +21,9 @@ export interface Item { anvilUses?: number timestamp?: string enchantments?: { [name: string]: number } + petInfo?: { + id: string + } headTexture?: string } @@ -54,6 +57,7 @@ function cleanItem(rawItem): Item | null { headId = headIdFromBase64(headDataBase64) } + return { id: extraAttributes?.id ?? null, count: itemCount ?? 1, @@ -70,6 +74,9 @@ function cleanItem(rawItem): Item | null { enchantments: extraAttributes?.enchantments, anvilUses: extraAttributes?.anvil_uses, timestamp: extraAttributes?.timestamp, + petInfo: extraAttributes?.petInfo ? { + id: JSON.parse(extraAttributes.petInfo).type + } : undefined, headTexture: headId, } diff --git a/src/database.ts b/src/database.ts index d0ad04b..e31794a 100644 --- a/src/database.ts +++ b/src/database.ts @@ -146,11 +146,13 @@ export interface SimpleAuctionSchema { export interface ItemAuctionsSchema { /** The id of the item */ id: string + sbId: string auctions: SimpleAuctionSchema[] } export interface ItemAuctionsSchemaBson { /** The id of the item */ _id: string + sbId: string auctions: SimpleAuctionSchemaBson[] /** This is here so it can be indexed by Mongo, it can easily be figured out by getting the first item in auctions */ oldestDate: number @@ -1116,6 +1118,7 @@ export async function updateAccount(discordId: string, schema: AccountSchema) { function toItemAuctionsSchema(i: ItemAuctionsSchemaBson): ItemAuctionsSchema { return { id: i._id, + sbId: i.sbId, auctions: i.auctions.map(a => { return { ...a, @@ -1128,6 +1131,7 @@ function toItemAuctionsSchema(i: ItemAuctionsSchemaBson): ItemAuctionsSchema { function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson { return { _id: i.id, + sbId: i.sbId, auctions: i.auctions.map(a => { return { ...a, diff --git a/src/hypixel.ts b/src/hypixel.ts index 0407514..929c700 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -36,6 +36,7 @@ import { cleanEndedAuctions } from './cleaners/skyblock/endedAuctions.js' import { cleanAuctions } from './cleaners/skyblock/auctions.js' import { string } from 'prismarine-nbt' import { withCache } from './util.js' +import { Item } from './cleaners/skyblock/inventory.js' export type Included = 'profiles' | 'player' | 'stats' | 'inventories' | undefined @@ -330,6 +331,12 @@ export async function fetchAuctionUncached(uuid: string) { ) } +function createAuctionItemId(item: Item) { + if (item.id === 'PET' && item.petInfo?.id) + return `${item.petInfo.id}_${item.id}` + return item.id +} + // this function is called from database.ts so it starts when we connect to the database // it should only ever be called once! export async function periodicallyFetchRecentlyEndedAuctions() { @@ -348,7 +355,7 @@ export async function periodicallyFetchRecentlyEndedAuctions() { for (const auction of endedAuctions.auctions) { if (previousAuctionIds.has(auction.id)) continue newAuctionUuids.add(auction.id) - newAuctionItemIds.add(auction.item.id) + newAuctionItemIds.add(createAuctionItemId(auction.item)) } let updatedDatabaseAuctionItems: Map<string, ItemAuctionsSchema> = new Map() @@ -360,11 +367,13 @@ export async function periodicallyFetchRecentlyEndedAuctions() { for (const auction of endedAuctions.auctions) { if (previousAuctionIds.has(auction.id)) continue + const auctionItemId = createAuctionItemId(auction.item) + let auctions: SimpleAuctionSchema[] - if (!updatedDatabaseAuctionItems.has(auction.item.id)) { + if (!updatedDatabaseAuctionItems.has(auctionItemId)) { auctions = [] } else { - auctions = updatedDatabaseAuctionItems.get(auction.item.id)!.auctions + auctions = updatedDatabaseAuctionItems.get(auctionItemId)!.auctions } const simpleAuction: SimpleAuctionSchema = { @@ -382,8 +391,9 @@ export async function periodicallyFetchRecentlyEndedAuctions() { auctions = auctions.slice(-100) } - updatedDatabaseAuctionItems.set(auction.item.id, { - id: auction.item.id, + updatedDatabaseAuctionItems.set(auctionItemId, { + id: auctionItemId, + sbId: auction.item.id, auctions, }) } |