Skip to content

Commit

Permalink
feat(profile): add censor-sensor to stop people from being unnecessar…
Browse files Browse the repository at this point in the history
…ily profane. closes #11
  • Loading branch information
seiyria committed Jun 27, 2023
1 parent bfc618f commit 429fbf8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions server/src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -17,14 +17,19 @@ export class AuthService {
constructor(
private readonly userService: UserService,
private readonly jwtService: JwtService,
private readonly analyticsService: AnalyticsService,
private readonly contentService: ContentService,
) {}

async signUp(
username: string,
password: string,
email: string,
): Promise<IFullUser> {
if (this.contentService.censor.isProfaneIsh(username))
throw new BadRequestException(
'Username is somewhat profane. Please choose again.',
);

const usersWithUsername = await this.userService.getAllUsersWithUsername(
username,
);
Expand Down
9 changes: 9 additions & 0 deletions server/src/modules/content/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ILocation> {
Expand Down
12 changes: 8 additions & 4 deletions server/src/modules/player/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
player,
Expand Down Expand Up @@ -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>(
player,
Expand Down

0 comments on commit 429fbf8

Please sign in to comment.