From 809e79affe33bac8b1ca23f60dd0f6b827b3f9f2 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Fri, 28 Oct 2022 03:26:36 +0200 Subject: [PATCH] Improved 8-ball punctuation handling. --- src/games/8ball.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/games/8ball.js b/src/games/8ball.js index 5ab64f0..241be5c 100644 --- a/src/games/8ball.js +++ b/src/games/8ball.js @@ -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\p{P}]+\s+[\w\p{P}]+\?/.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\\p{P}]+\\s+[\\w, \\p{P}]+.*\\?`, '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);