aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/updateCache.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/tasks/updateCache.ts')
-rw-r--r--src/tasks/updateCache.ts17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts
index cfadeb5..404173b 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,18 +13,18 @@ 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 =
+ const row = (
(await Global.findByPk(environment)) ||
(await Global.create({
environment,
@@ -32,14 +33,18 @@ 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);
+ }
}
}