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 = [
'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);