2020-08-18 04:58:36 +00:00
|
|
|
// Check that the runtime is up to date
|
|
|
|
if (Number(process.version.slice(1).split(".")[0]) < 12) {
|
|
|
|
console.error(`Node v12.0.0 or higher is required. You have Node ${process.version}. Please update Node on your system.`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load up the discord.js library
|
|
|
|
const { Collection, Client } = require("discord.js");
|
2020-08-18 08:29:46 +00:00
|
|
|
const sentry = require("@sentry/node");
|
2020-08-18 04:58:36 +00:00
|
|
|
|
|
|
|
// Our custom client, extends the standard Discord client with things we will need.
|
|
|
|
class Custom extends Client {
|
|
|
|
constructor (options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.config = require("../config.json");
|
2020-08-18 11:28:28 +00:00
|
|
|
this.dev = true;
|
|
|
|
if (this.config.devmode === false) {
|
|
|
|
this.dev = false;
|
|
|
|
//sentry.init({ dsn: this.config.keys.sentry });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.path = __dirname;
|
2020-10-06 07:50:07 +00:00
|
|
|
this.package = require("../package.json")
|
2020-08-18 04:58:36 +00:00
|
|
|
this.logger = require("./util/logger");
|
2020-10-08 02:05:14 +00:00
|
|
|
this.functions = new (require("./util/functions"))(this);
|
2020-10-06 07:50:07 +00:00
|
|
|
this.db = new (require("./util/redis"))(this);
|
2020-08-18 11:28:28 +00:00
|
|
|
|
2020-08-18 04:58:36 +00:00
|
|
|
// Create collections to store loaded commands and aliases in
|
|
|
|
this.commands = new Collection();
|
|
|
|
this.aliases = new Collection();
|
|
|
|
|
|
|
|
const handlers = require("./util/handlers");
|
|
|
|
this.commandHandler = new handlers.CommandHandler(this);
|
|
|
|
this.eventHandler = new handlers.EventHandler(this);
|
|
|
|
|
|
|
|
// Basically just an async shortcut to using a setTimeout. Nothing fancy!
|
|
|
|
this.wait = require("util").promisify(setTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 11:28:28 +00:00
|
|
|
// Initialization function, so we can use async/await
|
|
|
|
const init = async () => {
|
|
|
|
// Initialize client
|
|
|
|
const client = new Custom();
|
2020-08-18 04:58:36 +00:00
|
|
|
|
2020-10-06 07:50:07 +00:00
|
|
|
client.logger.info(`Initializing Woomy v${client.package.version}`)
|
|
|
|
|
2020-08-19 08:21:23 +00:00
|
|
|
// Load all commands/events
|
2020-08-18 11:28:28 +00:00
|
|
|
await client.commandHandler.loadAll();
|
|
|
|
await client.eventHandler.loadAll();
|
|
|
|
|
2020-08-19 08:21:23 +00:00
|
|
|
// Connect to Redis database
|
|
|
|
await client.db.init();
|
|
|
|
|
2020-08-18 11:28:28 +00:00
|
|
|
if (client.dev === true) {
|
|
|
|
client.logger.warn("Development mode is on. Some features (such as Sentry) are disabled.");
|
|
|
|
client.login(client.config.devtoken);
|
|
|
|
} else {
|
|
|
|
client.login(client.config.token);
|
|
|
|
}
|
2020-08-18 04:58:36 +00:00
|
|
|
}
|
2020-08-18 11:28:28 +00:00
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
// Catch exceptions/rejections and give more details on the stack trace
|
|
|
|
process.on("uncaughtException", (err) => {
|
|
|
|
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, "g"), "./")
|
|
|
|
console.error("Uncaught Exception: ", errorMsg)
|
|
|
|
process.exit(1)
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on("unhandledRejection", err => {
|
|
|
|
console.error("Uncaught Promise Error: ", err)
|
|
|
|
});
|
|
|
|
|