obama-bot/index.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-28 16:38:23 +00:00
require('dotenv').config(); // Require and run dotenv
// Import modules
2020-07-17 16:08:27 +00:00
const Discord = require('discord.js');
const Enmap = require('enmap');
2020-11-28 16:38:23 +00:00
const client = new Discord.Client({partials: ["REACTION", "MESSAGE"]});
2020-07-17 16:08:27 +00:00
2020-11-28 16:38:23 +00:00
// Use log75 for logging
const { default: Log75, LogLevel } = require('log75')
const logger = new Log75(process.env.NODE_ENV == 'production' ? LogLevel.Standard : LogLevel.Debug, true);
2020-07-17 16:08:27 +00:00
2020-11-28 16:38:23 +00:00
module.exports = {
client: client,
logger: logger
2020-07-17 16:08:27 +00:00
}
2020-11-28 16:38:23 +00:00
// Execute modules in util folder in order
async function runModules() {
2021-01-07 01:08:52 +00:00
for (const file of ['commandLoader', 'login', 'eventHandler', 'karma', 'carloscounter']) {
2020-11-28 16:38:23 +00:00
logger.debug(`Running module ${file}`);
await require(`./util/${file}`).run();
2020-07-17 16:08:27 +00:00
}
2020-11-28 16:38:23 +00:00
}
2020-12-27 13:31:47 +00:00
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');
2020-12-27 13:42:22 +00:00
process.exit();
2020-12-27 13:31:47 +00:00
}
logger.done('Logged out client, exiting.');
process.exit();
});