mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 04:32:35 +01:00
Move message auto mod to the api route instead of a @beforeinsert/update method
This commit is contained in:
parent
6d7909a02c
commit
8d2a2ba12e
@ -12,6 +12,8 @@ import {
|
|||||||
Snowflake,
|
Snowflake,
|
||||||
uploadFile,
|
uploadFile,
|
||||||
MessageCreateSchema,
|
MessageCreateSchema,
|
||||||
|
BannedWords,
|
||||||
|
DiscordApiErrors,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
@ -42,6 +44,10 @@ router.patch(
|
|||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
|
|
||||||
|
if (body.content)
|
||||||
|
if (BannedWords.find(body.content))
|
||||||
|
throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
|
||||||
|
|
||||||
const message = await Message.findOneOrFail({
|
const message = await Message.findOneOrFail({
|
||||||
where: { id: message_id, channel_id },
|
where: { id: message_id, channel_id },
|
||||||
relations: ["attachments"],
|
relations: ["attachments"],
|
||||||
@ -178,7 +184,7 @@ router.put(
|
|||||||
channel.save(),
|
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);
|
return res.json(message);
|
||||||
},
|
},
|
||||||
|
@ -15,6 +15,8 @@ import {
|
|||||||
Role,
|
Role,
|
||||||
MessageCreateSchema,
|
MessageCreateSchema,
|
||||||
ReadState,
|
ReadState,
|
||||||
|
BannedWords,
|
||||||
|
DiscordApiErrors,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
||||||
@ -190,6 +192,10 @@ router.post(
|
|||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
const attachments: Attachment[] = [];
|
const attachments: Attachment[] = [];
|
||||||
|
|
||||||
|
if (body.content)
|
||||||
|
if (BannedWords.find(body.content))
|
||||||
|
throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({
|
const channel = await Channel.findOneOrFail({
|
||||||
where: { id: channel_id },
|
where: { id: channel_id },
|
||||||
relations: ["recipients", "recipients.user"],
|
relations: ["recipients", "recipients.user"],
|
||||||
|
@ -5,8 +5,6 @@ import { Channel } from "./Channel";
|
|||||||
import { InteractionType } from "../interfaces/Interaction";
|
import { InteractionType } from "../interfaces/Interaction";
|
||||||
import { Application } from "./Application";
|
import { Application } from "./Application";
|
||||||
import {
|
import {
|
||||||
BeforeInsert,
|
|
||||||
BeforeUpdate,
|
|
||||||
Column,
|
Column,
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
@ -23,8 +21,6 @@ import { Guild } from "./Guild";
|
|||||||
import { Webhook } from "./Webhook";
|
import { Webhook } from "./Webhook";
|
||||||
import { Sticker } from "./Sticker";
|
import { Sticker } from "./Sticker";
|
||||||
import { Attachment } from "./Attachment";
|
import { Attachment } from "./Attachment";
|
||||||
import { BannedWords } from "../util";
|
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
|
|
||||||
export enum MessageType {
|
export enum MessageType {
|
||||||
DEFAULT = 0,
|
DEFAULT = 0,
|
||||||
@ -206,18 +202,6 @@ export class Message extends BaseClass {
|
|||||||
|
|
||||||
@Column({ type: "simple-json", nullable: true })
|
@Column({ type: "simple-json", nullable: true })
|
||||||
components?: MessageComponent[];
|
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 {
|
export interface MessageComponent {
|
||||||
|
@ -973,6 +973,10 @@ export const DiscordApiErrors = {
|
|||||||
undefined,
|
undefined,
|
||||||
["5"],
|
["5"],
|
||||||
),
|
),
|
||||||
|
AUTOMODERATOR_BLOCK: new ApiError(
|
||||||
|
"Message was blocked by automatic moderation",
|
||||||
|
200000,
|
||||||
|
),
|
||||||
|
|
||||||
//Other errors
|
//Other errors
|
||||||
UNKNOWN_VOICE_STATE: new ApiError("Unknown Voice State", 10065, 404),
|
UNKNOWN_VOICE_STATE: new ApiError("Unknown Voice State", 10065, 404),
|
||||||
|
Loading…
Reference in New Issue
Block a user