From be9f059d96a5e19b23481225b4c0d958534756c8 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 23 Jan 2023 18:14:57 -0500 Subject: [PATCH] Add water time calucation to /compare --- modules/functions.js | 10 +++++++--- slash-commands/watertime.js | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/functions.js b/modules/functions.js index 04f32ee..7a6ca2b 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -150,12 +150,13 @@ const functions = { let difference = parseFloat(e.height).toFixed(1) - treeHeight; const absDifference = parseFloat(Math.abs(difference)).toFixed(1); if (difference > 0) { - replyString += `${absDifference}ft shorter than rank #${e.rank}\n`; + replyString += `#${e.rank} - ${absDifference}ft shorter `; } else if (difference < 0) { - replyString += `${absDifference}ft taller than rank #${e.rank}\n`; + replyString += `#${e.rank} - ${absDifference}ft taller `; } else if (difference == 0) { - replyString += `Same height as rank #${e.rank}\n`; + replyString += `#${e.rank} - Same height `; } + replyString += `[${functions.getWaterTime(e.height)}m]\n`; }); return 'Here\'s how your tree compares: \n' + replyString; } else { @@ -236,6 +237,9 @@ const functions = { } else { return "Your guild hasn't been set up yet."; } + }, + getWaterTime(size) { + return Math.floor((Math.pow(size * 0.07 + 5, 1.1) / 60)); } }; diff --git a/slash-commands/watertime.js b/slash-commands/watertime.js index c6a4510..4338176 100644 --- a/slash-commands/watertime.js +++ b/slash-commands/watertime.js @@ -13,7 +13,6 @@ module.exports = { async execute(interaction) { await interaction.deferReply(); const treeHeight = interaction.options.getString('height'); - const waterTime = Math.floor(Math.floor(Math.pow(treeHeight * 0.07 + 5, 1.1)) / 60); - await interaction.editReply(`A tree that is ${treeHeight}ft tall will have a watering time of ${waterTime} minutes.`); + await interaction.editReply(`A tree that is ${treeHeight}ft tall will have a watering time of ${fn.getWaterTime(treeHeight)} minutes.`); }, }; \ No newline at end of file