From ce6e2b7d8fb55802070b95ffbf8a13bc57c9369b Mon Sep 17 00:00:00 2001 From: David Ralph Date: Fri, 30 Sep 2022 19:21:59 +0100 Subject: [PATCH] optimise by removing unneeded modules and replacing with built-in methods (#344) --- .gitignore | 2 ++ package.json | 2 -- src/listeners/client/ready.js | 4 ++-- src/routes/api/client.js | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 278566d..a8cad29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # directories dist/ +.history/ +.vscode/ node_modules/ prisma/ diff --git a/package.json b/package.json index 280ff73..7d2f56c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "@fastify/jwt": "^5.0.1", "@fastify/oauth2": "^5.1.0", "@prisma/client": "^4.3.1", - "boolean": "^3.2.0", "cryptr": "^6.0.3", "discord.js": "^14.3.0", "dotenv": "^16.0.2", @@ -55,7 +54,6 @@ "keyv": "^4.5.0", "leeks.js": "^0.2.4", "leekslazylogger": "^4.1.7", - "md5": "^2.3.0", "ms": "^2.1.3", "node-dir": "^0.1.17", "node-emoji": "^1.11.0", diff --git a/src/listeners/client/ready.js b/src/listeners/client/ready.js index eef6218..5063e51 100644 --- a/src/listeners/client/ready.js +++ b/src/listeners/client/ready.js @@ -1,5 +1,5 @@ const { Listener } = require('@eartharoid/dbf'); -const md5 = require('md5'); +const crypto = require('crypto'); const ms = require('ms'); const { version } = require('../../../package.json'); const { msToMins } = require('../../lib/misc'); @@ -81,7 +81,7 @@ module.exports = class extends Listener { categories: await client.prisma.category.count(), database: process.env.DB_PROVIDER, guilds: client.guilds.cache.size, - id: md5(client.user.id), + id: crypto.createHash('md5').update(client.user.id).digest('hex'), members: client.guilds.cache.reduce((t, g) => t + g.memberCount, 0), messages: users.reduce((total, user) => total + user.messageCount, 0), // don't count archivedMessage table rows, they can be deleted, node: process.version, diff --git a/src/routes/api/client.js b/src/routes/api/client.js index 40a6a60..fd3051a 100644 --- a/src/routes/api/client.js +++ b/src/routes/api/client.js @@ -1,5 +1,4 @@ const ms = require('ms'); -const { boolean } = require('boolean'); module.exports.get = () => ({ handler: async (req, res) => { @@ -22,7 +21,7 @@ module.exports.get = () => ({ discriminator: client.user.discriminator, id: client.user.id, portal: process.env.PORTAL || null, - public: boolean(process.env.PUBLIC_BOT), + public: (process.env.PUBLIC_BOT === 'true'), stats: { activatedUsers: users.length, archivedMessages: users.reduce((total, user) => total + user.messageCount, 0), // don't count archivedMessage table rows, they can be deleted