2020-03-09 01:11:33 +00:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const { promisify } = require('util');
|
|
|
|
const readdir = promisify(require('fs').readdir);
|
|
|
|
const Enmap = require('enmap');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const DBL = require("dblapi.js");
|
|
|
|
const client = new Discord.Client();
|
|
|
|
|
2020-03-09 22:20:45 +00:00
|
|
|
try {
|
2020-03-09 01:43:21 +00:00
|
|
|
client.config = require('./config');
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Could not load config.js: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:43:21 +00:00
|
|
|
client.version = require('./version.json');
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Could not load version.json: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:43:21 +00:00
|
|
|
client.logger = require('./src/modules/Logger');
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Could not load Logger.js: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:43:21 +00:00
|
|
|
require("./src/modules/functions")(client);
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Could not load functions.js: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:11:33 +00:00
|
|
|
client.logger.setClient(client);
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Logger failed to initialize: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-03-09 01:11:33 +00:00
|
|
|
|
|
|
|
if(process.env['USER'] != 'container') {
|
2020-03-09 01:40:11 +00:00
|
|
|
client.devmode = true;
|
|
|
|
} else {
|
|
|
|
client.devmode = false;
|
2020-03-10 09:35:16 +00:00
|
|
|
if(client.config.dblkey.length == 0) {
|
|
|
|
const dblapi = new DBL(client.config.dblkey, client);
|
|
|
|
}
|
2020-03-09 01:40:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:20:45 +00:00
|
|
|
try{
|
2020-03-09 01:40:11 +00:00
|
|
|
client.commands = new Enmap();
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Failed to create the commands database: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:40:11 +00:00
|
|
|
client.aliases = new Enmap();
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Failed to create the aliases database: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:43:21 +00:00
|
|
|
client.settings = new Enmap({name: 'settings'});
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Failed to initialize the settings database: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
try{
|
2020-03-09 01:43:21 +00:00
|
|
|
client.blacklist = new Enmap({name: 'blacklist'});
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Failed to initialize the blacklist database: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-03-09 01:11:33 +00:00
|
|
|
|
2020-03-09 22:20:45 +00:00
|
|
|
try{
|
2020-03-09 01:11:33 +00:00
|
|
|
const init = async () => {
|
2020-03-09 01:43:21 +00:00
|
|
|
const cmdFiles = await readdir("./src/commands/");
|
2020-03-09 01:11:33 +00:00
|
|
|
client.logger.info(`Loading ${cmdFiles.length} commands.`);
|
|
|
|
cmdFiles.forEach(file => {
|
|
|
|
if (!file.endsWith(".js")) {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
const response = client.loadCommand(file);
|
|
|
|
if (response) {
|
|
|
|
console.log(response);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-03-09 01:43:21 +00:00
|
|
|
const evtFiles = await readdir("./src/events/");
|
2020-03-09 01:11:33 +00:00
|
|
|
client.logger.info(`Loading ${evtFiles.length} events.`);
|
|
|
|
evtFiles.forEach(file => {
|
|
|
|
if (!file.endsWith(".js")) {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
const eventName = file.split(".")[0];
|
2020-03-09 01:43:21 +00:00
|
|
|
const event = require(`./src/events/${file}`);
|
2020-03-09 01:11:33 +00:00
|
|
|
client.on(eventName, event.bind(null, client));
|
|
|
|
});
|
|
|
|
|
2020-03-09 22:20:45 +00:00
|
|
|
try{
|
2020-03-09 01:11:33 +00:00
|
|
|
client.levelCache = {};
|
|
|
|
for (let i = 0; i < client.config.permLevels.length; i++) {
|
|
|
|
const thisLevel = client.config.permLevels[i];
|
|
|
|
client.levelCache[thisLevel.name] = thisLevel.level;
|
|
|
|
};
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Level cache failed to initialize: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
2020-03-09 01:11:33 +00:00
|
|
|
|
2020-03-09 22:20:45 +00:00
|
|
|
try{
|
2020-03-09 01:11:33 +00:00
|
|
|
if(client.devmode === true) {
|
|
|
|
client.login(client.config.devtoken);
|
|
|
|
} else {
|
|
|
|
client.login(client.config.token);
|
|
|
|
};
|
2020-03-09 22:20:45 +00:00
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Could not login to Discord: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-03-09 01:11:33 +00:00
|
|
|
};
|
2020-03-09 22:20:45 +00:00
|
|
|
init();
|
|
|
|
} catch (err) {
|
2020-03-10 09:35:16 +00:00
|
|
|
console.log('Initialization failed: \n', err);
|
2020-03-09 22:20:45 +00:00
|
|
|
process.exit(1);
|
2020-03-09 22:58:41 +00:00
|
|
|
}
|