From 8b2c262c37128797d71fdf13de07e30df41c3b60 Mon Sep 17 00:00:00 2001 From: MrTech999 <48654513+MrTech999@users.noreply.github.com> Date: Mon, 9 Mar 2020 22:20:45 +0000 Subject: [PATCH] Added a dogfact and carfact command, while also improving index.js so it actually gives reasons for it shitting itself. --- index.js | 86 ++++++++++++++++++++++++++++++++++++++--- src/commands/catfact.js | 23 +++++++++++ src/commands/dogfact.js | 23 +++++++++++ 3 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 src/commands/catfact.js create mode 100644 src/commands/dogfact.js diff --git a/index.js b/index.js index 9b559ff..a6db338 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,40 @@ const chalk = require('chalk'); const DBL = require("dblapi.js"); const client = new Discord.Client(); +try { client.config = require('./config'); +} catch (err) { + console.log('Unable to load config.js \n', err); + process.exit(); +} + +try{ client.version = require('./version.json'); +} catch (err) { + console.log('Unable to load the version file. \n', err); + process.exit(); +} + +try{ client.logger = require('./src/modules/Logger'); +} catch (err) { + console.log('Unable to load the logger. \n', err); + process.exit(); +} + +try{ require("./src/modules/functions")(client); +} catch (err) { + console.log('Unable to load the functions. \n', err); + process.exit(); +} + +try{ client.logger.setClient(client); +} catch (err) { + console.log('Unable to initiate the logger. \n', err); + process.exit(1); +} if(process.env['USER'] != 'container') { client.devmode = true; @@ -19,12 +48,37 @@ if(process.env['USER'] != 'container') { const dblapi = new DBL(client.config.dblkey, client); } +try{ client.commands = new Enmap(); -client.aliases = new Enmap(); -client.settings = new Enmap({name: 'settings'}); -client.blacklist = new Enmap({name: 'blacklist'}); +} catch (err) { + console.log('Failed to create the commands database. \n', err); + process.exit(); +} +try{ +client.aliases = new Enmap(); +} catch (err) { + console.log('Unable to create the aliases database. \n', err); + process.exit(); +} + +try{ +client.settings = new Enmap({name: 'settings'}); +} catch (err) { + console.log('Unable to make the settings database. \n', err); + process.exit(); +} + +try{ +client.blacklist = new Enmap({name: 'blacklist'}); +} catch (err) { + console.log('Unable to create the blacklist database. \n', err); + process.exit(1); +} + +try{ const init = async () => { + try{ const cmdFiles = await readdir("./src/commands/"); client.logger.info(`Loading ${cmdFiles.length} commands.`); cmdFiles.forEach(file => { @@ -36,7 +90,12 @@ const init = async () => { console.log(response); }; }); +} catch (err) { + console.log('Unable to load Woomys commands. \n', err); + process.exit(1); +} + try{ const evtFiles = await readdir("./src/events/"); client.logger.info(`Loading ${evtFiles.length} events.`); evtFiles.forEach(file => { @@ -47,18 +106,35 @@ const init = async () => { const event = require(`./src/events/${file}`); client.on(eventName, event.bind(null, client)); }); +} catch (err) { + console.log('Unable to load Woomy events. \n', err); + process.exit(); +} + try{ client.levelCache = {}; for (let i = 0; i < client.config.permLevels.length; i++) { const thisLevel = client.config.permLevels[i]; client.levelCache[thisLevel.name] = thisLevel.level; }; +} catch (err) { + console.log('Unable to enable the levelCache. \n', err); + process.exit(); +} + try{ if(client.devmode === true) { client.login(client.config.devtoken); } else { client.login(client.config.token); }; +} catch (err) { + console.log('Unable to login to Discord. \n', err); + process.exit(1); +} }; - -init(); \ No newline at end of file +init(); +} catch (err) { + console.log('Failed to initiate Woomy. \n', err); + process.exit(1); +} \ No newline at end of file diff --git a/src/commands/catfact.js b/src/commands/catfact.js new file mode 100644 index 0000000..7505a1b --- /dev/null +++ b/src/commands/catfact.js @@ -0,0 +1,23 @@ +const request = require("request"); + +exports.run = async (bot, message, args) => { + request({ uri: "https://catfact.ninja/facts", json: true }, (error, response, body) => { + if (error) throw new Error(error); + message.channel.send(`**Did you know?**\n ${body.facts[0]}`); + }); +}; + +exports.conf = { + enabled: true, + guildOnly: false, + aliases: ["kittenfact"], + permLevel: "User", + requiredPerms: [] + }; + + exports.help = { + name: "catfact", + category: "User", + description: "Sends a fun fact about a cat.", + usage: "catfact/kittenfact" + }; diff --git a/src/commands/dogfact.js b/src/commands/dogfact.js new file mode 100644 index 0000000..ae0ef94 --- /dev/null +++ b/src/commands/dogfact.js @@ -0,0 +1,23 @@ +const request = require("request"); + +exports.run = async (bot, message, args) => { + request({ uri: "https://dog-api.kinduff.com/api/facts", json: true }, (error, response, body) => { + if (error) throw new Error(error); + message.channel.send(`**Did you know?**\n ${body.facts[0]}`); + }); +}; + +exports.conf = { + enabled: true, + guildOnly: false, + aliases: ["pupfact"], + permLevel: "User", + requiredPerms: [] + }; + + exports.help = { + name: "dogfact", + category: "User", + description: "Sends a fun fact about a doggo.", + usage: "dogfact/pupfact" + };