From 429fbf835855eba99c7348fc0a32bcb8d846f973 Mon Sep 17 00:00:00 2001 From: Kyle Kemp Date: Tue, 27 Jun 2023 15:55:07 -0500 Subject: [PATCH] feat(profile): add censor-sensor to stop people from being unnecessarily profane. closes #11 --- server/src/modules/auth/auth.service.ts | 9 +++++++-- server/src/modules/content/content.service.ts | 9 +++++++++ server/src/modules/player/player.service.ts | 12 ++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/server/src/modules/auth/auth.service.ts b/server/src/modules/auth/auth.service.ts index ac5ca24..4bdceda 100644 --- a/server/src/modules/auth/auth.service.ts +++ b/server/src/modules/auth/auth.service.ts @@ -8,7 +8,7 @@ import * as bcrypt from 'bcrypt'; import { sample } from 'lodash'; import { IFullUser, IHasAccessToken } from '@interfaces'; -import { AnalyticsService } from '@modules/content/analytics.service'; +import { ContentService } from '@modules/content/content.service'; import { User } from '../user/user.schema'; import { UserService } from '../user/user.service'; @@ -17,7 +17,7 @@ export class AuthService { constructor( private readonly userService: UserService, private readonly jwtService: JwtService, - private readonly analyticsService: AnalyticsService, + private readonly contentService: ContentService, ) {} async signUp( @@ -25,6 +25,11 @@ export class AuthService { password: string, email: string, ): Promise { + if (this.contentService.censor.isProfaneIsh(username)) + throw new BadRequestException( + 'Username is somewhat profane. Please choose again.', + ); + const usersWithUsername = await this.userService.getAllUsersWithUsername( username, ); diff --git a/server/src/modules/content/content.service.ts b/server/src/modules/content/content.service.ts index b8f8e3a..03a0ef5 100644 --- a/server/src/modules/content/content.service.ts +++ b/server/src/modules/content/content.service.ts @@ -4,8 +4,17 @@ import { ICollectible, IEquipment, IItem, IJob, ILocation } from '@interfaces'; import * as fs from 'fs-extra'; import { Logger } from 'nestjs-pino'; +import { CensorSensor } from 'censor-sensor'; + +const censor = new CensorSensor(); +censor.disableTier(4); + @Injectable() export class ContentService { + public get censor(): CensorSensor { + return censor; + } + public content = { locations: {}, jobs: {}, collectibles: {}, equipment: {} }; private get locations(): Record { diff --git a/server/src/modules/player/player.service.ts b/server/src/modules/player/player.service.ts index 5df4db0..050f435 100644 --- a/server/src/modules/player/player.service.ts +++ b/server/src/modules/player/player.service.ts @@ -90,9 +90,11 @@ export class PlayerService { const player = await this.getPlayerForUser(userId); if (!player) throw new ForbiddenException('Player not found'); - shortBio = shortBio.substring(0, 30).trim(); + shortBio = this.contentService.censor.cleanProfanityIsh( + shortBio.substring(0, 30).trim(), + ); - if(player.profile.shortBio === shortBio) return {}; + if (player.profile.shortBio === shortBio) return {}; const playerPatches = await getPatchesAfterPropChanges( player, @@ -120,9 +122,11 @@ export class PlayerService { const player = await this.getPlayerForUser(userId); if (!player) throw new ForbiddenException('Player not found'); - longBio = longBio.substring(0, 500).trim(); + longBio = this.contentService.censor.cleanProfanityIsh( + longBio.substring(0, 500).trim(), + ); - if(player.profile.longBio === longBio) return {}; + if (player.profile.longBio === longBio) return {}; const playerPatches = await getPatchesAfterPropChanges( player,