From cc82d328400d6f6ec794ed8526073dcb4960a2d9 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Wed, 14 Apr 2021 16:37:40 -0500 Subject: [PATCH] Fixed slow, changed clean to handle all env variables, changed database handling --- natives/speed.cc | 2 +- utils/database.js | 2 +- utils/database/{mongo.js => mongodb.js} | 0 utils/database/{postgres.js => postgresql.js} | 0 utils/misc.js | 20 ++++++++----------- 5 files changed, 10 insertions(+), 14 deletions(-) rename utils/database/{mongo.js => mongodb.js} (100%) rename utils/database/{postgres.js => postgresql.js} (100%) diff --git a/natives/speed.cc b/natives/speed.cc index 9077f88..92dc138 100644 --- a/natives/speed.cc +++ b/natives/speed.cc @@ -29,7 +29,7 @@ class SpeedWorker : public Napi::AsyncWorker { } int new_delay = slow ? old_delay * 2 : old_delay / 2; - if (new_delay <= 1) { + if (!slow && new_delay <= 1) { new_delay = old_delay; auto it = frames.begin(); while(it != frames.end() && ++it != frames.end()) it = frames.erase(it); diff --git a/utils/database.js b/utils/database.js index 51c1d2a..3664297 100644 --- a/utils/database.js +++ b/utils/database.js @@ -1,3 +1,3 @@ // wrapper for the database drivers in ./database/ -module.exports = require(`./database/${process.env.DB_DRIVER}.js`); \ No newline at end of file +module.exports = require(`./database/${process.env.DB.split("://")[0]}.js`); \ No newline at end of file diff --git a/utils/database/mongo.js b/utils/database/mongodb.js similarity index 100% rename from utils/database/mongo.js rename to utils/database/mongodb.js diff --git a/utils/database/postgres.js b/utils/database/postgresql.js similarity index 100% rename from utils/database/postgres.js rename to utils/database/postgresql.js diff --git a/utils/misc.js b/utils/misc.js index bc862e1..2a9d47b 100644 --- a/utils/misc.js +++ b/utils/misc.js @@ -6,7 +6,7 @@ exports.random = (array) => { }; const optionalReplace = (token) => { - return token === "" ? "" : ""; + return token === undefined || token === "" ? "" : ""; }; // clean(text) to clean message of any private info or mentions @@ -18,17 +18,13 @@ exports.clean = async (text) => { text = text .replaceAll("`", `\`${String.fromCharCode(8203)}`) - .replaceAll("@", `@${String.fromCharCode(8203)}`) - .replaceAll(process.env.TOKEN, optionalReplace(process.env.TOKEN)) - .replaceAll(process.env.MASHAPE, optionalReplace(process.env.MASHAPE)) - .replaceAll(process.env.CAT, optionalReplace(process.env.CAT)) - .replaceAll(process.env.GOOGLE, optionalReplace(process.env.GOOGLE)) - .replaceAll(process.env.DBL, optionalReplace(process.env.DBL)) - .replaceAll(process.env.MONGO, optionalReplace(process.env.MONGO)) - .replaceAll(process.env.TWITTER_KEY, optionalReplace(process.env.TWITTER_KEY)) - .replaceAll(process.env.CONSUMER_SECRET, optionalReplace(process.env.CONSUMER_SECRET)) - .replaceAll(process.env.ACCESS_TOKEN, optionalReplace(process.env.ACCESS_TOKEN)) - .replaceAll(process.env.ACCESS_SECRET, optionalReplace(process.env.ACCESS_SECRET)); + .replaceAll("@", `@${String.fromCharCode(8203)}`); + + const { parsed } = require("dotenv").config(); + + for (const env of Object.keys(parsed)) { + text = text.replaceAll(parsed[env], optionalReplace(parsed[env])); + } return text; };