You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.7 KiB
35 lines
1.7 KiB
const Discord = require('discord.js');
|
|
const chalk = require('chalk');
|
|
|
|
const AniData = require('../../models/anime');
|
|
|
|
module.exports = async (client, spinner) => {
|
|
return new Promise(async resolve => {
|
|
const st = new Date().getTime();
|
|
|
|
client.misc.cache.anime = new Discord.Collection();
|
|
client.misc.cache.animeID = new Discord.Collection();
|
|
client.misc.cache.animeLove = new Discord.Collection();
|
|
client.misc.cache.animeNum = 0;
|
|
let amount = 0;
|
|
|
|
for await (const ani of AniData.find()) {
|
|
if (ani.queued !== true) {
|
|
client.misc.cache.anime.set(ani.japname.normalize("NFD").replace(/[\u0300-\u036f]/g, ""), ani.id);
|
|
client.misc.cache.anime.set(ani.name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""), ani.id);
|
|
if (ani.altNames) {ani.altNames.forEach(altName => client.misc.cache.anime.set(altName, ani.id));}
|
|
client.misc.cache.animeID.set(ani.id, ani.name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""));
|
|
client.misc.cache.animeLove.set(ani.id, ani.watchers);
|
|
client.misc.cache.animeNum++;
|
|
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`animes into lookup registry.`)}`});
|
|
amount++;
|
|
}
|
|
}
|
|
|
|
const cacheTime = new Date().getTime() - st;
|
|
spinner.update({text: `${spinner.options.text.slice(0, 19).trim()} ${chalk.gray(`${cacheTime}ms >>`.padStart(8, '0').padStart(7, '0'))} ${spinner.options.text.slice(19).trim()}`});
|
|
spinner.status('non-spinnable');
|
|
|
|
resolve(0);
|
|
});
|
|
} |