aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/cache
diff options
context:
space:
mode:
Diffstat (limited to 'src/tasks/cache')
-rw-r--r--src/tasks/cache/updateCache.ts49
-rw-r--r--src/tasks/cache/updatePriceItemCache.ts6
2 files changed, 4 insertions, 51 deletions
diff --git a/src/tasks/cache/updateCache.ts b/src/tasks/cache/updateCache.ts
index 595a872..190e2a4 100644
--- a/src/tasks/cache/updateCache.ts
+++ b/src/tasks/cache/updateCache.ts
@@ -1,8 +1,4 @@
-import { Global, Guild, Shared, type BushClient } from '#lib';
-import type { Client } from 'discord.js';
-import config from '../../../config/options.js';
-import { BushTask } from '../../../lib/extensions/discord-akairo/BushTask.js';
-import { Time } from '../../../lib/utils/BushConstants.js';
+import { BushTask, Time, updateEveryCache } from '#lib';
export default class UpdateCacheTask extends BushTask {
public constructor() {
@@ -13,48 +9,7 @@ export default class UpdateCacheTask extends BushTask {
}
public async exec() {
- await Promise.all([
- UpdateCacheTask.#updateGlobalCache(this.client),
- UpdateCacheTask.#updateSharedCache(this.client),
- UpdateCacheTask.#updateGuildCache(this.client)
- ]);
+ await updateEveryCache(this.client);
void this.client.logger.verbose(`UpdateCache`, `Updated cache.`);
}
-
- public static async init(client: BushClient) {
- await Promise.all([
- UpdateCacheTask.#updateGlobalCache(client),
- UpdateCacheTask.#updateSharedCache(client),
- UpdateCacheTask.#updateGuildCache(client)
- ]);
- }
-
- static async #updateGlobalCache(client: Client) {
- const environment = config.environment;
- const row: { [x: string]: any } = ((await Global.findByPk(environment)) ?? (await Global.create({ environment }))).toJSON();
-
- for (const option in row) {
- if (Object.keys(client.cache.global).includes(option)) {
- client.cache.global[option as keyof typeof client.cache.global] = row[option];
- }
- }
- }
-
- static async #updateSharedCache(client: Client) {
- const row: { [x: string]: any } = ((await Shared.findByPk(0)) ?? (await Shared.create())).toJSON();
-
- for (const option in row) {
- if (Object.keys(client.cache.shared).includes(option)) {
- client.cache.shared[option as keyof typeof client.cache.shared] = row[option];
- if (option === 'superUsers') client.superUserID = row[option];
- }
- }
- }
-
- static async #updateGuildCache(client: Client) {
- const rows = await Guild.findAll();
- for (const row of rows) {
- client.cache.guilds.set(row.id, row.toJSON() as Guild);
- }
- }
}
diff --git a/src/tasks/cache/updatePriceItemCache.ts b/src/tasks/cache/updatePriceItemCache.ts
index 55115cc..bafbfaf 100644
--- a/src/tasks/cache/updatePriceItemCache.ts
+++ b/src/tasks/cache/updatePriceItemCache.ts
@@ -1,5 +1,4 @@
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 {
@@ -13,9 +12,8 @@ export default class UpdatePriceItemCache extends BushTask {
public async exec() {
const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all(
PriceCommand.urls.map(({ url }) =>
- got
- .get(url)
- .json()
+ fetch(url)
+ .then((p) => (p.ok ? p.json() : undefined))
.catch(() => undefined)
)
)) as [Bazaar?, LowestBIN?, LowestBIN?, AuctionAverages?];