Improved 8-ball punctuation handling.

This commit is contained in:
Niels Simenon 2022-10-28 03:26:36 +02:00
parent 335bd55a91
commit 809e79affe
1 changed files with 5 additions and 3 deletions

View File

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