mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-06 10:11:27 +03:00
mjs -> cjs
This commit is contained in:
78
src/index.js
Normal file
78
src/index.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Discord Tickets
|
||||
* Copyright (C) 2022 Isaac Saunders
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @name discord-tickets/bot
|
||||
* @description An open-source Discord bot for ticket management
|
||||
* @copyright 2022 Isaac Saunders
|
||||
* @license GNU-GPLv3
|
||||
*/
|
||||
|
||||
|
||||
const fs = require('fs');
|
||||
const semver = require('semver');
|
||||
const { colours } = require('leeks.js');
|
||||
const logger = require('./lib/logger');
|
||||
const banner = require('./lib/banner');
|
||||
const YAML = require('yaml');
|
||||
const Client = require('./client');
|
||||
|
||||
process.env.NODE_ENV ??= 'development'; // make sure NODE_ENV is set
|
||||
require('dotenv').config(); // load env file
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||
|
||||
// check node version
|
||||
if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
|
||||
console.log('\x07' + colours.redBright(`Error: Your current Node.js version, ${process.versions.node}, does not meet the requirement "${pkg.engines.node}".`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (process.env.DB_ENCRYPTION_KEY === undefined) {
|
||||
console.log('\x07' + colours.redBright('Error: The "DB_ENCRYPTION_KEY" environment variable is not set.\nRun "npm run keygen" to generate a key, or set it to "false" to disable encryption (not recommended).'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.env.CONFIG_PATH ??= './user/config.yml'; // set default config file path
|
||||
|
||||
if (!fs.existsSync(process.env.CONFIG_PATH)) {
|
||||
const examplePath = './user/example.config.yml';
|
||||
if (!fs.existsSync(examplePath)) {
|
||||
console.log('\x07' + colours.redBright('The config file does not exist, and the example file is missing so cannot be copied from.'));
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Creating config file...');
|
||||
fs.copyFileSync(examplePath, process.env.CONFIG_PATH);
|
||||
console.log(`Copied config to ${process.env.CONFIG_PATH}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(banner(pkg.version)); // print big title
|
||||
|
||||
const config = YAML.parse(fs.readFileSync(process.env.CONFIG_PATH, 'utf8'));
|
||||
const log = logger(config);
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
log.notice(`Discord Tickets v${pkg.version} on Node.js v${process.versions.node} (${process.platform})`);
|
||||
log.notice('An error was not caught');
|
||||
if (error instanceof Error) log.warn(`Uncaught ${error.name}`);
|
||||
log.error(error);
|
||||
});
|
||||
|
||||
const client = new Client();
|
||||
client.config = config;
|
||||
client.log = log;
|
||||
client.login();
|
Reference in New Issue
Block a user