Conversation
|
Hi Toby, The listDice() method of the dice controller kicks back an UnhandledPromiseRejection as listDice() must return a string. I would also recommend adjusting your __eslint.js file to include Thanks, Garrett |
gmoore10
left a comment
There was a problem hiding this comment.
Everything looks good on my end. Approved.
|
In regards to the _eslint.js file. I don't think it needs to be drilled into like that as it was 'bot' previously before. I also just ran tests with the change you suggested and it didn't make any difference leading me to believe that having just 'bot' as a testing route means it just summarizes everything within that folder instead of outputting each file in the console like the test folder does. |
bot/controllers/dice.js
Outdated
| const { message } = this; | ||
| const dice = message.parsed[1].split(','); | ||
| util.log('Parsed message: ', dice, 4); | ||
| let results = 'You rolled a '; |
There was a problem hiding this comment.
Variable name semantically ambiguous
bot/controllers/dice.js
Outdated
| // Decide what equation to run based on the dice type | ||
| switch (dice.toString()) { | ||
| case 'D4': | ||
| results += Math.floor((Math.random() * 4) + 1); |
There was a problem hiding this comment.
Duplicate logic: Lines 46, 49, 52, 55, 58
Magic numbers (same lines)
bot/controllers/dice.js
Outdated
| // Perform the rolling of the dice | ||
| rollAction() { | ||
| const { message } = this; | ||
| const dice = message.parsed[1].split(','); |
bot/controllers/dice.js
Outdated
| break; | ||
| default: | ||
| // Return an error if user didn't input a supported die type | ||
| results = 'You rolled an unidentified die, please use `!listDice` to see all available dice!'; |
There was a problem hiding this comment.
Tip: If the command changes this helper message will be invalid. Try to keep these instances to a min.
bot/controllers/dice.js
Outdated
|
|
||
| // Send an embedded message to the user in their dms | ||
| message.member.send({ embed: { | ||
| color: 0x9d0a0e, |
bot/controllers/dice.js
Outdated
| let diceString = 'Here is a list of all available dice:'; | ||
|
|
||
| // Map the dice array and add it to the string to return | ||
| dice.map((val) => { |
There was a problem hiding this comment.
Poor semantic variable name.
bot/controllers/dice.js
Outdated
| listDice() { | ||
| const { message } = this; | ||
| const dice = ['D4', 'D6', 'D8', 'D10', 'D12', 'D20']; // Dice array | ||
| let diceString = 'Here is a list of all available dice:'; |
There was a problem hiding this comment.
Semantically poor variable name.
bot/controllers/dice.js
Outdated
| color: 0x9d0a0e, | ||
| description: diceString, | ||
| } }); | ||
| return 'Use this information wisely!'; |
There was a problem hiding this comment.
Your current setup sends two dms when only 1 is needed. Additionally, you have created a race condition with your other message.member.send(). Would be better to see the color embed happen on the base controller and you can configure that from here, so that other controllers can benefit from this logic.
bot/controllers/dice.js
Outdated
| // List all the dice | ||
| listDice() { | ||
| const { message } = this; | ||
| const dice = ['D4', 'D6', 'D8', 'D10', 'D12', 'D20']; // Dice array |
There was a problem hiding this comment.
Why not support a D100? or a D3? You could more elegantly handle this by parsing the provided input and interpret the number following the D as the number you intend to mathematically use... skipping the magic number aspect and dynamical supporting what ever number your user wants rather than limiting the user to the narrow choices you have provided.
…tiple rolls of different dice. Removed limited dice types. Removed listDice command as it is no longer needed.
bot/controllers/dice.js
Outdated
|
|
||
| diceCommand.map((singleDie) => { | ||
| // Get the specifics of the roll based on the location of the 'd' | ||
| let rollCount = singleDie.toLowerCase().substr(0, singleDie.indexOf('d')); |
There was a problem hiding this comment.
This line is causing an issue that is crashing the bot when an unexpected input is found.
Because of the way this line is written, it is looking for an indexOf on a lowercase d... however, when I pass an uppercase D (or any other letter that isn't a D for that matter), the indexOf returns an unexpected value which turns the rollCount into a value that is not a number.
Because of this, line 44 (rollCount -= 1;) may not behave as expected and cause the while loop to loop endlessly until the bot runs out of memory.
I think this line should be:
let rollCount = singleDie.toLowerCase().substr(0, singleDie.toLowerCase.indexOf('d'));
However, this will not completely fix the issue. If I put in something other than an uppercase D or lowercase d, the bot will still crash.
You might need to implement some sort of check on the indexOf() to make sure the value is within range. If not, it should return an error indicating the problem with the input.
|
Hi Toby, I found an issue with the logic in the !roll function. Please see my notes above. Thanks, Garrett |
Added conditional to check for specific formatting. Added error output if input wasn’t correct.
|
I've fixed the error outlined above as well as added a conditional and error for when the user inputs an invalid dice format. |
|
Good work fixing the issue with the lowercase/uppercase d. I did still manage to crash the bot by running |
Edited command description to be valid. Edited error message to be valid.
|
Thanks for the feedback! The roll command now has regex to check for the proper format as well an extra conditional to verify the beginning of the command is accurate. The description and error messages have also been updated to account for support of |
gmoore10
left a comment
There was a problem hiding this comment.
Everything looks good on my end. Any die size and any number of rolls works correctly. Regex pattern correctly checks for the appropriate #D# format.
bot/controllers/dice.js
Outdated
| // Perform the rolling of the dice | ||
| rollAction() { | ||
| const { message } = this; | ||
| const diceCommand = message.parsed[1].split(','); |
There was a problem hiding this comment.
Magic Number (1) and Semantically diceCommand should be plural.
There was a problem hiding this comment.
Fixed these issues. For the magic number, this is present in all the other files as well, which is the only reason I assumed this instance of it was okay.
Added commands to direct message the user a list of all supported dice in a well formatted embedded message and to roll a dice from the list of supported dice.
A future release will allow users to roll multiple dice and add in their ability perks.