summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-12-17 18:45:42 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-12-17 18:45:42 +1100
commit77fa7ac886ac96ab02a014b64fb155250599a790 (patch)
tree27598093285dc1379d1822c0f279914372570b71
parentRemove /api/-/monitorz (diff)
downloadserver-77fa7ac886ac96ab02a014b64fb155250599a790.tar.xz
Remove bad banned words implementation
-rw-r--r--src/api/Server.ts3
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/index.ts5
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts5
-rw-r--r--src/bundle/Server.ts3
-rw-r--r--src/gateway/Server.ts3
-rw-r--r--src/util/entities/Member.ts6
-rw-r--r--src/util/entities/User.ts7
-rw-r--r--src/util/util/BannedWords.ts30
-rw-r--r--src/util/util/index.ts3
9 files changed, 5 insertions, 60 deletions
diff --git a/src/api/Server.ts b/src/api/Server.ts
index c7e53d70..b8d1f9f6 100644
--- a/src/api/Server.ts
+++ b/src/api/Server.ts
@@ -1,7 +1,7 @@
 import "missing-native-js-functions";
 import { Server, ServerOptions } from "lambert-server";
 import { Authentication, CORS } from "./middlewares/";
-import { BannedWords, Config, initDatabase, initEvent } from "@fosscord/util";
+import { Config, initDatabase, initEvent } from "@fosscord/util";
 import { ErrorHandler } from "./middlewares/ErrorHandler";
 import { BodyParser } from "./middlewares/BodyParser";
 import { Router, Request, Response, NextFunction } from "express";
@@ -38,7 +38,6 @@ export class FosscordServer extends Server {
 		await Config.init();
 		await initEvent();
 		await initInstance();
-		await BannedWords.init();
 
 		let logRequests = process.env["LOG_REQUESTS"] != undefined;
 		if (logRequests) {
diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
index 6fccac30..cd9da184 100644
--- a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
@@ -12,7 +12,6 @@ import {
 	Snowflake,
 	uploadFile,
 	MessageCreateSchema,
-	BannedWords,
 	DiscordApiErrors,
 } from "@fosscord/util";
 import { Router, Response, Request } from "express";
@@ -44,10 +43,6 @@ router.patch(
 		const { message_id, channel_id } = req.params;
 		var body = req.body as MessageCreateSchema;
 
-		if (body.content)
-			if (BannedWords.find(body.content))
-				throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
-
 		const message = await Message.findOneOrFail({
 			where: { id: message_id, channel_id },
 			relations: ["attachments"],
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index ecbd1b19..4b935f19 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -15,7 +15,6 @@ import {
 	Role,
 	MessageCreateSchema,
 	ReadState,
-	BannedWords,
 	DiscordApiErrors,
 } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
@@ -192,10 +191,6 @@ router.post(
 		var body = req.body as MessageCreateSchema;
 		const attachments: Attachment[] = [];
 
-		if (body.content)
-			if (BannedWords.find(body.content))
-				throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
-
 		const channel = await Channel.findOneOrFail({
 			where: { id: channel_id },
 			relations: ["recipients", "recipients.user"],
diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts
index 9ba715d1..1ae9511c 100644
--- a/src/bundle/Server.ts
+++ b/src/bundle/Server.ts
@@ -7,7 +7,7 @@ import * as Gateway from "@fosscord/gateway";
 import { CDNServer } from "@fosscord/cdn";
 import express from "express";
 import { green, bold, yellow } from "picocolors";
-import { Config, initDatabase, BannedWords } from "@fosscord/util";
+import { Config, initDatabase } from "@fosscord/util";
 import * as Sentry from "@sentry/node";
 import * as Tracing from "@sentry/tracing";
 import * as Integrations from "@sentry/integrations";
@@ -30,7 +30,6 @@ process.on("SIGTERM", async () => {
 async function main() {
 	await initDatabase();
 	await Config.init();
-	await BannedWords.init();
 
 	//Sentry
 	if (Config.get().sentry.enabled) {
diff --git a/src/gateway/Server.ts b/src/gateway/Server.ts
index 8c416b92..7e1489be 100644
--- a/src/gateway/Server.ts
+++ b/src/gateway/Server.ts
@@ -1,7 +1,7 @@
 import "missing-native-js-functions";
 import dotenv from "dotenv";
 dotenv.config();
-import { BannedWords, closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
+import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
 import ws from "ws";
 import { Connection } from "./events/Connection";
 import http from "http";
@@ -50,7 +50,6 @@ export class Server {
 		await initDatabase();
 		await Config.init();
 		await initEvent();
-		await BannedWords.init();
 		if (!this.server.listening) {
 			this.server.listen(this.port);
 			console.log(`[Gateway] online on 0.0.0.0:${this.port}`);
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index 34089af2..d0d57b26 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -15,7 +15,7 @@ import {
 	RelationId,
 } from "typeorm";
 import { Guild } from "./Guild";
-import { Config, emitEvent, BannedWords, FieldErrors } from "../util";
+import { Config, emitEvent, FieldErrors } from "../util";
 import {
 	GuildCreateEvent,
 	GuildDeleteEvent,
@@ -126,10 +126,6 @@ export class Member extends BaseClassWithoutId {
 		if (this.nick) {
 			this.nick = this.nick.split("\n").join("");
 			this.nick = this.nick.split("\t").join("");
-			if (BannedWords.find(this.nick))
-				throw FieldErrors({
-					nick: { message: "Bad nickname", code: "INVALID_NICKNAME" },
-				});
 		}
 	}
 
diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index 585bd725..7790856a 100644
--- a/src/util/entities/User.ts
+++ b/src/util/entities/User.ts
@@ -16,7 +16,6 @@ import {
 	FieldErrors,
 	Snowflake,
 	trimSpecial,
-	BannedWords,
 	adjustEmail,
 } from "..";
 import { Member, Session } from ".";
@@ -242,12 +241,6 @@ export class User extends BaseClass {
 				});
 			this.discriminator = discrim.toString().padStart(4, "0");
 		}
-
-		if (/*!update ||*/ this.username)
-			if (BannedWords.find(this.username))
-				throw FieldErrors({
-					username: { message: "Bad username", code: "INVALID_USERNAME" },
-				});
 	}
 
 	toPublicUser() {
diff --git a/src/util/util/BannedWords.ts b/src/util/util/BannedWords.ts
deleted file mode 100644
index 28b03546..00000000
--- a/src/util/util/BannedWords.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import fs from "fs/promises";
-import path from "path";
-import { InvisibleCharacters } from "./InvisibleCharacters";
-
-var words: string[];
-
-export const BannedWords = {
-	init: async function init() {
-		if (words) return words;
-		const file = (
-			await fs.readFile(path.join(process.cwd(), "bannedWords"))
-		).toString();
-		if (!file) {
-			words = [];
-			return [];
-		}
-		words = file.trim().split("\r").join("").split("\n");
-		return words;
-	},
-
-	get: () => words,
-
-	find: (val: string) => {
-		InvisibleCharacters.forEach(x => val = val.replaceAll(x, ""));
-		var normal = words.some((x) => val.indexOf(x) != -1);
-		val = val.split("").reverse().join("");
-		var rtlOverride = words.some((x) => val.indexOf(x) != -1);
-		return normal || rtlOverride;
-	},
-};
diff --git a/src/util/util/index.ts b/src/util/util/index.ts
index aa38e472..f7a273cb 100644
--- a/src/util/util/index.ts
+++ b/src/util/util/index.ts
@@ -19,5 +19,4 @@ export * from "./Snowflake";
 export * from "./String";
 export * from "./Array";
 export * from "./TraverseDirectory";
-export * from "./InvisibleCharacters";
-export * from "./BannedWords";
+export * from "./InvisibleCharacters";
\ No newline at end of file