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 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();
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"
};