From d263c42d38971a42c7de1e9cac28b2a5dc50ab19 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Wed, 12 Apr 2023 17:17:49 +0200 Subject: [PATCH] Allow arithmetic functions in numbers. --- src/games/numbers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/games/numbers.js b/src/games/numbers.js index 892305d..518e35d 100644 --- a/src/games/numbers.js +++ b/src/games/numbers.js @@ -30,7 +30,7 @@ function divide(a, b) { const result = math.divide(a, b); if (result % 1) { - throw new RuleError(`The division ${style.bold(style.code(`${a} / ${b}`))} resulting in a fraction is not allowed`); + throw new RuleError(`The division ${style.bold(style.code(`${a} / ${b}`))} results in a fraction, which is not allowed`); } return result; @@ -239,7 +239,7 @@ function playSolution(solution, context) { const parsed = limitedMath.parse(solution.replace(/`/g, '')); // backticks may be used to prevent the expression from being expanded by Markdown in SChat const numbers = parsed.filter((node) => { - if (node.type === 'FunctionNode') { + if (node.type === 'FunctionNode' && !['add', 'subtract', 'multiply', 'divide'].includes(node.fn.name)) { throw new RuleError(`The ${style.bold(node.name)} function is not allowed`); } @@ -405,5 +405,5 @@ module.exports = { onCommand, onMessage, commands: ['nums', 'numsgo', 'numgo', 'calculate', 'calc', 'solve'], - help: `Reach the target number using only the ${config.numbers.length} numbers on the board. You can use each number only once, but do not have to use all of them. You may use addition, subtraction, multiplication and divisions, but each intermediate calculation must result in a whole number. You can score ${Array.from(new Set(config.numbers.points)).slice(0, -1).join(', ')} or ${config.numbers.points.at(-1)} points for solutions up to ${config.numbers.points.length - 1} away, but only the first best solution gets the points. Quick-start with ${config.prefix}numsgo, or use ${config.prefix}numbers to fill the board by manually selecting a random *large* or *big* number (100, 75, 50, 25), a random *small* number (1-10), or multiple at once like LLSSSS.`, // eslint-disable-line max-len + help: `Reach the target number using only the ${config.numbers.length} numbers on the board. You can use each number only once, but do not have to use all of them. You may use addition, subtraction, multiplication and division, but each intermediate calculation must result in a whole number. You can score ${Array.from(new Set(config.numbers.points)).slice(0, -1).join(', ')} or ${config.numbers.points.at(-1)} points for solutions up to ${config.numbers.points.length - 1} away, but only the first best solution gets the points. Quick-start with ${config.prefix}numsgo, or use ${config.prefix}numbers to fill the board by manually selecting a random *large* or *big* number (100, 75, 50, 25), a random *small* number (1-10), or multiple at once like LLSSSS.`, // eslint-disable-line max-len };