From 0cea6efa15197ef5ec7e49afb601db4d7aa00e79 Mon Sep 17 00:00:00 2001 From: ThePendulum Date: Thu, 8 Oct 2026 04:33:20 +0200 Subject: [PATCH] Added missing timeout commands and help. --- src/games/letters.js | 25 ++++++++++++++++++++++++- src/games/numbers.js | 2 +- src/games/riddle.js | 27 ++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/games/letters.js b/src/games/letters.js index 71fb465..1c4dcb9 100755 --- a/src/games/letters.js +++ b/src/games/letters.js @@ -64,6 +64,24 @@ function playWord(rawWord, context) { context.sendMessage(`${context.user.username} played ${style.bold(style.pink(word))} for ${style.bold(word.length)} points!`, context.room.id); } +function setTimeout(timeout, context) { + if (!timeout) { + context.sendMessage(`Timeout is set to ${style.bold(settings.timeout)}`, context.room.id); + return; + } + + const parsedTimeout = Number(timeout); + + if (Number.isNaN(parsedTimeout) || parsedTimeout < 10 || parsedTimeout > 300) { + context.sendMessage('Timeout must be a number between 10 and 300', context.room.id); + return; + } + + settings.timeout = parsedTimeout; + + context.sendMessage(`Timeout set to ${style.bold(settings.timeout)} by ${context.user.prefixedUsername}`, context.room.id); +} + function stop(context, aborted) { const game = games.get(context.room.id); @@ -163,6 +181,11 @@ function onCommand(args, context) { return; } + if (context.subcommand === 'timeout') { + setTimeout(args[0], context); + return; + } + if (context.command === 'letsgo' || ['start', 'go', 'auto', 'random'].includes(context.subcommand)) { start(context, Array.from({ length: config.letters.length }, () => (Math.random() < config.letters.consonantBias ? 'c' : 'v')).join('')); // a slight bias towards consonants seems to give better boards return; @@ -206,7 +229,7 @@ function onMessage(message, context) { module.exports = { name: 'Letters', - help: `Make the longest word from the ${config.letters.length} letters on the board. Quick-start with ${config.prefix}letsgo, or use ${config.prefix}letters to fill the board by manually selecting a vow(el), a con(sonant), or multiple at once like CCVVCCVVC.`, + help: `Make the longest word from the ${config.letters.length} letters on the board. Quick-start with ${config.prefix}letsgo, or use ${config.prefix}letters to fill the board by manually selecting a vow(el), a con(sonant), or multiple at once like CCVVCCVVC. Change the time limit with ${config.prefix}letters:timeout [10-300].`, commands: ['letsgo'], onCommand, onMessage, diff --git a/src/games/numbers.js b/src/games/numbers.js index 8af1a28..058a8ac 100644 --- a/src/games/numbers.js +++ b/src/games/numbers.js @@ -455,5 +455,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 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 + 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. Change the time limit with ${config.prefix}numbers:timeout [10-300].`, // eslint-disable-line max-len }; diff --git a/src/games/riddle.js b/src/games/riddle.js index 156cbcb..70abfae 100644 --- a/src/games/riddle.js +++ b/src/games/riddle.js @@ -7,11 +7,35 @@ const timers = require('timers/promises'); const riddles = require('../../assets/riddles.json'); const style = require('../utils/style'); +const settings = { ...config.riddle }; const open = new Map(); const emojis = ['😆', 'ðŸĪĢ', '😂', '😅', 'ðŸĪŠ', '😛', '😝', '🙃', 'ðŸĨē', 'ðŸĪ­', '😏', 'ðŸĨī', '💀', 'ðŸĪĶ']; +function setTimeout(timeout, context) { + if (!timeout) { + context.sendMessage(`Timeout is set to ${style.bold(settings.timeout)}`, context.room.id); + return; + } + + const parsedTimeout = Number(timeout); + + if (Number.isNaN(parsedTimeout) || parsedTimeout < 10 || parsedTimeout > 300) { + context.sendMessage('Timeout must be a number between 10 and 300', context.room.id); + return; + } + + settings.timeout = parsedTimeout; + + context.sendMessage(`Timeout set to ${style.bold(settings.timeout)} by ${context.user.prefixedUsername}`, context.room.id); +} + async function onCommand(args, context) { + if (context.subcommand === 'timeout') { + setTimeout(args[0], context); + return; + } + if (open.has(context.room.id)) { context.sendMessage(open.get(context.room.id).riddle, context.room.id); return; @@ -26,7 +50,7 @@ async function onCommand(args, context) { context.logger.info(`Riddle asked "${riddle.riddle}" with answer: ${riddle.answers[0]}`); try { - await timers.setTimeout(config.riddle.timeout * 1000, null, { signal: ac.signal }); + await timers.setTimeout(settings.timeout * 1000, null, { signal: ac.signal }); open.delete(context.room.id); context.sendMessage(`No one guessed the riddle: ${style.bold(riddle.fullAnswer)}! ${emojis[crypto.randomInt(0, emojis.length)]}`, context.room.id); @@ -54,6 +78,7 @@ function onMessage(message, context) { } module.exports = { + help: `Solve the riddle before time runs out! Ask for one with ${config.prefix}riddle, and answer by typing it in the chat. Change the time limit with ${config.prefix}riddle:timeout [10-300].`, onCommand, onMessage, };