code cleanup + new db

This commit is contained in:
Emily 2020-10-17 12:16:03 +11:00
parent ffc5592055
commit f479782a39

View file

@ -1,71 +1,70 @@
// Check that the runtime is up to date // Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license.
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 { Client, Collection } = require('discord.js');
const { Collection, Client } = require("discord.js"); const { CommandHandler, EventHandler } = require('./util/handlers');
const sentry = require("@sentry/node"); const Functions = require('./util/functions');
const Database = require('./util/database');
const logger = require('./util/logger');
const sentry = require('@sentry/node');
const config = require('../config.json');
const pkg = require('../package.json');
// Our custom client, extends the standard Discord client with things we will need. class WoomyClient extends Client {
class Custom extends Client { constructor () {
constructor (options) { super();
super(options);
this.config = require("../config.json"); // Important information our bot needs to access
this.dev = true; this.config = config;
if (this.config.devmode === false) { this.path = __dirname;
this.dev = false; this.version = pkg.version;
//sentry.init({ dsn: this.config.keys.sentry });
}
this.path = __dirname; // dev mode, disables some features if enabled
this.package = require("../package.json") this.dev = false;
this.logger = require("./util/logger"); if (this.config.devmode === true) {
this.functions = new (require("./util/functions"))(this); this.dev = true;
this.db = new (require("./util/redis"))(this); // sentry.init({ dsn: this.config.keys.sentry });
};
// Create collections to store loaded commands and aliases in
this.commands = new Collection();
this.aliases = new Collection();
this.cooldown = new Collection();
const handlers = require("./util/handlers"); // Essential modules
this.commandHandler = new handlers.CommandHandler(this); this.logger = logger;
this.eventHandler = new handlers.EventHandler(this); this.functions = new Functions(this);
} this.db = new Database(this);
}
// Initialization function, so we can use async/await // collections, to store commands, their aliases and their cooldown timers in
const init = async () => { this.commands = new Collection();
// Initialize client this.aliases = new Collection();
const client = new Custom(); this.cooldowns = new Collection();
client.logger.info(`Initializing Woomy v${client.package.version}`) // Handlers, to load commands and events
this.commandHandler = new CommandHandler(this);
this.eventHandler = new EventHandler(this);
};
};
// Load all commands/events async function init() {
await client.commandHandler.loadAll(); const client = new WoomyClient();
await client.eventHandler.loadAll();
if (client.dev === true) { client.logger.info(`Initializing Woomy v${client.version}`);
client.logger.warn("Development mode is on. Some features (such as Sentry) are disabled.");
client.login(client.config.devtoken); await client.commandHandler.loadAll();
} else { await client.eventHandler.loadAll();
client.login(client.config.token);
} 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);
};
};
init(); init();
// Catch exceptions/rejections and give more details on the stack trace process.on('uncaughtException', (err) => {
process.on("uncaughtException", (err) => { const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, 'g'), './');
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, "g"), "./") console.error('Uncaught Exception: ', errorMsg);
console.error("Uncaught Exception: ", errorMsg) process.exit(1);
process.exit(1)
});
process.on("unhandledRejection", err => {
console.error("Uncaught Promise Error: ", err)
}); });
process.on('unhandledRejection', err => {
console.error('Uncaught Promise Error: ', err);
});