ramirez/src/index.js

52 lines
1.9 KiB
JavaScript
Raw Normal View History

const path = require('path');
2017-09-19 13:23:55 -04:00
const config = require('./config');
2017-02-09 21:56:36 -05:00
const utils = require('./utils');
const main = require('./main');
const knex = require('./knex');
const legacyMigrator = require('./legacy/legacyMigrator');
2017-02-09 21:56:36 -05:00
2017-09-19 13:23:55 -04:00
// Force crash on unhandled rejections (use something like forever/pm2 to restart)
process.on('unhandledRejection', err => {
if (err instanceof utils.BotError || (err && err.code)) {
// We ignore stack traces for BotErrors (the message has enough info) and network errors from Eris (their stack traces are unreadably long)
2017-09-19 13:23:55 -04:00
console.error(`Error: ${err.message}`);
} else {
console.error(err);
}
process.exit(1);
});
(async function() {
// Make sure the database is up to date
await knex.migrate.latest();
2017-07-23 20:27:21 -04:00
// Migrate legacy data if we need to
if (await legacyMigrator.shouldMigrate()) {
console.log('=== MIGRATING LEGACY DATA ===');
console.log('Do not close the bot!');
console.log('');
2017-09-19 13:23:55 -04:00
await legacyMigrator.migrate();
2017-07-23 20:27:21 -04:00
const relativeDbDir = (path.isAbsolute(config.dbDir) ? config.dbDir : path.resolve(process.cwd(), config.dbDir));
const relativeLogDir = (path.isAbsolute(config.logDir) ? config.logDir : path.resolve(process.cwd(), config.logDir));
2017-07-23 20:27:21 -04:00
console.log('');
console.log('=== LEGACY DATA MIGRATION FINISHED ===');
console.log('');
console.log('IMPORTANT: After the bot starts, please verify that all logs, threads, blocked users, and snippets are still working correctly.');
2017-12-31 19:16:05 -05:00
console.log('Once you\'ve done that, feel free to delete the following legacy files/directories:');
console.log('');
console.log('FILE: ' + path.resolve(relativeDbDir, 'threads.json'));
console.log('FILE: ' + path.resolve(relativeDbDir, 'blocked.json'));
console.log('FILE: ' + path.resolve(relativeDbDir, 'snippets.json'));
console.log('DIRECTORY: ' + relativeLogDir);
console.log('');
console.log('Starting the bot...');
2017-07-23 20:27:21 -04:00
}
// Start the bot
2017-12-31 19:16:05 -05:00
main.start();
})();