From 314526742717fa734a0324554b78d4951c4ce008 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 21 Apr 2020 18:15:21 -0400 Subject: [PATCH] Minimum Value in Roll --- README.md | 2 +- commands/random-res/roll.js | 30 ++++++++++++++++++++++-------- package.json | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 68cdc294..ccf50e22 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ Total: 398 * **random-user:** Randomly chooses a member of the server. * **rate:** Rates something. * **roast:** Roasts a user. -* **roll:** Rolls a dice with a maximum value of your choice. +* **roll:** Rolls a dice with a minimum/maximum value of your choice. * **security-key:** Responds with a random security key. * **shower-thought:** Responds with a random shower thought, directly from r/Showerthoughts. * **smw-level:** Responds with a random Super Mario World level name. diff --git a/commands/random-res/roll.js b/commands/random-res/roll.js index 6ad0f7f3..30c69d0d 100644 --- a/commands/random-res/roll.js +++ b/commands/random-res/roll.js @@ -1,5 +1,5 @@ const Command = require('../../structures/Command'); -const { formatNumber } = require('../../util/Util'); +const { randomRange, formatNumber } = require('../../util/Util'); module.exports = class RollCommand extends Command { constructor(client) { @@ -8,20 +8,34 @@ module.exports = class RollCommand extends Command { aliases: ['dice'], group: 'random-res', memberName: 'roll', - description: 'Rolls a dice with a maximum value of your choice.', + description: 'Rolls a dice with a minimum/maximum value of your choice.', args: [ { - key: 'value', - label: 'maximum number', - prompt: 'What is the maximum number you wish to appear?', + key: 'maxValue', + label: 'highest number', + prompt: 'What is the highest number you wish to appear?', type: 'integer', - default: 6 + default: 6, + min: 1, + max: Number.MAX_SAFE_INTEGER + }, + { + key: 'minValue', + label: 'lowest number', + prompt: 'What is the lowest number you wish to appear?', + type: 'integer', + default: 0, + min: 0, + max: Number.MAX_SAFE_INTEGER } ] }); } - run(msg, { value }) { - return msg.say(`You rolled a ${formatNumber(Math.floor(Math.random() * value) + 1)}.`); + run(msg, { maxValue, minValue }) { + let result; + if (!minValue) result = Math.floor(Math.random() * maxValue) + 1; + else result = randomRange(minValue, maxValue); + return msg.say(`You rolled a ${formatNumber(result)}.`); } }; diff --git a/package.json b/package.json index 74b7d1b4..33f7f9da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "113.12.1", + "version": "113.12.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {