Skip to content

Commit

Permalink
Moved createExpBar to things.js
Browse files Browse the repository at this point in the history
  • Loading branch information
12beesinatrenchcoat committed Apr 3, 2021
1 parent c994780 commit 2f295af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
25 changes: 3 additions & 22 deletions commands/meta/me.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,7 @@ const { MessageEmbed } = require("discord.js");
const info = require("./commandinfo.json");
const userModel = require("../../model.user.js");

const { expNeededForLevel } = require.main.require("./things.js");

async function createExpBar(percentage, maxLength) {
let output = "";
const fillCount = Math.floor(percentage / 100 * maxLength);

for(let char = 0; char < maxLength; char++){

if (char === 0) {
output += "[";
} else if (char <= fillCount) {
output += "|";
} else if (char === maxLength - 1) {
output += "]";
} else {
output += " ";
}
}

return output;
}
const { expNeededForLevel, createExpBar } = require.main.require("./things.js");

function toBigNumber(number){

Expand Down Expand Up @@ -122,8 +102,9 @@ class SlabbotMe extends Command{

async exec(message) {

const { exp, level, stats } = await userModel.findById(message.author.id, "exp level stats");
const { exp, level, stats } = await userModel.findById(message.author.id, "exp level stats") || 0;

// TODO: better error handling with new users.
if(exp === 0){
return;
}
Expand Down
22 changes: 21 additions & 1 deletion things.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
// misc. things that would be used in more than one thing.

// see also: https://www.desmos.com/calculator/kcrt4evjgg
exports.expNeededForLevel = level => 1024 * (level ** 1.3) + (256 *((level-1) / 8) ** 1.8) || 0;
exports.expNeededForLevel = level => 1024 * (level ** 1.3) + (256 *((level-1) / 8) ** 1.8) || 0;

exports.createExpBar = async function createExpBar(percentage, maxLength) {
let output = "";
const fillCount = Math.floor(percentage / 100 * maxLength);

for(let char = 0; char < maxLength; char++){

if (char === 0) {
output += "[";
} else if (char <= fillCount) {
output += "|";
} else if (char === maxLength - 1) {
output += "]";
} else {
output += " ";
}
}

return output;
}

0 comments on commit 2f295af

Please sign in to comment.