Added PM support to chat.

This commit is contained in:
Niels Simenon
2023-04-11 00:37:03 +02:00
parent ee50935339
commit da9c85d90c
6 changed files with 76 additions and 33 deletions

View File

@@ -44,7 +44,7 @@ mathImport({
divide,
}, { override: true });
const settings = config.numbers;
const settings = { ...config.numbers };
const games = new Map();
/* eslint-disable no-irregular-whitespace */
@@ -89,6 +89,24 @@ function countNumbers(numbers) {
return numbers.reduce((acc, number) => ({ ...acc, [number]: (acc[number] || 0) + 1 }), {});
}
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 getWinnerText(game) {
if (game.state === 'pick') {
return null;
@@ -327,6 +345,11 @@ function onCommand(args, context) {
return;
}
if (context.subcommand === 'timeout') {
setTimeout(args[0], context);
return;
}
if (['calculate', 'calc', 'solve'].includes(context.subcommand || context.command)) {
solve(args.join(' '), context); // two from the top, four from the bottom, please Rachel
return;
@@ -343,7 +366,7 @@ function onCommand(args, context) {
}
function onMessage(message, context) {
const game = games.get(context.room.id);
const game = games.get(context.room?.id);
const body = message.originalBody || message.body; // * gets resolved to <em>
if (game?.state === 'pick') {