Added PM support to chat.
This commit is contained in:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user