From dbbcf9a05185c2a1901bdf8b250239ccc96dca10 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 20 Feb 2021 20:40:23 -0700 Subject: [PATCH] Local XP cache --- bot.js | 4 ++++ util/cache.js | 5 +++++ util/cache/lxp.js | 9 +++++++++ 3 files changed, 18 insertions(+) create mode 100644 util/cache/lxp.js diff --git a/bot.js b/bot.js index ee77cf5..d55bcbb 100644 --- a/bot.js +++ b/bot.js @@ -17,6 +17,10 @@ client.misc = { bl: { guild: [], user: [] + }, + lxp: { + enabled: [], + xp: {} } } }; diff --git a/util/cache.js b/util/cache.js index 5aba566..527e735 100644 --- a/util/cache.js +++ b/util/cache.js @@ -13,4 +13,9 @@ module.exports = async (client) => { ora_blCache.stop(); ora_blCache.clear(); console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.bl.guild.length}`)} ${chalk.blueBright(`guild blacklists`)}`); console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.bl.user.length}`)} ${chalk.blueBright(`user blacklists`)}`); + + let ora_lxpCache = ora("Caching Local XPs...").start(); + await require('./cache/lxp')(client); + ora_lxpCache.stop(); ora_lxpCache.clear(); + console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.enabled.length}`)} ${chalk.blueBright(`guilds with XP enabled.`)}`); }; \ No newline at end of file diff --git a/util/cache/lxp.js b/util/cache/lxp.js new file mode 100644 index 0000000..3c9e1b9 --- /dev/null +++ b/util/cache/lxp.js @@ -0,0 +1,9 @@ +const LXP = require('../../models/localxp'); + +module.exports = async client => { + client.misc.cache.lxp.enabled = []; + + for await (const xp of LXP.find()) { + client.misc.cache.lxp.enabled.push(xp.gid); + } +}; \ No newline at end of file