diff --git a/commands/meta/me.js b/commands/meta/me.js index 5faca85..f7d348d 100644 --- a/commands/meta/me.js +++ b/commands/meta/me.js @@ -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){ @@ -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; } diff --git a/things.js b/things.js index dd889c1..dc5dfff 100644 --- a/things.js +++ b/things.js @@ -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; \ No newline at end of file +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; +} \ No newline at end of file