Added a dogfact and carfact command, while also improving index.js so it actually gives reasons for it shitting itself.

This commit is contained in:
MrTech999 2020-03-09 22:20:45 +00:00
parent cfc3f40dcb
commit 8b2c262c37
3 changed files with 127 additions and 5 deletions

View file

@ -6,11 +6,40 @@ const chalk = require('chalk');
const DBL = require("dblapi.js"); const DBL = require("dblapi.js");
const client = new Discord.Client(); const client = new Discord.Client();
try {
client.config = require('./config'); client.config = require('./config');
} catch (err) {
console.log('Unable to load config.js \n', err);
process.exit();
}
try{
client.version = require('./version.json'); 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'); 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); require("./src/modules/functions")(client);
} catch (err) {
console.log('Unable to load the functions. \n', err);
process.exit();
}
try{
client.logger.setClient(client); client.logger.setClient(client);
} catch (err) {
console.log('Unable to initiate the logger. \n', err);
process.exit(1);
}
if(process.env['USER'] != 'container') { if(process.env['USER'] != 'container') {
client.devmode = true; client.devmode = true;
@ -19,12 +48,37 @@ if(process.env['USER'] != 'container') {
const dblapi = new DBL(client.config.dblkey, client); const dblapi = new DBL(client.config.dblkey, client);
} }
try{
client.commands = new Enmap(); client.commands = new Enmap();
client.aliases = new Enmap(); } catch (err) {
client.settings = new Enmap({name: 'settings'}); console.log('Failed to create the commands database. \n', err);
client.blacklist = new Enmap({name: 'blacklist'}); 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 () => { const init = async () => {
try{
const cmdFiles = await readdir("./src/commands/"); const cmdFiles = await readdir("./src/commands/");
client.logger.info(`Loading ${cmdFiles.length} commands.`); client.logger.info(`Loading ${cmdFiles.length} commands.`);
cmdFiles.forEach(file => { cmdFiles.forEach(file => {
@ -36,7 +90,12 @@ const init = async () => {
console.log(response); console.log(response);
}; };
}); });
} catch (err) {
console.log('Unable to load Woomys commands. \n', err);
process.exit(1);
}
try{
const evtFiles = await readdir("./src/events/"); const evtFiles = await readdir("./src/events/");
client.logger.info(`Loading ${evtFiles.length} events.`); client.logger.info(`Loading ${evtFiles.length} events.`);
evtFiles.forEach(file => { evtFiles.forEach(file => {
@ -47,18 +106,35 @@ const init = async () => {
const event = require(`./src/events/${file}`); const event = require(`./src/events/${file}`);
client.on(eventName, event.bind(null, client)); client.on(eventName, event.bind(null, client));
}); });
} catch (err) {
console.log('Unable to load Woomy events. \n', err);
process.exit();
}
try{
client.levelCache = {}; client.levelCache = {};
for (let i = 0; i < client.config.permLevels.length; i++) { for (let i = 0; i < client.config.permLevels.length; i++) {
const thisLevel = client.config.permLevels[i]; const thisLevel = client.config.permLevels[i];
client.levelCache[thisLevel.name] = thisLevel.level; client.levelCache[thisLevel.name] = thisLevel.level;
}; };
} catch (err) {
console.log('Unable to enable the levelCache. \n', err);
process.exit();
}
try{
if(client.devmode === true) { if(client.devmode === true) {
client.login(client.config.devtoken); client.login(client.config.devtoken);
} else { } else {
client.login(client.config.token); client.login(client.config.token);
}; };
} catch (err) {
console.log('Unable to login to Discord. \n', err);
process.exit(1);
}
}; };
init(); init();
} catch (err) {
console.log('Failed to initiate Woomy. \n', err);
process.exit(1);
}

23
src/commands/catfact.js Normal file
View file

@ -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"
};

23
src/commands/dogfact.js Normal file
View file

@ -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"
};