Start on database schema

This commit is contained in:
Isaac
2022-03-21 23:28:20 +00:00
parent 5ae4da227e
commit e569642240
10 changed files with 149 additions and 29 deletions

31
src/client.mjs Normal file
View File

@@ -0,0 +1,31 @@
import {
container,
SapphireClient
} from '@sapphire/framework';
import { Intents } from 'discord.js';
import prisma from '@prisma/client';
export default class Client extends SapphireClient {
constructor() {
super({
defaultPrefix: 'tickets/',
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS
],
});
}
async login(token) {
container.prisma = new prisma.PrismaClient();
return super.login(token);
}
async destroy() {
await container.prisma.$disconnect();
return super.destroy();
}
}

View File

@@ -21,13 +21,15 @@
* @license GNU-GPLv3
*/
import dotenv from 'dotenv-cra';
import dotenv from 'dotenv';
import fs from 'fs';
import semver from 'semver';
import { colours } from 'leeks.js';
import logger from './lib/logger.mjs';
import banner from './lib/banner.mjs';
import YAML from 'yaml';
import { container } from '@sapphire/framework';
import Client from './client.mjs';
process.env.NODE_ENV ??= 'development'; // make sure NODE_ENV is set
dotenv.config(); // load env file
@@ -36,7 +38,7 @@ 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: Discord Tickets requires Node.js version ${pkg.engines.node}; you are currently using ${process.versions.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);
}
@@ -45,8 +47,6 @@ if (process.env.DB_ENCRYPTION_KEY === undefined) {
process.exit(1);
}
console.log(banner(pkg.version)); // print big title
process.env.CONFIG_PATH ??= './user/config.yml'; // set default config file path
if (!fs.existsSync(process.env.CONFIG_PATH)) {
@@ -61,10 +61,11 @@ if (!fs.existsSync(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);
container.log = log;
process.on('unhandledRejection', error => {
log.notice(`Discord Tickets v${pkg.version} on Node.js v${process.versions.node} (${process.platform})`);
@@ -73,3 +74,5 @@ process.on('unhandledRejection', error => {
log.error(error);
});
const client = new Client();
client.login();

View File

@@ -1,22 +1,9 @@
import { colours } from 'leeks.js';
import figlet from 'figlet';
import link from 'terminal-link';
export default version => colours.cyan(`
######## #### ###### ###### ####### ######## ########
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ##
## ## ## ###### ## ## ## ######## ## ##
## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ##
######## #### ###### ###### ####### ## ## ########
######## #### ###### ## ## ######## ######## ######
## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
## ## ## ##### ###### ## ######
## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ##
## #### ###### ## ## ######## ## ######
`) +
colours.cyanBright(`\n${link('Discord Tickets', 'https://discordtickets.app')} bot v${version} by eartharoid`) +
colours.cyanBright('\n' + link('Sponsor this project', 'https://discordtickets.app/sponsor')) +
'\n\n';
export default version => colours.cyan(figlet.textSync('Discord', { font: 'Banner3' })) +
colours.cyan('\n\n' + figlet.textSync('Tickets', { font: 'Banner3' })) +
colours.cyanBright(`\n\n${link('Discord Tickets', 'https://discordtickets.app')} bot v${version} by eartharoid`) +
colours.cyanBright('\n' + link('Sponsor this project', 'https://discordtickets.app/sponsor')) +
'\n\n';