aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-18 18:20:44 +0000
committermat <github@matdoes.dev>2022-05-18 18:20:44 +0000
commit0f7e0ba6b71963f70a5e35ef3abc57747da8d49f (patch)
treea295d90ecca480b46ea37095b37980b8fe8cebf3 /src
parentd6516b5b5d8ecce0b872c87ce6dff65b42abe694 (diff)
downloadskyblock-api-0f7e0ba6b71963f70a5e35ef3abc57747da8d49f.tar.gz
skyblock-api-0f7e0ba6b71963f70a5e35ef3abc57747da8d49f.tar.bz2
skyblock-api-0f7e0ba6b71963f70a5e35ef3abc57747da8d49f.zip
better auction item list info
Diffstat (limited to 'src')
-rw-r--r--src/database.ts6
-rw-r--r--src/hypixel.ts22
2 files changed, 19 insertions, 9 deletions
diff --git a/src/database.ts b/src/database.ts
index 2cbab72..5ede904 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -1167,14 +1167,14 @@ export async function updateItemAuction(auction: ItemAuctionsSchema) {
/**
* Fetches the SkyBlock ids of all the items in the auctions database. This method is slow and should be cached!
*/
-export async function fetchItemsAuctionsIds(): Promise<string[] | undefined> {
+export async function fetchItemsAuctionsIds(skyblockIds: boolean = false): Promise<string[] | undefined> {
if (!itemAuctionsCollection) return undefined
const docs = await itemAuctionsCollection?.aggregate([
{ $sort: { oldestDate: -1 } },
// this removes everything except the _id
- { $project: { _id: true } }
+ { $project: skyblockIds ? { _id: false, sbId: true } : { _id: true } }
]).toArray()
- return docs.map(r => r._id)
+ return skyblockIds ? docs.filter(r => r.sbId).map(r => r.sbId) : docs.map(r => r._id)
}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index c614c1c..ebe2eea 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -446,20 +446,30 @@ export async function fetchAuctionItems() {
}
async function fetchAuctionItemsUncached() {
- const auctionItemIds = await fetchItemsAuctionsIds()
+ const auctionItemIds = await fetchItemsAuctionsIds(true)
if (!auctionItemIds) return undefined
const itemList = await fetchItemList()
- const idsToNames: Record<string, string> = {}
+ const idsToData: Record<string, {
+ display: { name: string }
+ vanillaId?: string
+ headTexture?: string
+ }> = {}
for (const item of itemList.list)
// we only return items in auctionItemIds so the response isn't too big,
// since usually it would contain stuff that we don't care about like
// minions
if (auctionItemIds.includes(item.id))
- idsToNames[item.id] = item.display.name
+ idsToData[item.id] = {
+ display: {
+ name: item.display.name
+ },
+ vanillaId: item.vanillaId,
+ headTexture: item.headTexture
+ }
// if the item in the database isn't in the items api, just set the name to the id
for (const item of auctionItemIds)
- if (!(item in idsToNames))
- idsToNames[item] = item.toLowerCase().replace(/^./, item[0].toUpperCase()).replace(/_/g, ' ')
- return idsToNames
+ if (!(item in idsToData))
+ idsToData[item] = { display: { name: item.toLowerCase().replace(/^./, item[0].toUpperCase()).replace(/_/g, ' ') } }
+ return idsToData
}