From 313b473abab6fe929680c3358a6e686a541a4824 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Mon, 24 Oct 2022 02:37:32 +0200 Subject: [PATCH] Supported 1d6 dice input. --- src/games/dice.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/games/dice.js b/src/games/dice.js index 33ce346..3383bc0 100644 --- a/src/games/dice.js +++ b/src/games/dice.js @@ -8,9 +8,21 @@ const style = require('../utils/style'); const dieFaces = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅']; function onCommand(args, context) { + const pattern = args[0]?.match(/(\d+)?d(\d+)?/i); + + if (pattern) { + onCommand(pattern.slice(1), context); + return; + } + const rolls = Number(args[0]) || 1; const faces = Number(args[1]) || 6; + if (rolls < 1 || faces < 1) { + context.sendMessage('The dice must exist in the physical universe.', context.room.id); + return; + } + if (rolls > config.dice.maxRolls) { context.sendMessage(`You can only roll ${config.dice.maxRolls} dice at one time`, context.room.id); return;