woomy-v2/bot/index.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-10-17 01:16:03 +00:00
// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license.
2020-08-18 04:58:36 +00:00
2020-10-17 01:16:03 +00:00
const { Client, Collection } = require('discord.js');
const { CommandHandler, EventHandler } = require('./util/handlers');
const Functions = require('./util/functions');
const Database = require('./util/database');
const logger = require('./util/logger');
2020-10-17 05:00:41 +00:00
const sentry = require('@sentry/node'); // eslint-disable-line no-unused-vars
2020-10-17 01:16:03 +00:00
const config = require('../config.json');
const pkg = require('../package.json');
2020-08-18 04:58:36 +00:00
2020-10-17 01:16:03 +00:00
class WoomyClient extends Client {
constructor () {
super();
2020-08-18 04:58:36 +00:00
2020-10-17 01:16:03 +00:00
// Important information our bot needs to access
this.config = config;
this.path = __dirname;
this.version = pkg.version;
2020-08-18 11:28:28 +00:00
2020-10-17 01:16:03 +00:00
// dev mode, disables some features if enabled
this.dev = false;
if (this.config.devmode === true) {
this.dev = true;
// sentry.init({ dsn: this.config.keys.sentry });
2020-10-17 05:00:41 +00:00
}
2020-08-18 04:58:36 +00:00
2020-10-17 01:16:03 +00:00
// Essential modules
this.logger = logger;
this.functions = new Functions(this);
this.db = new Database(this);
2020-08-18 04:58:36 +00:00
2020-10-17 01:16:03 +00:00
// collections, to store commands, their aliases and their cooldown timers in
this.commands = new Collection();
this.aliases = new Collection();
this.cooldowns = new Collection();
2020-08-18 04:58:36 +00:00
2020-10-17 01:16:03 +00:00
// Handlers, to load commands and events
this.commandHandler = new CommandHandler(this);
this.eventHandler = new EventHandler(this);
2020-10-17 05:00:41 +00:00
}
}
2020-10-06 07:50:07 +00:00
2020-10-17 05:17:02 +00:00
async function init () {
const client = new WoomyClient({ ws: {}});
2020-08-18 11:28:28 +00:00
2020-10-17 01:16:03 +00:00
client.logger.info(`Initializing Woomy v${client.version}`);
2020-08-18 11:28:28 +00:00
2020-10-17 01:16:03 +00:00
await client.commandHandler.loadAll();
await client.eventHandler.loadAll();
2020-08-18 11:28:28 +00:00
2020-10-17 01:16:03 +00:00
if (client.dev === true) {
client.logger.warn('Development mode is enabled. Some features (such as Sentry) have been disabled.');
client.login(client.config.devtoken);
} else {
client.login(client.config.token);
2020-10-17 05:00:41 +00:00
}
}
2020-10-17 01:16:03 +00:00
init();
2020-08-18 11:28:28 +00:00
2020-10-17 01:16:03 +00:00
process.on('uncaughtException', (err) => {
2020-10-17 05:00:41 +00:00
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, 'g'), './');
console.error('Uncaught Exception: ', errorMsg);
process.exit(1);
2020-08-18 11:28:28 +00:00
});
2020-10-17 01:16:03 +00:00
process.on('unhandledRejection', err => {
2020-10-17 05:00:41 +00:00
console.error('Uncaught Promise Error: ', err);
2020-10-17 01:16:03 +00:00
});