Added missing timeout commands and help.

This commit is contained in:
ThePendulum
2026-10-08 04:33:20 +02:00
parent 3a678130a1
commit 0cea6efa15
3 changed files with 51 additions and 3 deletions
+24 -1
View File
@@ -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,
+1 -1
View File
@@ -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
};
+26 -1
View File
@@ -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,
};