startup is now blazing fast bc of "multithreading"

master
Kit Kasune 3 years ago
parent ad047ffa19
commit 3959a4765c
  1. 4
      bot.js
  2. 1
      events/ready.js
  3. 87
      util/cache.js
  4. 38
      util/cache/anime.js
  5. 23
      util/cache/ar.js
  6. 37
      util/cache/bl.js
  7. 36
      util/cache/char.js
  8. 19
      util/cache/chest.js
  9. 20
      util/cache/lr.js
  10. 25
      util/cache/lxp.js
  11. 34
      util/cache/monit.js

@ -15,6 +15,7 @@ const {TagFilter} = require('./util/tagfilter');
const flags = Discord.Intents.FLAGS;
let fl = []; Object.keys(flags).forEach(flag => fl.push(flags[flag]));
let client = new Discord.Client({intents: fl, partials: ["CHANNEL", "REACTION", "MESSAGE"]});
let botReadyResolver;
client.misc = {
savers: ['497598953206841375', '480535078150340609', '468903364533420074'],
@ -69,6 +70,7 @@ client.misc = {
gradients: false,
spinners: false
},
botFinished: new Promise(r => {botReadyResolver = r;}),
fullyReady: false
};
@ -159,6 +161,8 @@ async function init() {
client.guildconfig.logs = new Map();
botReadyResolver(0);
await require('./util/wait')(5000);
if (!client.misc.readied) {client.misc.forcedReady = true; await require('./events/ready')(client);}
}

@ -17,6 +17,7 @@ let prefix = 'n?';
module.exports = async client => {
if (client.misc.readied) {return;}
client.misc.readied = true;
await client.misc.botFinished;
const config = client.config;

@ -1,46 +1,49 @@
const ora = require('ora');
const gs = require('gradient-string');
const spinnies = require('dreidels');
const chalk = require('chalk');
module.exports = async (client) => {
console.log('');
let ora_arCache = ora("Caching ARs...").start();
await require('./cache/ar')(client);
ora_arCache.stop(); ora_arCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.ar.size}`)} ${chalk.blueBright(`guilds with auto responses.`)}`);
let ora_blCache = ora("Caching Blacklists...").start();
await require('./cache/bl')(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.`)}`);
let ora_lrCache = ora("Caching Level Roles...").start();
await require('./cache/lr')(client);
ora_lrCache.stop(); ora_lrCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.hasLevelRoles.length}`)} ${chalk.blueBright(`guilds with Level Roles enabled.`)}`);
let ora_moCache = ora("Caching Monitors...").start();
await require('./cache/monit')(client);
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.`)}`);
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.animeNum}`)} ${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.charsNum}`)} ${chalk.blueBright(`characters into lookup registry.`)} ${chalk.gray(`(${client.misc.cache.chars.size} // NN)`)}`);
let ora_ctCache = ora("Caching Chests...").start();
await require('./cache/chest')(client);
ora_ctCache.stop(); ora_ctCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.chests.enabled.length}`)} ${chalk.blueBright("guilds that spawn chests.")}`);
return new Promise(async resolve => {
const loaders = [];
const spin = new spinnies();
console.log('');
let arCache = spin.add("ar", {text: "Caching ARs..."});
loaders.push(require('./cache/ar')(client, arCache));
let blCache = spin.add("bl", {text: "Caching Guild Blacklists..."});
let bluCache = spin.add("blu", {text: "Caching User Blacklists..."});
loaders.push(require('./cache/bl')(client, blCache, bluCache));
let lxpCache = spin.add("xp", {text: "Caching Local XPs..."});
loaders.push(require('./cache/lxp')(client, lxpCache));
let lrCache = spin.add("lr", {text: "Caching Level Roles..."});
loaders.push(require('./cache/lr')(client, lrCache));
let moCache = spin.add("m", {text: "Caching Monitors..."});
loaders.push(require('./cache/monit')(client, moCache));
let anCache = spin.add("a", {text: "Caching Animes..."});
loaders.push(require('./cache/anime')(client, anCache));
let chCache = spin.add("ch", {text: "Caching Characters..."});
loaders.push(require('./cache/char')(client, chCache));
let ctCache = spin.add("cht", {text: "Caching Chests..."});
loaders.push(require('./cache/chest')(client, ctCache));
await Promise.all(loaders);
/*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`)}`);
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.enabled.length}`)} ${chalk.blueBright(`guilds with XP enabled.`)}`);
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.hasLevelRoles.length}`)} ${chalk.blueBright(`guilds with Level Roles enabled.`)}`);
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(`${client.misc.cache.animeNum}`)} ${chalk.blueBright(`animes into lookup registry.`)}`);
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.charsNum}`)} ${chalk.blueBright(`characters into lookup registry.`)} ${chalk.gray(`(${client.misc.cache.chars.size} // NN)`)}`);
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.chests.enabled.length}`)} ${chalk.blueBright("guilds that spawn chests.")}`);*/
resolve(0);
});
};

@ -1,21 +1,31 @@
const Discord = require('discord.js');
const chalk = require('chalk');
const AniData = require('../../models/anime');
module.exports = async client => {
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;
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
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, ani.id);
client.misc.cache.anime.set(ani.name, 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);
client.misc.cache.animeLove.set(ani.id, ani.watchers);
client.misc.cache.animeNum++;
for await (const ani of AniData.find()) {
if (ani.queued !== true) {
client.misc.cache.anime.set(ani.japname, ani.id);
client.misc.cache.anime.set(ani.name, 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);
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++;
}
}
}
spinner.status('non-spinnable');
resolve(0);
});
}

23
util/cache/ar.js vendored

@ -1,11 +1,20 @@
const AR = require('../../models/ar');
const chalk = require('chalk');
module.exports = async client => {
client.misc.cache.ar = new Map();
client.misc.cache.arIgnore = new Map();
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
client.misc.cache.ar = new Map();
client.misc.cache.arIgnore = new Map();
let amount = 0;
for await (const ar of AR.find()) {
client.misc.cache.ar.set(ar.gid, ar.triggers);
if (ar.ignoreChs.length) {client.misc.cache.arIgnore.set(ar.gid, ar.ignoreChs);}
}
for await (const ar of AR.find()) {
client.misc.cache.ar.set(ar.gid, ar.triggers);
if (ar.ignoreChs.length) {client.misc.cache.arIgnore.set(ar.gid, ar.ignoreChs);}
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guilds with auto responses.`)}`});
amount++;
}
spinner.status('non-spinnable');
resolve(0);
});
};

37
util/cache/bl.js vendored

@ -1,17 +1,32 @@
const GuildData = require('../../models/guild');
const UserData = require('../../models/user');
const chalk = require('chalk');
module.exports = async (client) => {
client.misc.cache.bl = {
guild: [],
user: []
};
module.exports = async (client, spinner, spinner2) => {
return new Promise(async resolve => {
client.misc.cache.bl = {
guild: [],
user: []
};
let amount = 0;
let amount2 = 0;
for await (const guild of GuildData.find()) {
if (guild.blacklisted) {client.misc.cache.bl.guild.push(guild.gid);}
}
for await (const guild of GuildData.find()) {
if (guild.blacklisted) {client.misc.cache.bl.guild.push(guild.gid); amount++;}
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guild blacklists.`)}`});
}
for await (const user of UserData.find()) {
if (user.blackisted) {client.misc.cache.bl.user.push(user.uid);}
}
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guild blacklists.`)}`});
spinner.status('non-spinnable');
for await (const user of UserData.find()) {
if (user.blackisted) {client.misc.cache.bl.user.push(user.uid); amount2++;}
spinner2.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount2}`)} ${chalk.blueBright(`user blacklists.`)}`});
}
spinner2.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount2}`)} ${chalk.blueBright(`user blacklists.`)}`});
spinner2.status('non-spinnable');
resolve(0);
});
};

36
util/cache/char.js vendored

@ -1,20 +1,30 @@
const Discord = require('discord.js');
const chalk = require('chalk');
const CharData = require('../../models/char');
module.exports = async client => {
client.misc.cache.chars = new Discord.Collection();
client.misc.cache.charsID = new Discord.Collection();
client.misc.cache.charsLove = new Discord.Collection();
client.misc.cache.charsNum = 0;
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
client.misc.cache.chars = new Discord.Collection();
client.misc.cache.charsID = new Discord.Collection();
client.misc.cache.charsLove = new Discord.Collection();
client.misc.cache.charsNum = 0;
let amount = 0;
for await (const char of CharData.find()) {
if (char.queued !== true) {
client.misc.cache.chars.set(char.name, char.id);
char.nicknames.forEach(nn => client.misc.cache.chars.set(nn, char.id));
client.misc.cache.charsID.set(char.id, char.name);
client.misc.cache.charsNum++;
client.misc.cache.charsLove.set(char.id, char.loved);
for await (const char of CharData.find()) {
if (char.queued !== true) {
client.misc.cache.chars.set(char.name, char.id);
char.nicknames.forEach(nn => client.misc.cache.chars.set(nn, char.id));
client.misc.cache.charsID.set(char.id, char.name);
client.misc.cache.charsNum++;
client.misc.cache.charsLove.set(char.id, char.loved);
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`characters into lookup registry.`)} ${chalk.gray(`(${client.misc.cache.chars.size} // NN)`)}`});
amount++;
}
}
}
spinner.status('non-spinnable');
resolve(0);
});
}

@ -1,9 +1,18 @@
const Chests = require('../../models/chests');
const chalk = require('chalk');
module.exports = async client => {
client.misc.cache.chests.enabled = [];
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
client.misc.cache.chests.enabled = [];
let amount = 0;
for await (const chest of Chests.find()) {
client.misc.cache.chests.enabled.push(chest.gid);
}
for await (const chest of Chests.find()) {
client.misc.cache.chests.enabled.push(chest.gid);
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guilds that spawn chests.`)}`});
amount++;
}
spinner.status('non-spinnable');
resolve(0);
});
};

20
util/cache/lr.js vendored

@ -1,9 +1,19 @@
const LR = require('../../models/levelroles');
const chalk = require('chalk');
module.exports = async client => {
client.misc.cache.lxp.hasLevelRoles = [];
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
client.misc.cache.lxp.hasLevelRoles = [];
let amount = 0;
for await (const lr of LR.find()) {
client.misc.cache.lxp.hasLevelRoles.push(lr.gid);
}
for await (const lr of LR.find()) {
client.misc.cache.lxp.hasLevelRoles.push(lr.gid);
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guilds with Level Roles enabled.`)}`});
amount++;
}
spinner.status('non-spinnable');
resolve(0);
});
};

25
util/cache/lxp.js vendored

@ -1,12 +1,21 @@
const LXP = require('../../models/localxp');
const chalk = require('chalk');
module.exports = async client => {
client.misc.cache.lxp.enabled = [];
client.misc.cache.lxp.disabledChannels = new Map();
client.misc.cache.chests.enabled = new Map();
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
client.misc.cache.lxp.enabled = [];
client.misc.cache.lxp.disabledChannels = new Map();
client.misc.cache.chests.enabled = new Map();
let amount = 0;
for await (const xp of LXP.find()) {
client.misc.cache.lxp.enabled.push(xp.gid);
if (xp.noGains && xp.noGains.length) {client.misc.cache.lxp.disabledChannels.set(xp.gid, xp.noGains);}
}
for await (const xp of LXP.find()) {
client.misc.cache.lxp.enabled.push(xp.gid);
if (xp.noGains && xp.noGains.length) {client.misc.cache.lxp.disabledChannels.set(xp.gid, xp.noGains);}
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guilds with XP enabled.`)}`});
amount++;
}
spinner.status('non-spinnable');
resolve(0);
});
};

@ -1,15 +1,25 @@
const Monitor = require('../../models/monitor');
const chalk = require('chalk');
module.exports = async client => {
client.misc.cache.monit = {};
client.misc.cache.monitEnabled = [];
for await (const tm of Monitor.find()) {
client.misc.cache.monit[tm.gid] = {
messages: tm.messages,
voice: tm.voice,
expiry: new Date()
};
client.misc.cache.monitEnabled.push(tm.gid);
}
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
client.misc.cache.monit = {};
client.misc.cache.monitEnabled = [];
let amount = 0;
for await (const tm of Monitor.find()) {
client.misc.cache.monit[tm.gid] = {
messages: tm.messages,
voice: tm.voice,
expiry: new Date()
};
client.misc.cache.monitEnabled.push(tm.gid);
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guilds with Monitors enabled.`)}`});
amount++;
}
spinner.status('non-spinnable');
resolve(0);
});
}
Loading…
Cancel
Save