Allow arithmetic functions in numbers.
This commit is contained in:
parent
fcd1597707
commit
d263c42d38
|
@ -30,7 +30,7 @@ function divide(a, b) {
|
||||||
const result = math.divide(a, b);
|
const result = math.divide(a, b);
|
||||||
|
|
||||||
if (result % 1) {
|
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;
|
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 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) => {
|
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`);
|
throw new RuleError(`The ${style.bold(node.name)} function is not allowed`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,5 +405,5 @@ module.exports = {
|
||||||
onCommand,
|
onCommand,
|
||||||
onMessage,
|
onMessage,
|
||||||
commands: ['nums', 'numsgo', 'numgo', 'calculate', 'calc', 'solve'],
|
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
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue