cache anime and chars

master
Kit Kasune 3 years ago
parent 350c8ea5ff
commit 8fa25eb201
  1. 4
      bot.js
  2. 10
      util/cache.js
  3. 12
      util/cache/anime.js
  4. 11
      util/cache/char.js

@ -35,7 +35,9 @@ client.misc = {
monitEnabled: [], monitEnabled: [],
inVC: [], inVC: [],
VCG: {}, VCG: {},
activeVC: [] activeVC: [],
chars: new Discord.Collection(),
anime: new Discord.Collection()
}, },
loggers: {}, loggers: {},
rl: readline.createInterface({input: process.stdin, output: process.stdout}) rl: readline.createInterface({input: process.stdin, output: process.stdout})

@ -28,4 +28,14 @@ module.exports = async (client) => {
await require('./cache/monit')(client); await require('./cache/monit')(client);
ora_moCache.stop(); ora_moCache.clear(); ora_moCache.stop(); ora_moCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${Object.keys(client.misc.cache.monit).length}`)} ${chalk.blueBright(`guilds with Monitors enabled.`)}`); console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${Object.keys(client.misc.cache.monit).length}`)} ${chalk.blueBright(`guilds with Monitors enabled.`)}`);
let ora_anCache = ora("Caching Animes...").start();
await require('./cache/anime')(client);
ora_anCache.stop(); ora_anCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.anime.size / 2}`)} ${chalk.blueBright(`animes into lookup registry.`)}`);
let ora_chCache = ora("Caching Characters...").start();
await require('./cache/char')(client);
ora_chCache.stop(); ora_chCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.chars.size}`)} ${chalk.blueBright(`characters into lookup registry.`)}`);
}; };

@ -0,0 +1,12 @@
const Discord = require('discord.js');
const AniData = require('../../models/anime');
module.exports = async client => {
client.misc.cache.anime = new Discord.Collection();
for await (const ani of AniData.find()) {
client.misc.cache.anime.set(ani.japname, ani.id);
client.misc.cache.anime.set(ani.name, ani.id);
}
}

11
util/cache/char.js vendored

@ -0,0 +1,11 @@
const Discord = require('discord.js');
const CharData = require('../../models/char');
module.exports = async client => {
client.misc.cache.chars = new Discord.Collection();
for await (const char of CharData.find()) {
client.misc.cache.chars.set(char.name, char.id);
}
}
Loading…
Cancel
Save