From c1cff0284d12e41667e0d569dbd01cd412e1b18a Mon Sep 17 00:00:00 2001 From: fatchan Date: Sun, 8 Mar 2020 04:18:52 +0100 Subject: [PATCH] improve dicerolls, uncomment invalid quotes --- helpers/posting/diceroll.js | 18 ++---------------- helpers/posting/markdown.js | 2 +- helpers/posting/quotes.js | 12 ++++-------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/helpers/posting/diceroll.js b/helpers/posting/diceroll.js index 6bfd758d..66d964f4 100644 --- a/helpers/posting/diceroll.js +++ b/helpers/posting/diceroll.js @@ -2,22 +2,8 @@ module.exports = (match, numdice, numsides, operator, modifier) => { numdice = parseInt(numdice); - if (numdice > 100) { - numdice = 100; - } else if (numdice <= 0) { - numdice = 1; - } numsides = parseInt(numsides); - if (numsides > 100) { - numsides = 100; - } else if (numsides <= 0) { - numsides = 1; - } - let sum = 0; - for (let i = 0; i < numdice; i++) { - const roll = Math.floor(Math.random() * numsides)+1; - sum += roll; - } + let sum = (Math.floor(Math.random() * numsides) + 1) * numdice; if (modifier && operator) { modifier = parseInt(modifier); //do i need to make sure it doesnt go negative or maybe give absolute value? @@ -27,5 +13,5 @@ module.exports = (match, numdice, numsides, operator, modifier) => { sum -= modifier; } } - return `\n(${match}) Rolled ${numdice} dice with ${numsides} sides${modifier ? ' and modifier '+operator+modifier : '' } = ${sum}\n`; + return `(${match}) Rolled ${numdice} dice with ${numsides} sides${modifier ? ' and modifier '+operator+modifier : '' } = ${sum}`; } diff --git a/helpers/posting/markdown.js b/helpers/posting/markdown.js index 4438bfc9..778462e8 100644 --- a/helpers/posting/markdown.js +++ b/helpers/posting/markdown.js @@ -14,7 +14,7 @@ const greentextRegex = /^>((?!>\d+|>>/\w+(/\d*)?).*)/gm , codeRegex = /(?:(?[a-z+]{1,10})\r?\n)?(?[\s\S]+)/i , splitRegex = /```([\s\S]+?)```/gm , trimNewlineRegex = /^\s*(\r?\n)*|(\r?\n)*$/g - , diceRegex = /##(?\d+)d(?\d+)(?:(?[+-])(?\d+))?/gmi + , diceRegex = /##(?[1-9][0-9]{0,8})d(?[2-9][0-9]{0,8})(?:(?[+-])(?[1-9][0-9]{0,8}))?/gmi , getDomain = (string) => string.split(/\/\/|\//)[1] //unused atm , escape = require(__dirname+'/escape.js') , { highlight, highlightAuto } = require('highlight.js') diff --git a/helpers/posting/quotes.js b/helpers/posting/quotes.js index 9252b95d..4f7fd9d9 100644 --- a/helpers/posting/quotes.js +++ b/helpers/posting/quotes.js @@ -101,19 +101,15 @@ module.exports = async (board, text, thread) => { } return `>>${quotenum}${postThreadIdMap[board][quotenum].postId == thread ? ' (OP) ' : ''}`; } - return match;//`>>${quotenum}`; + return `>>${quotenum}`; }); } if (crossQuotes) { text = text.replace(crossQuoteRegex, (match, quoteboard, quotenum) => { - if (postThreadIdMap[quoteboard]) { - if (!isNaN(quotenum) && quotenum > 0 && postThreadIdMap[quoteboard][quotenum]) { - return `>>>/${quoteboard}/${quotenum}`; - } else { - return `>>>/${quoteboard}/`; - } + if (postThreadIdMap[quoteboard] && !isNaN(quotenum) && quotenum > 0 && postThreadIdMap[quoteboard][quotenum]) { + return `>>>/${quoteboard}/${quotenum}`; } - return match;// `>>>/${quoteboard}/`; + return `>>>/${quoteboard}/${quotenum || ''}`; }); }