Supported 1d6 dice input.

This commit is contained in:
ThePendulum 2022-10-24 02:37:32 +02:00
parent c63f05fcf5
commit 313b473aba
1 changed files with 12 additions and 0 deletions

View File

@ -8,9 +8,21 @@ const style = require('../utils/style');
const dieFaces = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅']; const dieFaces = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅'];
function onCommand(args, context) { 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 rolls = Number(args[0]) || 1;
const faces = Number(args[1]) || 6; 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) { if (rolls > config.dice.maxRolls) {
context.sendMessage(`You can only roll ${config.dice.maxRolls} dice at one time`, context.room.id); context.sendMessage(`You can only roll ${config.dice.maxRolls} dice at one time`, context.room.id);
return; return;