Compare commits
2 Commits
b161a29909
...
d4d736bb56
Author | SHA1 | Date |
---|---|---|
|
d4d736bb56 | |
|
5adb55692f |
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "schat2-clive",
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bhttp": "^1.2.8",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.0",
|
||||
"description": "Game host for SChat 2-powered chat sites",
|
||||
"main": "src/app.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -215,9 +215,11 @@ function getGames(bot) {
|
|||
const games = config.games.reduce((acc, key) => {
|
||||
const game = require(`./games/${key.game || key}`); // eslint-disable-line global-require, import/no-dynamic-require
|
||||
|
||||
const sendMessage = (body, roomId, options) => {
|
||||
const sendMessage = (body, roomId, options, recipient) => {
|
||||
bot.socket.transmit('message', {
|
||||
roomId,
|
||||
recipient,
|
||||
type: recipient ? 'whisper' : 'message',
|
||||
body: options?.label === false ? body : `[${game.name || key}] ${body}`,
|
||||
style: config.style,
|
||||
});
|
||||
|
|
|
@ -8,6 +8,11 @@ const questions = require('../../assets/jeopardy.json');
|
|||
const shuffle = require('../utils/shuffle');
|
||||
|
||||
const settings = { ...config.trivia };
|
||||
const help = {
|
||||
mode: '\'first\' or \'timeout\'',
|
||||
rounds: 'rounds per game as a number',
|
||||
timeout: 'seconds as a number',
|
||||
};
|
||||
|
||||
let game = null;
|
||||
|
||||
|
@ -85,7 +90,7 @@ async function playRound(context, round = 0) {
|
|||
}
|
||||
|
||||
if (game.mode === 'timeout') {
|
||||
context.sendMessage(`**STOP!** The correct answer is **${question.answer}**. ${scores}`, context.room.id);
|
||||
context.sendMessage(`**STOP!** The correct answer is **${question.fullAnswer || question.answer}**. ${scores}`, context.room.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,12 +161,20 @@ function onCommand(args, context) {
|
|||
context.sendMessage(`There is no game going on at the moment. Start one with ${config.prefix}trivia!`, context.room.id);
|
||||
}
|
||||
|
||||
if (['help', 'commands'].includes(context.subcommand)) {
|
||||
context.sendMessage(`Available subcommands for ${config.prefix}trivia are :stop, :mode, :rounds and :timeout`, context.room.id);
|
||||
}
|
||||
|
||||
const subcommand = context.subcommand?.toLowerCase();
|
||||
|
||||
if (subcommand && settings[subcommand]) {
|
||||
settings[subcommand] = typeof settings[subcommand] === 'number' ? (Number(args[0]) || settings[subcommand]) : args[0];
|
||||
if (args[0]) {
|
||||
settings[subcommand] = typeof settings[subcommand] === 'number' ? (Number(args[0]) || settings[subcommand]) : args[0];
|
||||
|
||||
context.sendMessage(`${subcommand} set to ${settings[subcommand]}`, context.room.id);
|
||||
context.sendMessage(`${subcommand} set to ${settings[subcommand]}`, context.room.id);
|
||||
} else if (help[subcommand]) {
|
||||
context.sendMessage(`Please give ${help[subcommand]}`, context.room.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +183,7 @@ async function onMessage(message, context) {
|
|||
return;
|
||||
}
|
||||
|
||||
const { answer } = game.questions[game.round];
|
||||
const { answer, fullAnswer } = game.questions[game.round];
|
||||
|
||||
if (new RegExp(answer, 'i').test(decode(message.originalBody || message.body))) { // resolve HTML entities in case original body is not available, such as & to &
|
||||
game.answers.push({
|
||||
|
@ -181,6 +194,14 @@ async function onMessage(message, context) {
|
|||
if (settings.mode === 'first') {
|
||||
game.ac.abort();
|
||||
}
|
||||
|
||||
if (settings.mode === 'timeout') {
|
||||
if (message.type === 'message') {
|
||||
context.sendMessage(`**${fullAnswer || answer}** is the correct answer! You might want to **/whisper** the answer to me instead, so others can't leech off your impeccable knowledge. You will receive a point at the end of the round.`, context.room.id, null, context.user.username);
|
||||
} else {
|
||||
context.sendMessage(`**${fullAnswer || answer}** is the correct answer! You will receive a point at the end of the round.`, context.room.id, null, context.user.username);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue