Compare commits

...

3 Commits

Author SHA1 Message Date
Niels Simenon dc6df7c344 Added letter generator to letters game. 2022-10-28 03:44:09 +02:00
Niels Simenon 809e79affe Improved 8-ball punctuation handling. 2022-10-28 03:26:36 +02:00
Niels Simenon 335bd55a91 Accepting punctuation as part of a 8ball question. 2022-10-28 03:17:09 +02:00
3 changed files with 17 additions and 5 deletions

View File

@ -21,7 +21,7 @@ module.exports = {
greeting: 'Hi, I am aisha, your game host!',
usernamePrefix: '@',
channels: ['GamesNight'],
games: ['mash', 'trivia', 'letters', 'duck', '8ball', 'dice', 'rock-paper-scissors', 'ping', 'say', 'kill', 'uptime', 'help'],
games: ['mash', 'trivia', 'letters', 'duck', '8ball', 'riddle', 'dice', 'rock-paper-scissors', 'ping', 'say', 'kill', 'uptime', 'help'],
schatColors: {
white: 'white',
blue: 'var(--message-40)',

View File

@ -9,8 +9,10 @@ const style = require('../utils/style');
const contemplations = [
'Hmmm...',
'Let me see...',
'Let me give that some thought',
'🤔',
'Let\'s see...',
'💭',
];
const answersByType = {
@ -56,7 +58,7 @@ function purgeQuestions() {
async function onCommand(args, context) {
const question = args.join(' ');
if (!/\w+\s+\w+\?/.test(question)) {
if (!/[\w\p{P}]+\s+[\w\p{P}]+\?/u.test(question)) {
context.sendMessage('Please ask me a question, any question...', context.room.id);
return;
}
@ -93,7 +95,7 @@ async function onCommand(args, context) {
}
function onMessage(message, context) {
const regex = new RegExp(`^${config.usernamePrefix}${config.user.username}:?\\s+\\w+\\s+\\w+.*\\?`, 'i');
const regex = new RegExp(`^${config.usernamePrefix}${config.user.username}[\\s\\p{P}]*\\s+[\\w\\p{P}]+\\s+[\\w, \\p{P}]+.*\\?`, 'ui');
if (regex.test(message.body)) {
onCommand([message.body.replaceAll(`${config.usernamePrefix}${config.user.username}:?`, '').trim()], context, false);

View File

@ -122,7 +122,7 @@ function pickLetters(type, context) {
context.sendMessage(`${getBoard(context)} Would you like a consonant or a vowel?`, context.room.id);
}
function start(context) {
function start(context, letters) {
if (games.has(context.room.id)) {
context.sendMessage(`${getBoard(context)} This is the current board. Use ${config.prefix}letters:stop to reset.`, context.room.id);
return;
@ -136,6 +136,11 @@ function start(context) {
ac: new AbortController(), // eslint-disable-line no-undef
});
if (letters) {
pickLetters(letters.toLowerCase(), context);
return;
}
context.sendMessage('Let\'s play the letters! Would you like a consonant or a vowel?', context.room.id);
}
@ -145,6 +150,11 @@ function onCommand(args, context) {
return;
}
if (['start', 'go', 'auto', 'random'].includes(context.subcommand)) {
start(context, Array.from({ length: config.letters.length }, () => (Math.random() < 0.55 ? 'c' : 'v')).join('')); // a slight bias towards consonants seems to give better boards
return;
}
if (!context.subcommand) {
start(context);
}