Added riddles.
This commit is contained in:
parent
8b75691c5f
commit
33c7b25bd2
|
@ -0,0 +1,19 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const riddles = require('./riddles.json');
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
const answers = new Map();
|
||||||
|
|
||||||
|
riddles.forEach((riddle) => {
|
||||||
|
riddle.answers.forEach((answer) => {
|
||||||
|
if (answers.has(answer)) {
|
||||||
|
console.log(`Possible duplicate, answer '${answer}' for ${riddle.riddle} ||| ${answers.get(answer).riddle}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
answers.set(answer, riddle);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
1173
assets/riddles.json
1173
assets/riddles.json
File diff suppressed because it is too large
Load Diff
|
@ -57,6 +57,10 @@ module.exports = {
|
||||||
length: 9,
|
length: 9,
|
||||||
timeout: 60,
|
timeout: 60,
|
||||||
},
|
},
|
||||||
|
riddle: {
|
||||||
|
timeout: 10000,
|
||||||
|
score: false,
|
||||||
|
},
|
||||||
dice: {
|
dice: {
|
||||||
maxRolls: 10,
|
maxRolls: 10,
|
||||||
maxFaces: 1000,
|
maxFaces: 1000,
|
||||||
|
|
|
@ -1,12 +1,59 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const config = require('config');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const timers = require('timers/promises');
|
||||||
|
|
||||||
const riddles = require('../../assets/riddles.json');
|
const riddles = require('../../assets/riddles.json');
|
||||||
|
const style = require('../utils/style');
|
||||||
|
|
||||||
const open = new Map();
|
const open = new Map();
|
||||||
|
|
||||||
function onCommand(args, context) {
|
const emojis = ['😆', '🤣', '😂', '😅', '🤪', '😛', '😝', '🙃', '🥲', '🤭', '😏', '🥴', '💀', '🤦'];
|
||||||
|
|
||||||
|
async function onCommand(args, context) {
|
||||||
|
if (open.has(context.room.id)) {
|
||||||
|
context.sendMessage(open.get(context.room.id).riddle, context.room.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const riddle = riddles[crypto.randomInt(0, riddles.length)];
|
||||||
|
const ac = new AbortController(); // eslint-disable-line no-undef
|
||||||
|
|
||||||
|
open.set(context.room.id, { ...riddle, ac });
|
||||||
|
|
||||||
|
context.sendMessage(riddle.riddle, context.room.id);
|
||||||
|
context.logger.info(`Riddle asked "${riddle.riddle}" with answer: ${riddle.answers[0]}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await timers.setTimeout(config.riddle.timeout, null, { signal: ac.signal });
|
||||||
|
|
||||||
|
open.delete(context.room.id);
|
||||||
|
context.sendMessage(`No one guessed the riddle: ${style.bold(riddle.fullAnswer)}! ${emojis[crypto.randomInt(0, emojis.length)]}`, context.room.id);
|
||||||
|
} catch (error) {
|
||||||
|
// timer aborted because someone guessed the answer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMessage(message, context) {
|
||||||
|
const riddle = open.get(context.room?.id);
|
||||||
|
|
||||||
|
if (riddle && riddle.answers.some((answer) => new RegExp(`\\b${answer}s?\\b`, 'i').test(message.body))) {
|
||||||
|
riddle.ac.abort();
|
||||||
|
open.delete(context.room.id);
|
||||||
|
|
||||||
|
if (config.riddle.score) {
|
||||||
|
context.setPoints(context.user, 1);
|
||||||
|
context.sendMessage(`${style.bold(style.yellow(riddle.fullAnswer))} is the right answer! ${context.user.prefixedUsername} gets a point.`, context.room.id);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.sendMessage(`${style.bold(riddle.fullAnswer)} is the right answer!`, context.room.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
onCommand,
|
onCommand,
|
||||||
|
onMessage,
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,7 +61,7 @@ function getPoints(game, rawUsername, { user, room, command }) {
|
||||||
? Object.entries(gamePoints || {}).find(([identifier]) => identifier.split(':')[1] === username)?.[1]
|
? Object.entries(gamePoints || {}).find(([identifier]) => identifier.split(':')[1] === username)?.[1]
|
||||||
: gamePoints?.[`${user?.id}:${user?.username}`];
|
: gamePoints?.[`${user?.id}:${user?.username}`];
|
||||||
|
|
||||||
game.sendMessage(`${username ? `${style.bold(username)} has` : 'You have'} scored ${style.bold(userPoints || 0)} points in ${game.name}, ${config.usernamePrefix}${user.username}`, room.id);
|
game.sendMessage(`${username ? `${style.bold(username)} has` : 'You have'} scored ${style.bold(userPoints || 'no')} points in ${game.name}, ${config.usernamePrefix}${user.username}`, room.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLeaderboard(game, { user, room, command }) {
|
function getLeaderboard(game, { user, room, command }) {
|
||||||
|
|
Loading…
Reference in New Issue