Resolve message body HTML entities in Trivia bot.

This commit is contained in:
ThePendulum 2021-11-15 20:29:13 +01:00
parent 0870ac9352
commit a5fb878192
3 changed files with 14 additions and 1 deletions

11
package-lock.json generated
View File

@ -12,6 +12,7 @@
"bhttp": "^1.2.8", "bhttp": "^1.2.8",
"bottleneck": "^2.19.5", "bottleneck": "^2.19.5",
"config": "^3.3.6", "config": "^3.3.6",
"html-entities": "^2.3.2",
"jsdom": "^18.1.0", "jsdom": "^18.1.0",
"linkify-it": "^3.0.3", "linkify-it": "^3.0.3",
"simple-node-logger": "^21.8.12", "simple-node-logger": "^21.8.12",
@ -1906,6 +1907,11 @@
"node": ">=12" "node": ">=12"
} }
}, },
"node_modules/html-entities": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.3.2.tgz",
"integrity": "sha512-c3Ab/url5ksaT0WyleslpBEthOzWhrjQbg75y7XUsfSzi3Dgzt0l8w5e7DylRn15MTlMMD58dTfzddNS2kcAjQ=="
},
"node_modules/http-proxy-agent": { "node_modules/http-proxy-agent": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz",
@ -5159,6 +5165,11 @@
"whatwg-encoding": "^2.0.0" "whatwg-encoding": "^2.0.0"
} }
}, },
"html-entities": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.3.2.tgz",
"integrity": "sha512-c3Ab/url5ksaT0WyleslpBEthOzWhrjQbg75y7XUsfSzi3Dgzt0l8w5e7DylRn15MTlMMD58dTfzddNS2kcAjQ=="
},
"http-proxy-agent": { "http-proxy-agent": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz",

View File

@ -21,6 +21,7 @@
"bhttp": "^1.2.8", "bhttp": "^1.2.8",
"bottleneck": "^2.19.5", "bottleneck": "^2.19.5",
"config": "^3.3.6", "config": "^3.3.6",
"html-entities": "^2.3.2",
"jsdom": "^18.1.0", "jsdom": "^18.1.0",
"linkify-it": "^3.0.3", "linkify-it": "^3.0.3",
"simple-node-logger": "^21.8.12", "simple-node-logger": "^21.8.12",

View File

@ -2,6 +2,7 @@
const config = require('config'); const config = require('config');
const timers = require('timers/promises'); const timers = require('timers/promises');
const { decode } = require('html-entities');
const questions = require('../../assets/jeopardy.json'); const questions = require('../../assets/jeopardy.json');
const shuffle = require('../utils/shuffle'); const shuffle = require('../utils/shuffle');
@ -171,7 +172,7 @@ async function onMessage(message, context) {
const { answer } = game.questions[game.round]; const { answer } = game.questions[game.round];
if (new RegExp(answer, 'i').test(message.body)) { if (new RegExp(answer, 'i').test(decode(message.body))) { // resolve HTML entities, such as & to &
game.answers.push({ game.answers.push({
user: context.user, user: context.user,
answer: message.body, answer: message.body,