2020-08-13 01:02:33 +03:00
|
|
|
/**
|
2021-02-15 20:34:59 +02:00
|
|
|
* DiscordTickets
|
|
|
|
* Copyright (C) 2021 Isaac Saunders
|
2021-02-16 02:02:44 +02:00
|
|
|
*
|
2021-02-15 20:34:59 +02:00
|
|
|
* 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.
|
2021-02-16 02:02:44 +02:00
|
|
|
*
|
2021-02-15 20:34:59 +02:00
|
|
|
* 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.
|
2021-02-16 02:02:44 +02:00
|
|
|
*
|
2021-02-15 20:34:59 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2021-02-16 02:02:44 +02:00
|
|
|
*
|
2021-02-15 20:34:59 +02:00
|
|
|
* @name @eartharoid/discordtickets
|
|
|
|
* @description An open-source & self-hosted Discord bot for ticket management.
|
|
|
|
* @copyright 2021 Isaac Saunders
|
|
|
|
* @license GNU-GPLv3
|
2021-02-16 02:02:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
const node_version = Number(process.versions.node.split('.')[0]);
|
|
|
|
if (node_version < 14) 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 { path } = require('./utils/fs');
|
|
|
|
if (!fs.existsSync(path('./.env'))) return console.log('Please make a copy of \'example.env\' called \'.env\'');
|
2021-02-16 16:48:04 +02:00
|
|
|
if (!fs.existsSync(path('./user/config.js'))) return console.log('Please make a copy of \'user/example.config.js\' called \'user/config.js\'');
|
2021-02-16 02:02:44 +02:00
|
|
|
|
2021-02-16 16:48:04 +02:00
|
|
|
require('dotenv').config({
|
|
|
|
path: path('./.env')
|
|
|
|
});
|
2021-02-16 02:02:44 +02:00
|
|
|
|
|
|
|
const config = require('../user/config');
|
|
|
|
|
|
|
|
const Logger = require('leekslazylogger');
|
|
|
|
const log = new Logger({
|
|
|
|
name: 'DiscordTickets by eartharoid',
|
|
|
|
debug: config.debug,
|
|
|
|
logToFile: config.logs.enabled,
|
|
|
|
keepFor: config.logs.keep_for
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
log.report = error => {
|
|
|
|
let report = [
|
|
|
|
'<< Issue report >>',
|
|
|
|
'Please include this information if you ask for help about the following error!',
|
|
|
|
`Support server: ${terminalLink('go.eartharoid.me/discord', 'https://go.eartharoid.me/discord')}`,
|
2021-02-16 14:28:43 +02:00
|
|
|
`Node.JS version: ${process.versions.node}`,
|
2021-02-16 02:02:44 +02:00
|
|
|
`Bot version: ${version}`,
|
|
|
|
`Platform: ${process.platform}`
|
|
|
|
];
|
|
|
|
log.warn(report.join('\n'));
|
|
|
|
if (error) log.error(error);
|
|
|
|
};
|
|
|
|
|
2021-02-16 16:48:04 +02:00
|
|
|
const terminalLink = require('terminal-link');
|
|
|
|
const I18n = require('@eartharoid/i18n');
|
|
|
|
|
2021-02-16 02:02:44 +02:00
|
|
|
const { Client } = require('discord.js');
|
|
|
|
class Bot extends Client {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
autoReconnect: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.assign(this, {
|
|
|
|
config,
|
2021-02-16 16:48:04 +02:00
|
|
|
db: require('./database')(log),
|
2021-02-16 02:02:44 +02:00
|
|
|
log,
|
2021-02-16 16:48:04 +02:00
|
|
|
i18n: new I18n(path('./src/locales'), 'en-GB')
|
2021-02-16 02:02:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.log.info('Connecting to Discord API');
|
|
|
|
|
|
|
|
this.login();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new Bot();
|
|
|
|
|
|
|
|
process.on('unhandledRejection', error => {
|
|
|
|
log.report();
|
|
|
|
log.warn('An error was not caught');
|
|
|
|
if (error instanceof Error) log.warn(`Uncaught ${error.name}: ${error}`);
|
|
|
|
log.error(error);
|
|
|
|
});
|
|
|
|
|