diff options
Diffstat (limited to 'src/tasks/updateCache.ts')
-rw-r--r-- | src/tasks/updateCache.ts | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index 8f9cc5d..9084c1c 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -1,4 +1,4 @@ -import { Global, Guild, type BushClient } from '#lib'; +import { Global, Guild, Shared, type BushClient } from '#lib'; import { BushTask } from '../lib/extensions/discord-akairo/BushTask.js'; import config from './../config/options.js'; @@ -11,23 +11,39 @@ export default class UpdateCacheTask extends BushTask { } public override async exec() { - await UpdateCacheTask.updateGlobalCache(client); - await UpdateCacheTask.#updateGuildCache(client); + await Promise.all([ + UpdateCacheTask.#updateGlobalCache(client), + UpdateCacheTask.#updateSharedCache(client), + UpdateCacheTask.#updateGuildCache(client) + ]); void client.logger.verbose(`UpdateCache`, `Updated cache.`); } public static async init(client: BushClient) { - await UpdateCacheTask.updateGlobalCache(client); - await UpdateCacheTask.#updateGuildCache(client); + await Promise.all([ + UpdateCacheTask.#updateGlobalCache(client), + UpdateCacheTask.#updateSharedCache(client), + UpdateCacheTask.#updateGuildCache(client) + ]); } - private static async updateGlobalCache(client: BushClient) { + static async #updateGlobalCache(client: BushClient) { 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: BushClient) { + 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]; } } |