diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-08 12:25:35 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-08 12:25:35 -0500 |
| commit | 0e160ae77477f0986a02746e84158329299f438f (patch) | |
| tree | 55a70950bae700bbd77ff693aecd1b2cbf0777cf /src/tasks | |
| parent | 42eab3390f7e2fcdc020eb1e3d602a46c9f34273 (diff) | |
| download | tanzanite-0e160ae77477f0986a02746e84158329299f438f.tar.gz tanzanite-0e160ae77477f0986a02746e84158329299f438f.tar.bz2 tanzanite-0e160ae77477f0986a02746e84158329299f438f.zip | |
add shared db
Diffstat (limited to 'src/tasks')
| -rw-r--r-- | src/tasks/updateCache.ts | 28 | ||||
| -rw-r--r-- | src/tasks/updateSuperUsers.ts | 28 |
2 files changed, 22 insertions, 34 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]; } } diff --git a/src/tasks/updateSuperUsers.ts b/src/tasks/updateSuperUsers.ts deleted file mode 100644 index 8dcd00e..0000000 --- a/src/tasks/updateSuperUsers.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { BushTask, Global } from '#lib'; - -export default class UpdateSuperUsersTask extends BushTask { - public constructor() { - super('updateSuperUsers', { - delay: 10_000, // 10 seconds - runOnStart: true - }); - } - - public override async exec() { - const superUsers = client.guilds.cache - .get(client.config.supportGuild.id) - ?.members.cache.filter( - (member) => (member.roles.cache.has('865954009280938056') || member.permissions.has('ADMINISTRATOR')) && !member.user.bot - ) - .map((member) => member.id); - - const row = - (await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment })); - - row.superUsers = superUsers ?? row.superUsers; - client.cache.global.superUsers = superUsers ?? row.superUsers; - await row.save(); - - void client.logger.verbose(`updateSuperUsers`, 'Updated superusers.'); - } -} |
