Compare commits
2
Commits
1572e74ebf
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
678b2991ad | ||
|
|
f048c1d077 |
Generated
+2
-2
@@ -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
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user