Added whisper option. Whispering answer feedback in Trivia timeout mode, added command help.
This commit is contained in:
parent
b161a29909
commit
5adb55692f
|
@ -215,9 +215,11 @@ function getGames(bot) {
|
||||||
const games = config.games.reduce((acc, key) => {
|
const games = config.games.reduce((acc, key) => {
|
||||||
const game = require(`./games/${key.game || key}`); // eslint-disable-line global-require, import/no-dynamic-require
|
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', {
|
bot.socket.transmit('message', {
|
||||||
roomId,
|
roomId,
|
||||||
|
recipient,
|
||||||
|
type: recipient ? 'whisper' : 'message',
|
||||||
body: options?.label === false ? body : `[${game.name || key}] ${body}`,
|
body: options?.label === false ? body : `[${game.name || key}] ${body}`,
|
||||||
style: config.style,
|
style: config.style,
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,11 @@ const questions = require('../../assets/jeopardy.json');
|
||||||
const shuffle = require('../utils/shuffle');
|
const shuffle = require('../utils/shuffle');
|
||||||
|
|
||||||
const settings = { ...config.trivia };
|
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;
|
let game = null;
|
||||||
|
|
||||||
|
@ -85,7 +90,7 @@ async function playRound(context, round = 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.mode === 'timeout') {
|
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);
|
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();
|
const subcommand = context.subcommand?.toLowerCase();
|
||||||
|
|
||||||
if (subcommand && settings[subcommand]) {
|
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;
|
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 &
|
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({
|
game.answers.push({
|
||||||
|
@ -181,6 +194,14 @@ async function onMessage(message, context) {
|
||||||
if (settings.mode === 'first') {
|
if (settings.mode === 'first') {
|
||||||
game.ac.abort();
|
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