summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-25 10:58:36 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-25 10:58:36 +1100
commitf5b50ed3a89dce8e9ec89c1bc25f08c56ef80e50 (patch)
tree1b0e6522b3ac776949fb0f0fd5620d2c20034db7 /src/api
parentFix tweets with only video breaking embeds (diff)
downloadserver-f5b50ed3a89dce8e9ec89c1bc25f08c56ef80e50.tar.xz
Move message auto mod to the api route instead of a @beforeinsert/update method
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/index.ts8
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts6
2 files changed, 13 insertions, 1 deletions
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 3abfebe8..47faba73 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,6 +12,8 @@ import {
 	Snowflake,
 	uploadFile,
 	MessageCreateSchema,
+	BannedWords,
+	DiscordApiErrors,
 } from "@fosscord/util";
 import { Router, Response, Request } from "express";
 import multer from "multer";
@@ -42,6 +44,10 @@ 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"],
@@ -178,7 +184,7 @@ router.put(
 			channel.save(),
 		]);
 
-		postHandleMessage(message).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error
+		postHandleMessage(message).catch((e) => { }); // no await as it shouldnt block the message send function and silently catch error
 
 		return res.json(message);
 	},
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index e0c91b8a..ecbd1b19 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -15,6 +15,8 @@ import {
 	Role,
 	MessageCreateSchema,
 	ReadState,
+	BannedWords,
+	DiscordApiErrors,
 } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
 import { handleMessage, postHandleMessage, route } from "@fosscord/api";
@@ -190,6 +192,10 @@ 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"],