From 0a0bd9b6fe7c8146a88bb299a2bb81edb9bb385f Mon Sep 17 00:00:00 2001 From: EdwinYi-JanYang <51840314+EdwinYi-JanYang@users.noreply.github.com> Date: Wed, 19 Jan 2022 22:18:35 -0500 Subject: [PATCH 1/6] Create rollDice.ts --- src/commands/fun/rollDice.ts | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/commands/fun/rollDice.ts diff --git a/src/commands/fun/rollDice.ts b/src/commands/fun/rollDice.ts new file mode 100644 index 00000000..2d558fc4 --- /dev/null +++ b/src/commands/fun/rollDice.ts @@ -0,0 +1,41 @@ +import { Message } from 'discord.js'; +import { CommandoClient, CommandoMessage } from 'discord.js-commando'; +import { BaseCommand } from '../../utils/commands'; + +class RollDiceCommand extends BaseCommand { + constructor(client: CommandoClient) { + super(client, { + name: 'roll-dice', + aliases: ['rd', 'roll', 'rolldice', 'dice-roll', 'diceroll', 'dice'], + group: 'fun', + args: [ + { + key: 'sides', + prompt: 'enter the number of sides of the dice', + type: 'integer' + } + ], + memberName: 'dice-coin', + description: 'Roll a dice!', + examples: [`${client.commandPrefix}dice-roll`] + }); + } + + getRandomInt(max: number): number { + return Math.floor(Math.random() * max); + } + + async onRun(message: CommandoMessage, args: {sides: number;}): Promise { + const {sides} = args; + if (sides <= 0) { + return message.reply(`cannot compute ` + sides + ' sides!'); + } + else if (sides > 1000000) { + return message.reply(`that's too many sides!`); + } + const diceFace = this.getRandomInt(sides); + return message.reply(`you rolled a ` + diceFace + `!`); + } +} + +export default RollDiceCommand; \ No newline at end of file From 2047e8f0bdaa6a202db029d162c0cea485a6d4f5 Mon Sep 17 00:00:00 2001 From: EdwinYi-JanYang <51840314+EdwinYi-JanYang@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:48:39 -0500 Subject: [PATCH 2/6] Update rollDice.ts --- src/commands/fun/rollDice.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/fun/rollDice.ts b/src/commands/fun/rollDice.ts index 2d558fc4..aa9adb21 100644 --- a/src/commands/fun/rollDice.ts +++ b/src/commands/fun/rollDice.ts @@ -22,13 +22,17 @@ class RollDiceCommand extends BaseCommand { } getRandomInt(max: number): number { - return Math.floor(Math.random() * max); + const roll = Math.floor(Math.random() * max); + if (roll == 0) { + return 1; + } + return roll; } async onRun(message: CommandoMessage, args: {sides: number;}): Promise { const {sides} = args; if (sides <= 0) { - return message.reply(`cannot compute ` + sides + ' sides!'); + return message.reply(`I cannot compute ` + sides + ' sides!'); } else if (sides > 1000000) { return message.reply(`that's too many sides!`); From c0f37a9bb321821761fce62826a784b0ca8c3850 Mon Sep 17 00:00:00 2001 From: EdwinYi-JanYang <51840314+EdwinYi-JanYang@users.noreply.github.com> Date: Fri, 28 Jan 2022 20:24:46 -0500 Subject: [PATCH 3/6] Update rollDice.ts --- src/commands/fun/rollDice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/fun/rollDice.ts b/src/commands/fun/rollDice.ts index aa9adb21..9fc111aa 100644 --- a/src/commands/fun/rollDice.ts +++ b/src/commands/fun/rollDice.ts @@ -22,7 +22,7 @@ class RollDiceCommand extends BaseCommand { } getRandomInt(max: number): number { - const roll = Math.floor(Math.random() * max); + const roll = Math.floor(Math.random() * (max + 1)); if (roll == 0) { return 1; } @@ -34,7 +34,7 @@ class RollDiceCommand extends BaseCommand { if (sides <= 0) { return message.reply(`I cannot compute ` + sides + ' sides!'); } - else if (sides > 1000000) { + if (sides > 1000000) { return message.reply(`that's too many sides!`); } const diceFace = this.getRandomInt(sides); From f0faf793ef10ffea3cd5f85e060efec751855624 Mon Sep 17 00:00:00 2001 From: EdwinYi-JanYang <51840314+EdwinYi-JanYang@users.noreply.github.com> Date: Fri, 28 Jan 2022 20:28:46 -0500 Subject: [PATCH 4/6] Update rollDice.ts --- src/commands/fun/rollDice.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/fun/rollDice.ts b/src/commands/fun/rollDice.ts index 9fc111aa..6fa304b3 100644 --- a/src/commands/fun/rollDice.ts +++ b/src/commands/fun/rollDice.ts @@ -10,6 +10,7 @@ class RollDiceCommand extends BaseCommand { group: 'fun', args: [ { + default: 6, key: 'sides', prompt: 'enter the number of sides of the dice', type: 'integer' From 35711066baebfc167bb6256263d10af8285968c1 Mon Sep 17 00:00:00 2001 From: EdwinYi-JanYang <51840314+EdwinYi-JanYang@users.noreply.github.com> Date: Fri, 28 Jan 2022 20:38:23 -0500 Subject: [PATCH 5/6] Update rollDice.ts --- src/commands/fun/rollDice.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/commands/fun/rollDice.ts b/src/commands/fun/rollDice.ts index 6fa304b3..eb2b69cc 100644 --- a/src/commands/fun/rollDice.ts +++ b/src/commands/fun/rollDice.ts @@ -23,11 +23,7 @@ class RollDiceCommand extends BaseCommand { } getRandomInt(max: number): number { - const roll = Math.floor(Math.random() * (max + 1)); - if (roll == 0) { - return 1; - } - return roll; + return Math.floor(Math.random() * (max)) + 1; } async onRun(message: CommandoMessage, args: {sides: number;}): Promise { From a786a66c0ee9ee5bcf20675b69ec2efdff6b650b Mon Sep 17 00:00:00 2001 From: EdwinYi-JanYang <51840314+EdwinYi-JanYang@users.noreply.github.com> Date: Fri, 28 Jan 2022 20:46:15 -0500 Subject: [PATCH 6/6] Update rollDice.ts --- src/commands/fun/rollDice.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/fun/rollDice.ts b/src/commands/fun/rollDice.ts index eb2b69cc..3f73d078 100644 --- a/src/commands/fun/rollDice.ts +++ b/src/commands/fun/rollDice.ts @@ -23,11 +23,11 @@ class RollDiceCommand extends BaseCommand { } getRandomInt(max: number): number { - return Math.floor(Math.random() * (max)) + 1; + return Math.floor(Math.random() * max) + 1; } - async onRun(message: CommandoMessage, args: {sides: number;}): Promise { - const {sides} = args; + async onRun(message: CommandoMessage, args: { sides: number }): Promise { + const { sides } = args; if (sides <= 0) { return message.reply(`I cannot compute ` + sides + ' sides!'); } @@ -39,4 +39,4 @@ class RollDiceCommand extends BaseCommand { } } -export default RollDiceCommand; \ No newline at end of file +export default RollDiceCommand;