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]);
|
2021-02-17 15:24:33 +02:00
|
|
|
if (node_version < 14)
|
|
|
|
return console.log(`Error: DiscordTickets does not work on Node v${node_version}. Please upgrade to v14 or above.`);
|
2021-02-16 02:02:44 +02:00
|
|
|
|
2021-02-17 15:24:33 +02:00
|
|
|
const { version } = require('../package.json');
|
2021-02-16 02:02:44 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const { path } = require('./utils/fs');
|
2021-02-17 15:24:33 +02:00
|
|
|
|
|
|
|
if (!fs.existsSync(path('./.env')))
|
|
|
|
return console.log('Please make a copy of \'example.env\' called \'.env\'');
|
|
|
|
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');
|
|
|
|
|
2021-02-17 00:34:20 +02:00
|
|
|
require('./banner')();
|
|
|
|
|
2021-02-16 02:02:44 +02:00
|
|
|
const Logger = require('leekslazylogger');
|
|
|
|
const log = new Logger({
|
|
|
|
name: 'DiscordTickets by eartharoid',
|
|
|
|
debug: config.debug,
|
|
|
|
logToFile: config.logs.enabled,
|
2021-02-17 00:34:20 +02:00
|
|
|
keepFor: config.logs.keep_for,
|
|
|
|
custom: {
|
|
|
|
listeners: {
|
|
|
|
title: 'info',
|
|
|
|
prefix: 'listeners'
|
|
|
|
},
|
|
|
|
commands: {
|
|
|
|
title: 'info',
|
|
|
|
prefix: 'commands'
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
title: 'info',
|
|
|
|
prefix: 'plugins'
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 02:02:44 +02:00
|
|
|
});
|
|
|
|
|
2021-02-16 16:48:04 +02:00
|
|
|
const I18n = require('@eartharoid/i18n');
|
2021-02-17 00:34:20 +02:00
|
|
|
const { CommandManager } = require('./modules/commands');
|
2021-02-17 22:17:35 +02:00
|
|
|
const { PluginManager } = require('./modules/plugins');
|
2021-02-17 00:34:20 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
Client,
|
|
|
|
Intents
|
|
|
|
} = require('discord.js');
|
2021-02-16 16:48:04 +02:00
|
|
|
|
2021-02-16 02:02:44 +02:00
|
|
|
class Bot extends Client {
|
|
|
|
constructor() {
|
|
|
|
super({
|
2021-02-17 00:34:20 +02:00
|
|
|
partials: [
|
|
|
|
'MESSAGE',
|
|
|
|
'CHANNEL',
|
|
|
|
'REACTION'
|
|
|
|
],
|
|
|
|
ws: {
|
|
|
|
intents: Intents.NON_PRIVILEGED,
|
|
|
|
}
|
2021-02-16 02:02:44 +02:00
|
|
|
});
|
2021-02-17 22:17:35 +02:00
|
|
|
/** The global bot configuration */
|
|
|
|
this.config= config;
|
|
|
|
/** A sequelize instance */
|
|
|
|
this.db = require('./database')(log), // this.db.models.Ticket...
|
|
|
|
/** A leekslazylogger instance */
|
|
|
|
this.log = log;
|
|
|
|
/** An @eartharoid/i18n instance */
|
|
|
|
this.i18n = new I18n(path('./src/locales'), 'en-GB');
|
|
|
|
|
|
|
|
// set the max listeners for each event to the number in the config
|
2021-02-17 15:24:33 +02:00
|
|
|
this.setMaxListeners(this.config.max_listeners);
|
|
|
|
|
2021-02-17 22:17:35 +02:00
|
|
|
// check for updates
|
2021-02-17 15:24:33 +02:00
|
|
|
require('./updater')(this);
|
2021-02-17 22:17:35 +02:00
|
|
|
// load internal listeners
|
2021-02-17 15:24:33 +02:00
|
|
|
require('./modules/listeners')(this);
|
2021-02-17 22:17:35 +02:00
|
|
|
|
|
|
|
/** The command manager, used by internal and plugin commands */
|
|
|
|
this.commands = new CommandManager(this);
|
|
|
|
/** The plugin manager */
|
|
|
|
this.plugins = new PluginManager(this);
|
|
|
|
// load plugins
|
|
|
|
this.plugins.load();
|
2021-02-16 02:02:44 +02:00
|
|
|
|
2021-02-17 15:24:33 +02:00
|
|
|
this.log.info('Connecting to Discord API...');
|
2021-02-17 01:35:31 +02:00
|
|
|
|
2021-02-17 15:24:33 +02:00
|
|
|
this.login();
|
2021-02-16 02:02:44 +02:00
|
|
|
}
|
2021-02-17 00:34:20 +02:00
|
|
|
|
2021-02-16 02:02:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
new Bot();
|
|
|
|
|
|
|
|
process.on('unhandledRejection', error => {
|
2021-02-17 01:35:31 +02:00
|
|
|
log.notice('PLEASE INCLUDE THIS INFORMATION:');
|
2021-02-17 15:24:33 +02:00
|
|
|
log.warn(`Discord Tickets v${version}, Node v${process.versions.node} on ${process.platform}`);
|
2021-02-16 02:02:44 +02:00
|
|
|
log.warn('An error was not caught');
|
|
|
|
if (error instanceof Error) log.warn(`Uncaught ${error.name}: ${error}`);
|
|
|
|
log.error(error);
|
|
|
|
});
|
|
|
|
|