From 47484ba7e26c3f3e4abae1b8b58a26036385e85a Mon Sep 17 00:00:00 2001 From: ThePendulum Date: Tue, 2 Jan 2024 16:15:37 +0100 Subject: [PATCH] Preventing ~solve when numbers game is in progress. --- src/games/numbers.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/games/numbers.js b/src/games/numbers.js index ec1f6d9..8af1a28 100644 --- a/src/games/numbers.js +++ b/src/games/numbers.js @@ -367,6 +367,11 @@ async function solve(equation, context) { return; } + if (Array.from(games.entries()).some(([roomId, game]) => roomId === context.room.id || game.target === target)) { + context.sendMessage('Nice try! Please wait for this numbers round to end :)', context.room.id); + return; + } + try { const solutions = await solveAll(numbers, target, 3); const bestSolution = solutions.reduce((closest, solution) => (!closest || Math.abs(target - solution.answer) < Math.abs(target - closest.answer) ? solution : closest), null); @@ -377,11 +382,11 @@ async function solve(equation, context) { } if (bestSolution.answer === target) { - context.sendMessage(`My best solution for ${numbers.join(' ')} = ${target} is: ${bestSolution.solution}`, context.room.id); + context.sendMessage(`My best solution for ${numbers.join(' ')} = ${target} is: ${style.bold(bestSolution.solution)}`, context.room.id); return; } - context.sendMessage(`I could not find an exact solution for ${numbers.join(' ')} = ${target}. My closest solution is: ${bestSolution.solution} = ${bestSolution.answer}`, context.room.id); + context.sendMessage(`I could not find an exact solution for ${numbers.join(' ')} = ${target}. My closest solution is: ${style.bold(bestSolution.solution)} = ${style.italic(bestSolution.answer)}`, context.room.id); } catch (error) { console.log(error); }