diff --git a/src/Eco.js b/src/Eco.js index 70edc15..5760ff4 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: Number(item.data) || 0 + }); }); return arr; 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;