Compare commits

...
2 Commits
Author SHA1 Message Date
ThePendulum 678b2991ad 1.31.3 2026-10-18 02:15:24 +02:00
ThePendulum f048c1d077 Escaping trivia dataset before passing it into regex. 2026-10-18 02:15:23 +02:00
3 changed files with 13 additions and 4 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "schat2-clive",
"version": "1.31.2",
"version": "1.31.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.31.2",
"version": "1.31.3",
"license": "ISC",
"dependencies": {
"better-sqlite3": "^13.0.3",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "schat2-clive",
"version": "1.31.2",
"version": "1.31.3",
"description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js",
"scripts": {
+10 -1
View File
@@ -226,6 +226,15 @@ function onCommand(args, context) {
}
}
// answers are plain text and may contain regex characters, like '*batteries not included'
function getAnswerRegexp(answer) {
const pattern = answer
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
.replace(/\\[.?*]|!/g, '$&?'); // punctuation is optional, so T.S. Eliot also matches TS Eliot, and *NSYNC matches NSYNC
return new RegExp(pattern, 'i');
}
async function onMessage(message, context) {
const game = games.get(context.room?.id);
@@ -235,7 +244,7 @@ async function onMessage(message, context) {
const { answer, fullAnswer } = game.questions[game.round];
if (new RegExp(answer, 'i').test(decode(message.originalBody || message.body)) && !game.answers.has(context.user.id)) { // resolve HTML entities in case original body is not available, such as & to &
if (getAnswerRegexp(answer).test(decode(message.originalBody || message.body)) && !game.answers.has(context.user.id)) { // resolve HTML entities in case original body is not available, such as & to &
game.answers.set(context.user.id, {
user: context.user,
answer: message.body,