44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
require('dotenv').config(); // Require and run dotenv
|
|
|
|
// Import modules
|
|
const Discord = require('discord.js');
|
|
const Enmap = require('enmap');
|
|
|
|
const client = new Discord.Client({partials: ["REACTION", "MESSAGE"]});
|
|
|
|
// Use log75 for logging
|
|
const { default: Log75, LogLevel } = require('log75')
|
|
const logger = new Log75(process.env.NODE_ENV == 'production' ? LogLevel.Standard : LogLevel.Debug, true);
|
|
|
|
module.exports = {
|
|
client: client,
|
|
logger: logger
|
|
}
|
|
|
|
// Execute modules in util folder in order
|
|
async function runModules() {
|
|
for (const file of ['commandLoader', 'login', 'eventHandler', 'karma', 'carloscounter']) {
|
|
logger.debug(`Running module ${file}`);
|
|
await require(`./util/${file}`).run();
|
|
}
|
|
}
|
|
runModules();
|
|
|
|
|
|
// Destroy client when SIGINT
|
|
process.on('SIGINT', async () => {
|
|
process.stdin.resume(); // Don't exit immediately
|
|
|
|
console.log('');
|
|
logger.info('SIGINT received.');
|
|
|
|
try {
|
|
await client.destroy();
|
|
} catch(e) {
|
|
logger.warn('Failed to destroy client');
|
|
process.exit();
|
|
}
|
|
|
|
logger.done('Logged out client, exiting.');
|
|
process.exit();
|
|
}); |