woomy/index.js

113 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-03-26 04:31:32 +00:00
if (Number(process.version.slice(1).split(".")[0]) < 12) {
throw new Error("Node 12.0.0 or higher is required. Please update Node on your system.");
};
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');
2021-03-18 01:10:09 +00:00
const sentry = require('@sentry/node');
2020-03-09 01:11:33 +00:00
const chalk = require('chalk');
const client = new Discord.Client({ ws: { intents: [
'GUILDS',
'GUILD_MEMBERS',
'GUILD_EMOJIS',
'GUILD_VOICE_STATES',
'GUILD_MESSAGES',
2021-03-01 01:58:11 +00:00
'DIRECT_MESSAGES',
'GUILD_MESSAGE_REACTIONS',
]}});
2020-03-09 01:11:33 +00:00
try {
2020-03-26 04:31:32 +00:00
client.config = require('./config');
} catch (err) {
2020-03-26 04:31:32 +00:00
console.log('Failed to load config.js:', err);
process.exit();
};
2020-03-26 07:26:22 +00:00
try{
2020-03-26 04:31:32 +00:00
client.version = require('./version.json');
} catch (err) {
2020-03-26 04:31:32 +00:00
console.log('Failed to load version.json:', err);
process.exit();
};
2020-03-26 07:26:22 +00:00
try{
2020-03-26 04:31:32 +00:00
client.logger = require('./src/modules/Logger');
} catch (err) {
2020-03-26 04:31:32 +00:00
console.log('Failed to load Logger.js:', err);
process.exit();
};
2020-03-26 07:26:22 +00:00
2020-03-26 04:31:32 +00:00
client.logger.setClient(client);
try{
2020-03-26 04:31:32 +00:00
require("./src/modules/functions")(client);
} catch (err) {
2020-03-26 04:31:32 +00:00
console.log('Failed to load functions.js:', err);
process.exit();
};
2020-03-09 01:11:33 +00:00
2020-03-26 07:26:22 +00:00
if(client.config.devmodeEnabled == true && process.env['USER'] != 'container') {
2020-03-09 01:40:11 +00:00
client.devmode = true;
} else {
client.devmode = false;
2020-03-26 04:31:32 +00:00
if(client.config.dblkey.length > 0) {
const DBL = require("dblapi.js");
2020-03-10 09:35:16 +00:00
const dblapi = new DBL(client.config.dblkey, client);
2020-03-26 04:31:32 +00:00
};
2021-03-18 01:10:09 +00:00
if(client.config.sentry.length > 0) {
sentry.init({ dsn: client.config.sentry });
};
2020-03-26 04:31:32 +00:00
};
2020-03-09 01:40:11 +00:00
client.commands = new Enmap();
client.aliases = new Enmap();
client.settings = new Enmap({name: 'settings'});
2020-03-09 01:11:33 +00:00
const init = async () => {
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);
};
});
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];
const event = require(`./src/events/${file}`);
2020-03-09 01:11:33 +00:00
client.on(eventName, event.bind(null, client));
});
client.levelCache = {};
for (let i = 0; i < client.config.permLevels.length; i++) {
const thisLevel = client.config.permLevels[i];
client.levelCache[thisLevel.name] = thisLevel.level;
};
if(client.devmode === true) {
client.login(client.config.devtoken);
} else {
client.login(client.config.token);
};
};
2020-03-26 04:31:32 +00:00
2021-02-23 20:58:40 +00:00
process.on('SIGINT', function(){
client.logger.info("Disconnecting...")
client.destroy();
process.exit();
});
init();