diff --git "a/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" "b/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" index 3abfebe..47faba7 100644 --- "a/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" @@ -12,6 +12,8 @@ Snowflake, uploadFile, MessageCreateSchema, + BannedWords, + DiscordApiErrors, } from "@fosscord/util"; import { Router, Response, Request } from "express"; import multer from "multer"; @@ -42,6 +44,10 @@ 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 @@ 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/\043channel_id/messages/index.ts" "b/src/api/routes/channels/\043channel_id/messages/index.ts" index e0c91b8..ecbd1b1 100644 --- "a/src/api/routes/channels/\043channel_id/messages/index.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/index.ts" @@ -15,6 +15,8 @@ Role, MessageCreateSchema, ReadState, + BannedWords, + DiscordApiErrors, } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import { handleMessage, postHandleMessage, route } from "@fosscord/api"; @@ -190,6 +192,10 @@ 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/util/entities/Message.ts b/src/util/entities/Message.ts index a52b478..013de37 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -5,8 +5,6 @@ import { InteractionType } from "../interfaces/Interaction"; import { Application } from "./Application"; import { - BeforeInsert, - BeforeUpdate, Column, CreateDateColumn, Entity, @@ -23,8 +21,6 @@ import { Webhook } from "./Webhook"; import { Sticker } from "./Sticker"; import { Attachment } from "./Attachment"; -import { BannedWords } from "../util"; -import { HTTPError } from "lambert-server"; export enum MessageType { DEFAULT = 0, @@ -206,18 +202,6 @@ @Column({ type: "simple-json", nullable: true }) components?: MessageComponent[]; - - @BeforeUpdate() - @BeforeInsert() - validate() { - if (this.content) { - if (BannedWords.find(this.content)) - throw new HTTPError( - "Message was blocked by automatic moderation", - 200000, - ); - } - } } export interface MessageComponent { diff --git a/src/util/util/Constants.ts b/src/util/util/Constants.ts index 7c5b7dc..46cf2e4 100644 --- a/src/util/util/Constants.ts +++ b/src/util/util/Constants.ts @@ -973,6 +973,10 @@ undefined, ["5"], ), + AUTOMODERATOR_BLOCK: new ApiError( + "Message was blocked by automatic moderation", + 200000, + ), //Other errors UNKNOWN_VOICE_STATE: new ApiError("Unknown Voice State", 10065, 404),