Improve startup checking

Now attempts to copy example config & env automatically instead of just complaining about it
This commit is contained in:
Isaac 2021-02-17 20:51:03 +00:00
parent 7d5eec51b9
commit 8b661f0462
No known key found for this signature in database
GPG Key ID: 279D1F53391CED07

View File

@ -25,14 +25,33 @@ const node_version = Number(process.versions.node.split('.')[0]);
if (node_version < 14) if (node_version < 14)
return console.log(`Error: DiscordTickets does not work on Node v${node_version}. Please upgrade to v14 or above.`); return console.log(`Error: DiscordTickets does not work on Node v${node_version}. Please upgrade to v14 or above.`);
const { version } = require('../package.json');
const fs = require('fs'); const fs = require('fs');
const { path } = require('./utils/fs'); const { path } = require('./utils/fs');
if (!fs.existsSync(path('./.env'))) const ENV_PATH = path('./.env');
return console.log('Please make a copy of \'example.env\' called \'.env\''); const EXAMPLE_ENV_PATH = path('./example.env');
if (!fs.existsSync(path('./user/config.js'))) if (!fs.existsSync(ENV_PATH )) {
return console.log('Please make a copy of \'user/example.config.js\' called \'user/config.js\''); if (!fs.existsSync(EXAMPLE_ENV_PATH)) {
console.log('Error: \'.env\' not found, and unable to create it due to \'example.env\' being missing');
return process.exit();
}
console.log('Copying \'example.env\' to \'.env\'');
fs.copyFileSync(EXAMPLE_ENV_PATH, ENV_PATH);
console.log('Please set your bot\'s token in your \'.env\' file');
process.exit();
}
const CONFIG_PATH = path('./user/config.js');
const EXAMPLE_CONFIG_PATH = path('./user/example.config.js');
if (!fs.existsSync(CONFIG_PATH)) {
if (!fs.existsSync(EXAMPLE_CONFIG_PATH)) {
console.log('Error: \'user/config.js\' not found, and unable to create it due to \'user/example.config.js\' being missing');
return process.exit();
}
console.log('Copying \'user/example.config.js\' to \'user/config.js\'');
fs.copyFileSync(EXAMPLE_CONFIG_PATH, CONFIG_PATH);
}
require('dotenv').config({ require('dotenv').config({
path: path('./.env') path: path('./.env')
@ -85,6 +104,7 @@ class Bot extends Client {
intents: Intents.NON_PRIVILEGED, intents: Intents.NON_PRIVILEGED,
} }
}); });
/** The global bot configuration */ /** The global bot configuration */
this.config= config; this.config= config;
/** A sequelize instance */ /** A sequelize instance */
@ -118,6 +138,7 @@ class Bot extends Client {
new Bot(); new Bot();
const { version } = require('../package.json');
process.on('unhandledRejection', error => { process.on('unhandledRejection', error => {
log.notice('PLEASE INCLUDE THIS INFORMATION:'); log.notice('PLEASE INCLUDE THIS INFORMATION:');
log.warn(`Discord Tickets v${version}, Node v${process.versions.node} on ${process.platform}`); log.warn(`Discord Tickets v${version}, Node v${process.versions.node} on ${process.platform}`);