Compare commits

..

No commits in common. "22e51146472bba11454c41ed5a4ddc219157cef3" and "43478b3cc6a5a5e2aa7ad1af7d4c4fac02d94ba8" have entirely different histories.

3 changed files with 14 additions and 47 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "schat2-clive",
"version": "1.19.7",
"version": "1.19.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.19.7",
"version": "1.19.6",
"license": "ISC",
"dependencies": {
"bhttp": "^1.2.8",

View File

@ -1,6 +1,6 @@
{
"name": "schat2-clive",
"version": "1.19.7",
"version": "1.19.6",
"description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js",
"scripts": {

View File

@ -40,23 +40,21 @@ function scoreRound(context, round) {
async function playRound(context, round = 0) {
const game = games.get(context.room.id);
const ac = new AbortController(); // eslint-disable-line no-undef
const now = new Date();
game.answers = new Map();
game.round = round;
game.skipped = null;
game.ac = new AbortController(); // eslint-disable-line no-undef
game.ac = ac;
const question = game.questions[round];
// ASK QUESTION
context.sendMessage(`${style.bold(style.pink(`Question ${round + 1}/${game.questions.length}`))} ${style.grey(`(${question.category})`)}: ${question.question}`, context.room.id);
context.logger.info(`Trivia asked "${question.question}" with answer: ${question.answer}`);
try {
// SEND HINTS
await timers.setTimeout((game.timeout / 3) * 1000, null, {
signal: game.ac.signal,
signal: ac.signal,
});
// replace space with U+2003 Em Space to separate words, since a single space separates the placeholders, and double spaces are removed during Markdown render
@ -68,7 +66,7 @@ async function playRound(context, round = 0) {
}
await timers.setTimeout((game.timeout / 3) * 1000, null, {
signal: game.ac.signal,
signal: ac.signal,
});
if (question.answer.length >= 4) {
@ -76,29 +74,24 @@ async function playRound(context, round = 0) {
}
await timers.setTimeout((game.timeout / 3) * 1000, null, {
signal: game.ac.signal,
signal: ac.signal,
});
} catch (error) {
// abort expected, probably not an error
}
/* not sure why this was deemed necessary, the timeouts should be either finalized or aborted already
if (!ac.signal.aborted) {
ac.abort();
}
*/
// EVALUATE RESULTS
if (game.stopped) {
context.sendMessage(`The game was stopped by ${style.cyan(game.stopped)}. The answer to the last question was: ${style.bold(question.answer)}. Best players: ${getLeaders(game.points)}`, context.room.id);
context.sendMessage(`The game was stopped by ${style.cyan(`${config.usernamePrefix}${game.stopped.username}`)}. The answer to the last question was: ${style.bold(question.answer)}. Best players: ${getLeaders(game.points)}`, context.room.id);
games.delete(context.room.id);
return;
}
if (game.skipped) {
context.sendMessage(`The question was skipped by ${style.cyan(game.skipped)}. The answer was: ${style.bold(question.answer)}.`, context.room.id);
} else if (game.answers.size === 0) {
if (game.answers.size === 0) {
context.sendMessage(`${style.bold(style.red('TIME\'S UP!'))} No one guessed the answer: ${style.bold(question.answer)}`, context.room.id);
} else {
const scores = scoreRound(context, round);
@ -112,22 +105,11 @@ async function playRound(context, round = 0) {
}
}
// COOL DOWN AND RESTART
if (round < game.questions.length - 1) {
// present abort controller is expended if the question was answered or skipped
game.ac = new AbortController(); // eslint-disable-line no-undef
try {
await timers.setTimeout(5000, null, {
signal: game.ac.signal,
});
} catch (error) {
// abort expected, probably not an error
}
await timers.setTimeout(5000);
if (game.stopped) {
// stop was used between questions
context.sendMessage(`The game was stopped by ${style.cyan(game.stopped)}. The answer to the last question was: ${style.bold(question.answer)}. Best players: ${getLeaders(game.points)}`, context.room.id);
context.sendMessage(`The game was stopped by ${config.usernamePrefix}${game.stopped.username}. The answer to the last question was: ${style.bold(question.answer)}. Best players: ${getLeaders(game.points)}`, context.room.id);
games.delete(context.room.id);
return;
@ -161,15 +143,7 @@ async function start(context) {
async function stop(context) {
const game = games.get(context.room.id);
game.stopped = context.user.prefixedUsername;
game.ac.abort();
}
async function skip(context) {
const game = games.get(context.room.id);
// game.stopped = context.user;
game.skipped = context.user.prefixedUsername;
game.stopped = context.user;
game.ac.abort();
}
@ -188,17 +162,10 @@ function onCommand(args, context) {
if (context.subcommand === 'stop' && game) {
stop(context);
return;
}
if (context.subcommand === 'skip' && game) {
skip(context);
return;
}
if (['stop', 'skip'].includes(context.subcommand) && !game) {
if (context.subcommand === 'stop' && !game) {
context.sendMessage(`There is no game going on at the moment. Start one with ${config.prefix}trivia!`, context.room.id);
return;
}
const subcommand = context.subcommand?.toLowerCase();