diff --git a/util/src/entities/Message.ts b/src/util/entities/Message.ts
index 6ea5c4aa..3a3dd5e4 100644
--- a/util/src/entities/Message.ts
+++ b/src/util/entities/Message.ts
@@ -5,6 +5,8 @@ import { Channel } from "./Channel";
import { InteractionType } from "../interfaces/Interaction";
import { Application } from "./Application";
import {
+ BeforeInsert,
+ BeforeUpdate,
Column,
CreateDateColumn,
Entity,
@@ -23,6 +25,7 @@ import { Sticker } from "./Sticker";
import { Attachment } from "./Attachment";
import { BannedWords } from "../util";
import { HTTPError } from "lambert-server";
+import { ValidatorConstraint } from "class-validator";
export enum MessageType {
DEFAULT = 0,
@@ -58,7 +61,7 @@ export class Message extends BaseClass {
@Column({ nullable: true })
@RelationId((message: Message) => message.channel)
@Index()
- channel_id: string;
+ channel_id?: string;
@JoinColumn({ name: "channel_id" })
@ManyToOne(() => Channel, {
@@ -79,7 +82,7 @@ export class Message extends BaseClass {
@Column({ nullable: true })
@RelationId((message: Message) => message.author)
@Index()
- author_id: string;
+ author_id?: string;
@JoinColumn({ name: "author_id", referencedColumnName: "id" })
@ManyToOne(() => User, {
@@ -89,7 +92,7 @@ export class Message extends BaseClass {
@Column({ nullable: true })
@RelationId((message: Message) => message.member)
- member_id: string;
+ member_id?: string;
@JoinColumn({ name: "member_id", referencedColumnName: "id" })
@ManyToOne(() => User, {
@@ -99,7 +102,7 @@ export class Message extends BaseClass {
@Column({ nullable: true })
@RelationId((message: Message) => message.webhook)
- webhook_id: string;
+ webhook_id?: string;
@JoinColumn({ name: "webhook_id" })
@ManyToOne(() => Webhook)
@@ -107,7 +110,7 @@ export class Message extends BaseClass {
@Column({ nullable: true })
@RelationId((message: Message) => message.application)
- application_id: string;
+ application_id?: string;
@JoinColumn({ name: "application_id" })
@ManyToOne(() => Application)
@@ -116,17 +119,12 @@ export class Message extends BaseClass {
@Column({ nullable: true, type: process.env.PRODUCTION ? "longtext" : undefined })
content?: string;
- setContent(val: string) {
- if (val && BannedWords.find(val)) throw new HTTPError("Message was blocked by automatic moderation", 200000);
- this.content = val;
- }
-
@Column()
@CreateDateColumn()
timestamp: Date;
@Column({ nullable: true })
- edited_timestamp: Date;
+ edited_timestamp?: Date;
@Column({ nullable: true })
tts?: boolean;
@@ -179,6 +177,7 @@ export class Message extends BaseClass {
@Column({ nullable: true })
flags?: string;
+
@Column({ type: "simple-json", nullable: true })
message_reference?: {
message_id: string;
@@ -201,6 +200,14 @@ export class Message extends BaseClass {
@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 {
|