From 60b1af52b240bea4d7accd427625261780862d02 Mon Sep 17 00:00:00 2001 From: null <60427892+vierofernando@users.noreply.github.com> Date: Sun, 24 Oct 2021 17:50:09 +0700 Subject: [PATCH 1/3] refactor(Eco): code improvements --- src/Eco.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Eco.js b/src/Eco.js index 70edc15..586de0d 100644 --- a/src/Eco.js +++ b/src/Eco.js @@ -42,7 +42,7 @@ class EconomyManager { * Database Manager * @type {any} */ - this.db; + this.db = null; if (this.adapter.name && Object.keys(VALID_ADAPTERS).includes(this.adapter.name)) this.__makeAdapter() else throw new Error(`Invalid Adapter: ${this.adapter.name}`) @@ -63,8 +63,6 @@ class EconomyManager { default: this.db = new adapter(this.adapter.options); - - break; } } catch (err) { @@ -169,10 +167,10 @@ class EconomyManager { while (i < len) { this.db.delete(all[i].ID); i++; - }; + } return true; - } else return; + } } /** @@ -193,10 +191,10 @@ class EconomyManager { while (i < len) { this.db.delete(all[i].ID); i++; - }; + } return true; - } else return; + } } /** @@ -226,14 +224,12 @@ class EconomyManager { data.sort((a, b) => b.data - a.data).forEach((item, index) => { const parsedKey = Util.parseKey(item.ID); - const data = { + arr.push({ position: index + 1, user: `${parsedKey.userID}`, guild: `${parsedKey.guildID || ""}`, - money: isNaN(item.data) ? 0 : item.data - }; - - arr.push(data); + money: item.data || 0 + }); }); return arr; From ac928372f337df9159a9f54c1c295b2abc0b5099 Mon Sep 17 00:00:00 2001 From: null <60427892+vierofernando@users.noreply.github.com> Date: Sun, 24 Oct 2021 17:54:10 +0700 Subject: [PATCH 2/3] refactor(Util): shorten code --- src/Util.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Util.js b/src/Util.js index 8e220f1..e4709ef 100644 --- a/src/Util.js +++ b/src/Util.js @@ -66,8 +66,7 @@ class Util { if (typeof cooldownTime !== "number") throw new Error(`Expected cooldownTime to be a number, received ${typeof cooldownTime}!`); if (typeof collectedTime !== "number") throw new Error(`Expected collectedTime to be a number, received ${typeof collectedTime}!`); - if (collectedTime !== null && cooldownTime - (Date.now() - collectedTime) > 0) return true; - return false; + return (collectedTime !== null && cooldownTime - (Date.now() - collectedTime) > 0); } /** @@ -86,22 +85,17 @@ class Util { if (!key) throw new Error("Invalid key"); const chunk = key.split("_"); if (chunk.length >= 3) { - const obj = { + return { prefix: chunk[0], guildID: chunk[1], userID: chunk[2] - }; - - return obj; - } else { - const obj = { - prefix: chunk[0], - guildID: null, - userID: chunk[1] - }; - - return obj; + } } + return { + prefix: chunk[0], + guildID: null, + userID: chunk[1] + }; } /** @@ -123,8 +117,7 @@ class Util { */ static random(from, to) { if (typeof from !== "number" || typeof to !== "number") return 0; - const amt = Math.floor(Math.random() * (to - from + 1)) + from; - return amt; + return Math.floor(Math.random() * (to - from + 1)) + from; } /** @@ -218,4 +211,4 @@ class Util { } }; -module.exports = Util; \ No newline at end of file +module.exports = Util; From 17116bc5c8dee116cba169046f16389a230ab06b Mon Sep 17 00:00:00 2001 From: null <60427892+vierofernando@users.noreply.github.com> Date: Sun, 24 Oct 2021 18:01:18 +0700 Subject: [PATCH 3/3] fix(Eco): just in case --- src/Eco.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eco.js b/src/Eco.js index 586de0d..5760ff4 100644 --- a/src/Eco.js +++ b/src/Eco.js @@ -228,7 +228,7 @@ class EconomyManager { position: index + 1, user: `${parsedKey.userID}`, guild: `${parsedKey.guildID || ""}`, - money: item.data || 0 + money: Number(item.data) || 0 }); });