Commit 005e0606 authored by insert's avatar insert

Added chalk, prettier console messages now =)

parent 446b5b76
const fs = require('fs');
const child_process = require('child_process');
const path = require('path');
const chalk = require('chalk');
var modules = {};
var commands = {};
......@@ -49,10 +50,11 @@ let index = path => {
};
core.reload = () => {
console.log("[INFO] Reloading...");
commands = {};
modules = {};
commands = {};
let mods = fs.readdirSync('./core');
console.log(chalk`{blue [INFO]} Now reloading!`);
console.log(chalk`{blue [INFO]} {gray About to load ${mods.length} modules!}`);
let modules_missing = [];
mods.forEach(mod => {
if (mod == 'index.js' || mod == 'node_modules' || mod == 'package-lock.json') return;
......@@ -68,7 +70,7 @@ core.reload = () => {
nrc(a);
let m = require(a);
let n = cmd.split('.').shift();
if (commands[n]) console.log('[WARN] A conflict has been detected, command ' + n + ' already exists! And ' + mod + ' is now overwriting it!');
if (commands[n]) console.error(chalk`{yellow [WARN]} A conflict has been detected {yellow ${n}} already exists! And {red ${mod}} is now overwriting it!`);
let util = require('util');
if (!i.commands[n]) i.commands[n] = {};
commands[n] = Object.assign({
......@@ -78,25 +80,27 @@ core.reload = () => {
}, i.commands[n]);
});
} catch (e) {
console.error('[WARN] Failed to load module, ' + mod + ' with error: ' + e);
console.error(chalk`{red [ERR]} Failed to load module, {red ${mod}}, with error: {red ${e}}`);
if ((''+e).includes('Cannot find module')) {
let module = /Error: Cannot find module '(.+?)'/.exec((''+e))[1];
console.log('[WARN] Node module missing, ' + module + '!');
console.error(chalk`{red [ERR]} {gray Node module ${module} is missing!}`);
modules_missing.push(module);
}
}
});
console.log(chalk`{green [SUCCESS]} Finished reloading, {green ${Object.keys(modules).length} modules active} and {green ${Object.keys(commands).length} commands available}!`);
if (modules_missing.length == 0) return;
console.log("[INFO] Several modules are missing, installing them in 5 seconds! Exit if you do not want to proceed.");
console.log(chalk`{blue [INFO]} Several modules are missing, installing them in 5 seconds!`);
setTimeout(() => {
console.log(chalk`{blue [INFO]} {gray Installing ${modules_missing} node modules!}`);
modules_missing.forEach(module => {
try {
let res = child_process.execSync('npm i ' + module, {
cwd: path.resolve(__dirname)
});
console.log(res);
console.log(chalk`{green [SUCCESS]} Installed {magenta ${module}}!`);
} catch (e) {
console.log('[WARN] Failed to install node module: ' + module + '!');
console.error(chalk`{red [ERR]} {gray Failed to install node module ${module}, you should try installing it manually!}`);
}
});
core.reload();
......
const discord = require('discord.js');
const chalk = require('chalk');
const client = new discord.Client();
const services = require('./services');
const libs = require('./libs');
const fs = require('fs');
console.log(chalk`
####### ## ##
## ## ##
## ########
## ##
## ##
{blue Fully modular Discord bot.}
{green Now starting...}
`.replace(/#/g, chalk.bgMagenta(' ')));
global.components = {discord, client, services, libs};
global.needs = (component) => {
if (Object.keys(components).indexOf(component) < 0) throw new Error('Not a valid component!');
......@@ -13,7 +27,7 @@ global.needs = (component) => {
const core = require('./core');
client.on('ready', () => {
console.log(`Connected to Discord as ${client.user.tag}`);
console.log(chalk`\n{bgBlue Connected to Discord as ${client.user.tag} }\n`);
});
client.on('message', msg => {
......
......@@ -15,6 +15,14 @@
"json-schema-traverse": "^0.3.0"
}
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"requires": {
"color-convert": "^1.9.0"
}
},
"asn1": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz",
......@@ -72,11 +80,34 @@
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
},
"chalk": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz",
"integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==",
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"co": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ="
},
"color-convert": {
"version": "1.9.2",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.2.tgz",
"integrity": "sha512-3NUJZdhMhcdPn8vJ9v2UQJoH0qqoGUkYTgFEPZaPjEtwmmKUfNV46zZmgB2M5M4DCEQHMaCfWHCxiBflLm04Tg==",
"requires": {
"color-name": "1.1.1"
}
},
"color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.1.tgz",
"integrity": "sha1-SxQVMEz1ACjqgWQ2Q72C6gWANok="
},
"combined-stream": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz",
......@@ -137,6 +168,11 @@
"jsbn": "~0.1.0"
}
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"extend": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
......@@ -194,6 +230,11 @@
"har-schema": "^2.0.0"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"http-signature": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
......@@ -406,6 +447,14 @@
}
}
},
"supports-color": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
"integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
"requires": {
"has-flag": "^3.0.0"
}
},
"tough-cookie": {
"version": "2.3.4",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.4.tgz",
......
......@@ -18,6 +18,7 @@
"modular"
],
"dependencies": {
"chalk": "^2.4.1",
"discord.js": "^11.3.2",
"node-opus": "^0.3.0",
"request": "^2.87.0"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment