aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/cache/updatePriceItemCache.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/tasks/cache/updatePriceItemCache.ts')
-rw-r--r--src/tasks/cache/updatePriceItemCache.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tasks/cache/updatePriceItemCache.ts b/src/tasks/cache/updatePriceItemCache.ts
new file mode 100644
index 0000000..9809cbd
--- /dev/null
+++ b/src/tasks/cache/updatePriceItemCache.ts
@@ -0,0 +1,27 @@
+import { BushTask, Time } from '#lib';
+import got from 'got';
+import PriceCommand, { AuctionAverages, Bazaar, LowestBIN } from '../../commands/utilities/price.js';
+
+export default class UpdatePriceItemCache extends BushTask {
+ public constructor() {
+ super('updatePriceItemCache', {
+ delay: 10 * Time.Minute,
+ runOnStart: true
+ });
+ }
+
+ public async exec() {
+ const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all(
+ PriceCommand.urls.map(({ url }) => got.get(url).json().catch(undefined))
+ )) as [Bazaar?, LowestBIN?, LowestBIN?, AuctionAverages?];
+
+ const itemNames = new Set([
+ ...Object.keys(averageLowestBIN ?? {}),
+ ...Object.keys(currentLowestBIN ?? {}),
+ ...Object.keys(auctionAverages ?? {}),
+ ...Object.keys(bazaar?.products ?? {})
+ ]);
+
+ PriceCommand.cachedItemList = [...itemNames];
+ }
+}