Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: shorten code #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/Eco.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -63,8 +63,6 @@ class EconomyManager {
default:

this.db = new adapter(this.adapter.options);

break;
}

} catch (err) {
Expand Down Expand Up @@ -169,10 +167,10 @@ class EconomyManager {
while (i < len) {
this.db.delete(all[i].ID);
i++;
};
}

return true;
} else return;
}
}

/**
Expand All @@ -193,10 +191,10 @@ class EconomyManager {
while (i < len) {
this.db.delete(all[i].ID);
i++;
};
}

return true;
} else return;
}
}

/**
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 10 additions & 17 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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]
};
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -218,4 +211,4 @@ class Util {
}
};

module.exports = Util;
module.exports = Util;