From 3ab7728ae6a4a36ac2aadf390baa9bad2ea5b4ca Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 12 Feb 2021 15:14:43 -0700 Subject: [PATCH] reload spinnybois --- commands/reload.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/commands/reload.js b/commands/reload.js index 03fa52f..bb0f3a5 100644 --- a/commands/reload.js +++ b/commands/reload.js @@ -1,6 +1,8 @@ const Discord = require('discord.js'); const fs = require('fs'); const chalk = require('chalk'); +const ora = require('ora'); + const UserData = require("../models/user"); module.exports = { @@ -22,19 +24,22 @@ module.exports = { const tu = await UserData.findOne({uid: message.author.id}); if (!tu || !tu.developer) {return message.channel.send("You must be a Natsuki developer in order to do this!");} - var commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); + let commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); console.log(`\n${chalk.yellow('[WARN]')} >> ${chalk.gray('Reload:')} ${chalk.white('All commands and events are being reloaded!')}`); console.log(`${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`Developer ${message.author.username} initiated the system refresh`)}\n`); + let cmdspinner = ora(chalk.blue('Loading Commands')).start(); ['commands', 'aliases'].forEach(x => client[x] = new Discord.Collection()); for (let commandf of commands) { if (Object.keys(require.cache).includes(require.resolve(`./${commandf}`))) {delete require.cache[require.resolve(`./${commandf}`)];} - var command = require(`./${commandf}`); + let command = require(`./${commandf}`); client.commands.set(command.name, command); if (command.aliases) {command.aliases.forEach(a => client.aliases.set(a, command.name));} } + cmdspinner.stop(); cmdspinner.clear(); console.log(`${chalk.gray('[LOG]')} >> ${chalk.blue('Loaded all Commands')}`); + let eventspinner = ora(chalk.blue('Loading Events')).start(); let eventFilter = fs.readdirSync('./events/').filter(x => x.endsWith('.js')); for (let file of eventFilter) { let evtName = file.split('.')[0]; @@ -43,16 +48,19 @@ module.exports = { client.removeAllListeners(evtName); client.on(evtName, evt.bind(null, client)); } + eventspinner.stop(); eventspinner.clear(); console.log(`${chalk.gray('[LOG]')} >> ${chalk.blue('Loaded all Events')}`); - var responses = fs.readdirSync('./responses').filter(file => file.endsWith('.js')); + let rspspinner = ora(chalk.blue('Loading Commands')).start(); + let responses = fs.readdirSync('./responses').filter(file => file.endsWith('.js')); client.responses.triggers = []; for (let responsef of responses) { if (Object.keys(require.cache).includes(require.resolve(`../responses/${responsef}`))) {delete require.cache[require.resolve(`../responses/${responsef}`)];} - var response = require(`../responses/${responsef}`); + let response = require(`../responses/${responsef}`); client.responses.triggers.push([response.name, response.condition]); client.responses.commands.set(response.name, response); } + rspspinner.stop(); rspspinner.clear(); console.log(`${chalk.gray('[LOG]')} >> ${chalk.blue('Loaded all Responses')}`); console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`Client refresh successful`)}\n`);