From 491170cad3d7ecc041a73a84955fc00fc33d62ab Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Sat, 4 Feb 2023 05:18:53 +1100 Subject: [PATCH] Change diceroll to avoid the immense pain of dealing with tryign to localise that because of remarkdowning --- lib/post/markdown/handler/diceroll.js | 7 +++---- lib/post/markdown/handler/diceroll.test.js | 21 +++++++++++---------- views/custompages/faq.pug | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/post/markdown/handler/diceroll.js b/lib/post/markdown/handler/diceroll.js index 1d2b459a..33f2178b 100644 --- a/lib/post/markdown/handler/diceroll.js +++ b/lib/post/markdown/handler/diceroll.js @@ -2,8 +2,8 @@ module.exports = { - regexPrepare: /##(?[1-9][0-9]{0,1})d(?1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?[+-])(?[1-9][0-9]{0,8}))?(?=[1-9][0-9]{0,8})?/gmi, - regexMarkdown: /##(?[1-9][0-9]{0,1})d(?1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?[+-])(?[1-9][0-9]{0,8}))?=(?[1-9][0-9]{0,8})/gmi, + regexPrepare: /##(?[1-9][0-9]{0,1})%(?1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?[+-])(?[1-9][0-9]{0,8}))?(?=[1-9][0-9]{0,8})?/gmi, + regexMarkdown: /##(?[1-9][0-9]{0,1})%(?1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?[+-])(?[1-9][0-9]{0,8}))?=(?[1-9][0-9]{0,8})/gmi, prepare: (force, match, numdice, numsides, operator, modifier, value) => { if (!force && value) { @@ -34,7 +34,6 @@ module.exports = { numdice = parseInt(numdice); numsides = parseInt(numsides); value = parseInt(value); - let matchWithoutValue = match.replace(/=.*/, ''); - return `(${matchWithoutValue}) Rolled ${numdice} dice with ${numsides} sides${modifier ? ' and modifier '+operator+modifier : '' } = ${value}`; + return `(##${numdice}%${numsides}${modifier ? operator+modifier : '' }) = ${value}`; }, }; diff --git a/lib/post/markdown/handler/diceroll.test.js b/lib/post/markdown/handler/diceroll.test.js index 23a3c256..bedb483e 100644 --- a/lib/post/markdown/handler/diceroll.test.js +++ b/lib/post/markdown/handler/diceroll.test.js @@ -3,12 +3,12 @@ const diceroll = require('./diceroll.js'); describe('diceroll markdown', () => { const prepareCases = [ - { in: '##3d6', out: '##3d6=' }, - { in: '##99d99', out: '##99d99=' }, - { in: '##999d999', out: '##999d999' }, - { in: '##3d8+5', out: '##3d8+5=' }, - { in: '##3d8-5', out: '##3d8-5=' }, - { in: '##0d0', out: '##0d0' }, + { in: '##3%6', out: '##3%6=' }, + { in: '##99%99', out: '##99%99=' }, + { in: '##999%999', out: '##999%999' }, + { in: '##3%8+5', out: '##3%8+5=' }, + { in: '##3%8-5', out: '##3%8-5=' }, + { in: '##0%0', out: '##0%0' }, ]; for(let i in prepareCases) { test(`should contain ${prepareCases[i].out} for an input of ${prepareCases[i].in}`, () => { @@ -18,10 +18,11 @@ describe('diceroll markdown', () => { } const markdownCases = [ - { in: '##3d6=10', out: 'Rolled 3 dice with 6 sides =' }, - { in: '##99d99=5138', out: 'Rolled 99 dice with 99 sides =' }, - { in: '##999d999=10000', out: '##999d999=10000' }, - { in: '##0d0', out: '##0d0' }, + { in: '##3%6=10', out: '(##3%6)' }, + { in: '##99%99=5138', out: '(##99%99)' }, + { in: '##999%999=10000', out: '##999%999=' }, + { in: '##0%0=10', out: '##0%0=' }, + { in: '##0%0', out: '##0%0' }, ]; for(let i in markdownCases) { test(`should contain ${markdownCases[i].out} for an input of ${markdownCases[i].in}`, () => { diff --git a/views/custompages/faq.pug b/views/custompages/faq.pug index 2886a7e9..898f9bb4 100644 --- a/views/custompages/faq.pug +++ b/views/custompages/faq.pug @@ -148,10 +148,10 @@ block content td span.detected ((( detected ))) tr - td ##2d9+3 + td ##2%9+3 td img(src='/file/dice.png' height='16' width='16') - span.dice (##2d9+3) Rolled 2 dice with 9 sides and modifier +3 = 10 + span.dice (##2%9+3) = 10 tr td https://example.com td: a(href='#!') https://example.com