Catch NSFW rooms with underscores

This commit is contained in:
Eric Eastwood 2023-05-23 12:22:01 -05:00
parent f05d36e9f4
commit b500134245
2 changed files with 26 additions and 1 deletions

View File

@ -1,7 +1,7 @@
'use strict';
const NSFW_WORDS = ['nsfw', 'porn', 'nudes', 'sex', '18+'];
const NSFW_REGEXES = NSFW_WORDS.map((word) => new RegExp(`\\b${word}\\b`, 'i'));
const NSFW_REGEXES = NSFW_WORDS.map((word) => new RegExp(`(\\b|_)${word}(\\b|_)`, 'i'));
// A very basic check for NSFW content that just looks for some keywords in the given
// text

View File

@ -0,0 +1,25 @@
'use strict';
const assert = require('assert');
const checkTextForNsfw = require('matrix-public-archive-shared/lib/check-text-for-nsfw');
describe('checkTextForNsfw', () => {
Object.entries({
nsfw: true,
'foo NSFW bar': true,
foo_NSFW_bar: true,
'foo:NSFW:bar': true,
NSFW_foo: true,
'NSFW-foo': true,
'NSFW:foo': true,
}).forEach(([inputText, expectedNsfw]) => {
it(`should return ${expectedNsfw} for '${inputText}'`, () => {
assert.strictEqual(
checkTextForNsfw(inputText),
expectedNsfw,
`expected checkTextForNsfw('${inputText}') to be ${expectedNsfw}`
);
});
});
});