From cbfbf05e8cd61b8250d5d023f75bcc0290be4f12 Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 5 May 2022 21:29:28 +0100 Subject: [PATCH] mjs -> cjs --- jsconfig.json | 5 ----- package.json | 18 ++++++++---------- scripts/{keygen.mjs => keygen.js} | 6 +++--- src/client.js | 24 ++++++++++++++++++++++++ src/client.mjs | 31 ------------------------------- src/{index.mjs => index.js} | 22 +++++++++++----------- src/lib/{banner.mjs => banner.js} | 8 ++++---- src/lib/{logger.mjs => logger.js} | 12 ++++++------ src/listeners/client/ready.js | 16 ++++++++++++++++ 9 files changed, 72 insertions(+), 70 deletions(-) rename scripts/{keygen.mjs => keygen.js} (68%) create mode 100644 src/client.js delete mode 100644 src/client.mjs rename src/{index.mjs => index.js} (87%) rename src/lib/{banner.mjs => banner.js} (59%) rename src/lib/{logger.mjs => logger.js} (85%) create mode 100644 src/listeners/client/ready.js diff --git a/jsconfig.json b/jsconfig.json index 554aae6..120fd76 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -6,13 +6,8 @@ "baseUrl": "src", "resolveJsonModule": true, "checkJs": false, - "paths": { - "@/*": ["*.mjs"], - "#/*": ["*.json"] - } }, "include": [ - "src/**/*.mjs", "src/**/*.js" ] } \ No newline at end of file diff --git a/package.json b/package.json index f024b27..33d8694 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,11 @@ "version": "4.0.0", "private": "true", "description": "An open-source Discord bot for ticket management", - "main": "src/index.mjs", - "module": "src/index.mjs", - "type": "module", + "main": "src/", "scripts": { "contributors:add": "all-contributors add", "contributors:generate": "all-contributors generate", - "keygen": "node scripts/keygen.mjs", + "keygen": "node scripts/keygen", "lint": "eslint src scripts --ext mjs --fix", "test": "echo \"There's nothing to test\" && exit 1" }, @@ -32,22 +30,22 @@ "node": ">=16.6" }, "dependencies": { + "@eartharoid/dbf": "^0.0.1", "@eartharoid/dtf": "^2.0.1", - "@prisma/client": "^3.11.0", - "@sapphire/framework": "^2.4.1", + "@prisma/client": "^3.13.0", "discord.js": "^13.6.0", "dotenv": "^16.0.0", "figlet": "^1.5.2", "leeks.js": "^0.2.4", "leekslazylogger": "^4.1.7", - "semver": "^7.3.5", - "terminal-link": "^3.0.0", + "semver": "^7.3.7", + "terminal-link": "^2.1.1", "yaml": "^1.10.2" }, "devDependencies": { "all-contributors-cli": "^6.20.0", - "eslint": "^8.11.0", + "eslint": "^8.14.0", "eslint-plugin-unused-imports": "^2.0.0", - "prisma": "^3.11.0" + "prisma": "^3.13.0" } } \ No newline at end of file diff --git a/scripts/keygen.mjs b/scripts/keygen.js similarity index 68% rename from scripts/keygen.mjs rename to scripts/keygen.js index 9dd0443..1750a61 100644 --- a/scripts/keygen.mjs +++ b/scripts/keygen.js @@ -1,8 +1,8 @@ -import { randomBytes } from 'crypto'; -import { short } from 'leeks.js'; +const { randomBytes } = require('crypto'); +const { short } = require('leeks.js'); console.log(short( 'Set the "DB_ENCRYPTION_KEY" environment variable to: \n&1&!f' + randomBytes(24).toString('hex') + - '&r\n\n&0&!e WARNING &r &e&lIf you lose the encryption key, most of the data in the database will become unreadable, requiring a new key and a full reset.' + '&r\n\n&0&!e WARNING &r &e&lIf you lose the encryption key, most of the data in the database will become unreadable, requiring a new key and a full reset.', )); \ No newline at end of file diff --git a/src/client.js b/src/client.js new file mode 100644 index 0000000..f24a6b8 --- /dev/null +++ b/src/client.js @@ -0,0 +1,24 @@ +const { Client: FrameworkClient }= require('@eartharoid/dbf'); +const { Intents } = require('discord.js'); +const prisma = require('@prisma/client'); + +module.exports = class Client extends FrameworkClient { + constructor() { + super({ + intents: [ + Intents.FLAGS.GUILDS, + Intents.FLAGS.GUILD_MEMBERS, + Intents.FLAGS.GUILD_MESSAGES, + ], + }); + } + async login(token) { + this.prisma = new prisma.PrismaClient(); + return super.login(token); + } + + async destroy() { + await this.prisma.$disconnect(); + return super.destroy(); + } +}; \ No newline at end of file diff --git a/src/client.mjs b/src/client.mjs deleted file mode 100644 index 64645a9..0000000 --- a/src/client.mjs +++ /dev/null @@ -1,31 +0,0 @@ -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(); - } - - -} \ No newline at end of file diff --git a/src/index.mjs b/src/index.js similarity index 87% rename from src/index.mjs rename to src/index.js index cb52eb3..e98cd17 100644 --- a/src/index.mjs +++ b/src/index.js @@ -21,18 +21,17 @@ * @license GNU-GPLv3 */ -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'; + +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 -dotenv.config(); // load env file +require('dotenv').config(); // load env file const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); @@ -65,7 +64,6 @@ 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})`); @@ -75,4 +73,6 @@ process.on('unhandledRejection', error => { }); const client = new Client(); +client.config = config; +client.log = log; client.login(); \ No newline at end of file diff --git a/src/lib/banner.mjs b/src/lib/banner.js similarity index 59% rename from src/lib/banner.mjs rename to src/lib/banner.js index 2201c2f..2ade4cb 100644 --- a/src/lib/banner.mjs +++ b/src/lib/banner.js @@ -1,8 +1,8 @@ -import { colours } from 'leeks.js'; -import figlet from 'figlet'; -import link from 'terminal-link'; +const { colours } = require('leeks.js'); +const figlet = require('figlet'); +const link = require('terminal-link'); -export default version => colours.cyan(figlet.textSync('Discord', { font: 'Banner3' })) + +module.exports = 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')) + diff --git a/src/lib/logger.mjs b/src/lib/logger.js similarity index 85% rename from src/lib/logger.mjs rename to src/lib/logger.js index 6372ff3..4a330ae 100644 --- a/src/lib/logger.mjs +++ b/src/lib/logger.js @@ -1,6 +1,6 @@ -import Logger from 'leekslazylogger'; -import DTF from '@eartharoid/dtf'; -import { short } from 'leeks.js'; +const Logger = require('leekslazylogger'); +const DTF = require('@eartharoid/dtf'); +const { short } = require('leeks.js'); const dtf = new DTF(); const colours = { @@ -13,7 +13,7 @@ const colours = { warn: ['&6', '&e'], }; -export default config => { +module.exports = config => { const transports = [ new Logger.transports.ConsoleTransport({ format: log => { @@ -22,7 +22,7 @@ export default config => { return short(`&f&!7${timestamp}&r ${colour[0]}[${log.level.name.toUpperCase()}]&r ${log.namespace ? `&d(${log.namespace.toUpperCase()})&r ` : ''}${colour[1]}${log.content}`); }, level: config.logs.level, - }) + }), ]; if (config.logs.files.enabled) { @@ -32,7 +32,7 @@ export default config => { directory: config.logs.files.directory, level: config.logs.level, name: 'Discord Tickets by eartharoid', - }) + }), ); } diff --git a/src/listeners/client/ready.js b/src/listeners/client/ready.js new file mode 100644 index 0000000..5ef5e5b --- /dev/null +++ b/src/listeners/client/ready.js @@ -0,0 +1,16 @@ +const dbf = require('@eartharoid/dbf'); + +module.exports = class extends dbf.Listener { + constructor(client) { + super(client, { + emitter: client, + event: 'ready', + id: 'clientReady', + once: true, + }); + } + + run() { + this.client.log.success('Connected to Discord as "%s"', this.client.user.tag); + } +}; \ No newline at end of file