From 3a1c0f54bd4aaf8a9f9d2a5cf8474fd9c81db140 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 18 Jul 2022 13:34:29 +0100 Subject: [PATCH] Node v18, discord.js v14 --- package.json | 15 +++-- src/client.js | 10 ++-- src/http.js | 55 ++++++++----------- .../admin/guilds/[guild]/categories/index.js | 2 +- src/routes/auth/callback.js | 1 - 5 files changed, 37 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 11934a0..3b2029b 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ }, "homepage": "https://discordtickets.app", "engines": { - "node": ">=16.6" + "node": ">=18.0" }, "dependencies": { - "@eartharoid/dbf": "^0.0.1", + "@eartharoid/dbf": "^0.2.0", "@eartharoid/dtf": "^2.0.1", "@eartharoid/i18n": "^1.0.4", "@fastify/cookie": "^6.0.0", @@ -39,26 +39,25 @@ "@fastify/oauth2": "^5.0.0", "@prisma/client": "^4.0.0", "cryptr": "^6.0.3", - "discord.js": "^13.9.0", + "discord.js": "^14.0.2", "dotenv": "^16.0.1", "fastify": "^4.2.1", "figlet": "^1.5.2", - "keyv": "^4.3.2", + "keyv": "^4.3.3", "leeks.js": "^0.2.4", "leekslazylogger": "^4.1.7", "ms": "^2.1.3", "node-dir": "^0.1.17", - "node-fetch": "^2.6.7", "object-diffy": "^1.0.4", + "prisma": "^4.0.0", "semver": "^7.3.7", "terminal-link": "^2.1.1", "yaml": "^1.10.2" }, "devDependencies": { "all-contributors-cli": "^6.20.0", - "eslint": "^8.19.0", + "eslint": "^8.20.0", "eslint-plugin-unused-imports": "^2.0.0", - "nodemon": "^2.0.19", - "prisma": "^4.0.0" + "nodemon": "^2.0.19" } } \ No newline at end of file diff --git a/src/client.js b/src/client.js index 1b14547..a1e78ea 100644 --- a/src/client.js +++ b/src/client.js @@ -1,5 +1,5 @@ -const { Client: FrameworkClient }= require('@eartharoid/dbf'); -const { Intents } = require('discord.js'); +const { Client: FrameworkClient } = require('@eartharoid/dbf'); +const { GatewayIntentBits } = require('discord.js'); const { PrismaClient } = require('@prisma/client'); const Keyv = require('keyv'); const I18n = require('@eartharoid/i18n'); @@ -12,9 +12,9 @@ module.exports = class Client extends FrameworkClient { constructor(config, log) { super({ intents: [ - Intents.FLAGS.GUILDS, - Intents.FLAGS.GUILD_MEMBERS, - Intents.FLAGS.GUILD_MESSAGES, + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildMessages, ], }); diff --git a/src/http.js b/src/http.js index 4988973..21d578a 100644 --- a/src/http.js +++ b/src/http.js @@ -3,7 +3,7 @@ const oauth = require('@fastify/oauth2'); // const { randomBytes } = require('crypto'); const { short } = require('leeks.js'); const { join } = require('path'); -const { readFiles } = require('node-dir'); +const { files } = require('node-dir'); module.exports = client => { @@ -115,36 +115,29 @@ module.exports = client => { // route loading const dir = join(__dirname, '/routes'); - readFiles(dir, - { - exclude: /^\./, - match: /.js$/, - }, - (err, content, next) => next(), - (err, files) => { - if (err) throw err; + files(dir, { + exclude: /^\./, + match: /.js$/, + sync: true, + }).forEach(file => { + const path = file + .substring(0, file.length - 3) // remove `.js` + .substring(dir.length) // remove higher directories + .replace(/\[(\w+)\]/gi, ':$1') // convert [] to : + .replace('/index', '') || '/'; // remove index + const route = require(file); - for (const file of files) { - const path = file - .substring(0, file.length - 3) // remove `.js` - .substring(dir.length) // remove higher directories - .replace(/\[(\w+)\]/gi, ':$1') // convert [] to : - .replace('/index', '') || '/'; // remove index - const route = require(file); + Object.keys(route).forEach(method => fastify.route({ + config: { client }, + method: method.toUpperCase(), + path, + ...route[method](fastify), + })); // register route + }); - Object.keys(route).forEach(method => fastify.route({ - config: { client }, - method: method.toUpperCase(), - path, - ...route[method](fastify), - })); // register route - } - - // start server - fastify.listen({ port: process.env.HTTP_BIND }, (err, addr) => { - if (err) client.log.error.http(err); - else client.log.success.http(`Listening at ${addr}`); - }); - }, - ); + // start server + fastify.listen({ port: process.env.HTTP_BIND }, (err, addr) => { + if (err) client.log.error.http(err); + else client.log.success.http(`Listening at ${addr}`); + }); }; \ No newline at end of file diff --git a/src/routes/api/admin/guilds/[guild]/categories/index.js b/src/routes/api/admin/guilds/[guild]/categories/index.js index 2d1d9bd..1a8a9df 100644 --- a/src/routes/api/admin/guilds/[guild]/categories/index.js +++ b/src/routes/api/admin/guilds/[guild]/categories/index.js @@ -69,7 +69,7 @@ module.exports.post = fastify => ({ data.discordCategory = channel.id; } - if (!data.channelName) data.channelName = 'ticket-{num}'; + data.channelName ??= 'ticket-{num}'; const category = await client.prisma.category.create({ data: { diff --git a/src/routes/auth/callback.js b/src/routes/auth/callback.js index 43cf2cc..400fcb3 100644 --- a/src/routes/auth/callback.js +++ b/src/routes/auth/callback.js @@ -1,4 +1,3 @@ -const fetch = require('node-fetch'); const { domain } = require('../../lib/http'); module.exports.get = () => ({