feat(profiles): slur/swear blocker
This commit is contained in:
Generated
+628
-1121
File diff suppressed because it is too large
Load Diff
+10
-10
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "habitica",
|
||||
"description": "A habit tracker app which treats your goals like a Role Playing Game.",
|
||||
"version": "5.12.2",
|
||||
"version": "5.9.1",
|
||||
"main": "./website/server/index.js",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.22.10",
|
||||
"@babel/preset-env": "^7.22.10",
|
||||
"@babel/core": "^7.23.3",
|
||||
"@babel/preset-env": "^7.23.3",
|
||||
"@babel/register": "^7.22.15",
|
||||
"@google-cloud/trace-agent": "^7.1.2",
|
||||
"@parse/node-apn": "^5.2.3",
|
||||
@@ -36,7 +36,6 @@
|
||||
"gulp-babel": "^8.0.0",
|
||||
"gulp-imagemin": "^7.1.0",
|
||||
"gulp-nodemon": "^2.5.0",
|
||||
"nodemon": "^2.0.20",
|
||||
"gulp.spritesmith": "^6.13.0",
|
||||
"habitica-markdown": "^3.0.0",
|
||||
"helmet": "^4.6.0",
|
||||
@@ -50,10 +49,11 @@
|
||||
"method-override": "^3.0.0",
|
||||
"moment": "^2.29.4",
|
||||
"moment-recur": "^1.0.7",
|
||||
"mongoose": "^5.13.20",
|
||||
"mongoose": "^5.13.21",
|
||||
"morgan": "^1.10.0",
|
||||
"nconf": "^0.12.1",
|
||||
"node-gcm": "^1.0.5",
|
||||
"node-gcm": "^1.1.3",
|
||||
"nodemon": "^2.0.22",
|
||||
"on-headers": "^1.0.2",
|
||||
"passport": "^0.5.3",
|
||||
"passport-facebook": "^3.0.0",
|
||||
@@ -72,10 +72,10 @@
|
||||
"superagent": "^8.1.2",
|
||||
"universal-analytics": "^0.5.3",
|
||||
"useragent": "^2.1.9",
|
||||
"uuid": "^9.0.0",
|
||||
"uuid": "^9.0.1",
|
||||
"validator": "^13.11.0",
|
||||
"vinyl-buffer": "^1.0.1",
|
||||
"winston": "^3.10.0",
|
||||
"winston": "^3.11.0",
|
||||
"winston-loggly-bulk": "^3.3.0",
|
||||
"xml2js": "^0.6.2"
|
||||
},
|
||||
@@ -111,8 +111,8 @@
|
||||
"apidoc": "gulp apidoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": "^1.4.0",
|
||||
"chai": "^4.3.7",
|
||||
"axios": "^1.6.2",
|
||||
"chai": "^4.3.10",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"chai-moment": "^0.1.0",
|
||||
"chalk": "^5.3.0",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import * as slack from '../slack';
|
||||
import { getUserInfo } from '../email';
|
||||
import common from '../../../common';
|
||||
import * as Tasks from '../../models/task';
|
||||
import { model as Groups } from '../../models/group';
|
||||
@@ -105,16 +107,23 @@ function checkPreferencePurchase (user, path, item) {
|
||||
return _.get(user.purchased, itemPath);
|
||||
}
|
||||
|
||||
// checks for banned slurs - swears are allowed & dependent on user flagging
|
||||
async function checkNewInputForProfanity (user, res, newValue) {
|
||||
const containsSlur = stringContainsProfanity(newValue, 'slur');
|
||||
const containsBannedWord = stringContainsProfanity(newValue);
|
||||
if (containsSlur || containsBannedWord) {
|
||||
if (containsSlur) {
|
||||
user.flags.chatRevoked = true;
|
||||
await user.save();
|
||||
throw new BadRequest(res.t('bannedSlurUsedInProfile'));
|
||||
}
|
||||
throw new BadRequest(res.t('bannedWordUsedInProfile'));
|
||||
if (containsSlur) {
|
||||
user.flags.chatRevoked = true;
|
||||
user.flags.chatShadowMuted = true;
|
||||
await user.save();
|
||||
// slack flagged-posts
|
||||
const authorEmail = getUserInfo(user, ['email']).email;
|
||||
slack.sendSlurNotification({
|
||||
authorEmail,
|
||||
author: user,
|
||||
body: [user.profile.name,
|
||||
user.profile.blurb],
|
||||
});
|
||||
// hard stop error & message
|
||||
throw new BadRequest(res.t('bannedSlurUsedInProfile'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import bannedSlurs from '../bannedSlurs';
|
||||
import bannedWords from '../bannedWords';
|
||||
// import bannedWords from '../bannedWords';
|
||||
import {
|
||||
getMatchesByWordArray,
|
||||
normalizeUnicodeString,
|
||||
@@ -8,12 +8,13 @@ import {
|
||||
import forbiddenUsernames from '../forbiddenUsernames';
|
||||
|
||||
const bannedSlurRegexes = bannedSlurs.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
const bannedWordRegexes = bannedWords.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
// const bannedWordRegexes = bannedWords.map(word =>
|
||||
// new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
||||
|
||||
export function stringContainsProfanity (str, profanityType = 'bannedWord') {
|
||||
const bannedRegexes = profanityType === 'slur'
|
||||
? bannedSlurRegexes
|
||||
: bannedWordRegexes;
|
||||
&& bannedSlurRegexes;
|
||||
// : bannedWordRegexes;
|
||||
|
||||
for (let i = 0; i < bannedRegexes.length; i += 1) {
|
||||
const regEx = bannedRegexes[i];
|
||||
|
||||
Reference in New Issue
Block a user