diff options
Diffstat (limited to 'src/tasks')
-rw-r--r-- | src/tasks/updateCache.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index cfadeb5..1a17aef 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -1,6 +1,7 @@ import { BushClient } from '../lib/extensions/discord-akairo/BushClient'; import { BushTask } from '../lib/extensions/discord-akairo/BushTask'; import { Global } from '../lib/models/Global'; +import { Guild } from '../lib/models/Guild'; import config from './../config/options'; export class UpdateCacheTask extends BushTask { @@ -12,19 +13,19 @@ export class UpdateCacheTask extends BushTask { } public async exec(): Promise<void> { await UpdateCacheTask.updateGlobalCache(this.client); - // await UpdateCacheTask.updateGuildCache(this.client); + await UpdateCacheTask.updateGuildCache(this.client); await this.client.logger.verbose(`UpdateCache`, `Updated cache.`); } public static async init(client: BushClient): Promise<void> { await UpdateCacheTask.updateGlobalCache(client); - // await UpdateCacheTask.updateGuildCache(client); + await UpdateCacheTask.updateGuildCache(client); } private static async updateGlobalCache(client: BushClient): Promise<void> { const environment = config.environment; const row = - (await Global.findByPk(environment)) || + ((await Global.findByPk(environment)) || (await Global.create({ environment, superUsers: [], @@ -32,14 +33,17 @@ export class UpdateCacheTask extends BushTask { blacklistedGuilds: [], blacklistedUsers: [], disabledCommands: [] - })); + }))).toJSON() for (const option in row) { - if (client.cache[option]) client.cache[option] = row[option]; + if (Object.keys(client.cache.global).includes(option)) client.cache.global[option] = row[option]; } } private static async updateGuildCache(client: BushClient): Promise<void> { - // client.db.query(`SELECT * FROM 'Guilds'`) + const rows = await Guild.findAll(); + for (const row of rows){ + client.cache.guilds.set(row.id, row.toJSON() as Guild) + } } } |