summary refs log tree commit diff
path: root/src/api/util/handlers/Message.ts
diff options
context:
space:
mode:
authorCatalan Lover <48515417+FSG-Cat@users.noreply.github.com>2022-08-23 23:50:01 +0200
committerGitHub <noreply@github.com>2022-08-23 23:50:01 +0200
commitd63451b3fe6c0c6ab175adec82361834bb3633f5 (patch)
treeb738ee25bf9819300e1802ba9a8e2813e9dc2588 /src/api/util/handlers/Message.ts
parentMerge pull request #1 from FSG-Cat/FSG-Cat-patch-1 (diff)
parentCheck Captcha (diff)
downloadserver-d63451b3fe6c0c6ab175adec82361834bb3633f5.tar.xz
Merge branch 'fosscord:staging' into Bug-Report-Template
Diffstat (limited to 'src/api/util/handlers/Message.ts')
-rw-r--r--src/api/util/handlers/Message.ts52
1 files changed, 27 insertions, 25 deletions
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index ff5ece75..d760d27c 100644
--- a/src/api/util/handlers/Message.ts
+++ b/src/api/util/handlers/Message.ts
@@ -1,32 +1,31 @@
 import {
+	Application,
+	Attachment,
 	Channel,
+	CHANNEL_MENTION,
+	Config,
 	Embed,
 	emitEvent,
+	EVERYONE_MENTION,
+	getPermission,
+	getRights,
 	Guild,
+	HERE_MENTION,
+	HTTPError,
 	Message,
 	MessageCreateEvent,
+	MessageCreateSchema,
+	MessageType,
 	MessageUpdateEvent,
-	getPermission,
-	getRights,
-	CHANNEL_MENTION,
-	Snowflake,
-	USER_MENTION,
-	ROLE_MENTION,
+	OrmUtils,
 	Role,
-	EVERYONE_MENTION,
-	HERE_MENTION,
-	MessageType,
+	ROLE_MENTION,
 	User,
-	Application,
-	Webhook,
-	Attachment,
-	Config,
-	MessageCreateSchema,
+	USER_MENTION,
+	Webhook
 } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
-import fetch from "node-fetch";
 import cheerio from "cheerio";
-import { OrmUtils } from "@fosscord/util";
+import fetch from "node-fetch";
 
 const allow_empty = false;
 // TODO: check webhook, application, system author, stickers
@@ -61,21 +60,21 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 	});
 
 	if (message.content && message.content.length > Config.get().limits.message.maxCharacters) {
-		throw new HTTPError("Content length over max character limit")
+		throw new HTTPError("Content length over max character limit");
 	}
 
 	if (opts.author_id) {
 		message.author = await User.getPublicUser(opts.author_id);
 		const rights = await getRights(opts.author_id);
 		rights.hasThrow("SEND_MESSAGES");
-	}	
+	}
 	if (opts.application_id) {
 		message.application = await Application.findOneOrFail({ where: { id: opts.application_id } });
 	}
 	if (opts.webhook_id) {
 		message.webhook = await Webhook.findOneOrFail({ where: { id: opts.webhook_id } });
 	}
-	
+
 	const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id);
 	permission.hasThrow("SEND_MESSAGES");
 	if (permission.cache.member) {
@@ -89,8 +88,10 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 		if (message.guild_id !== null) {
 			const guild = await Guild.findOneOrFail({ where: { id: channel.guild_id } });
 			if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
-				if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError("You can only reference messages from this guild");
-				if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel");
+				if (opts.message_reference.guild_id !== channel.guild_id)
+					throw new HTTPError("You can only reference messages from this guild");
+				if (opts.message_reference.channel_id !== opts.channel_id)
+					throw new HTTPError("You can only reference messages from this channel");
 			}
 		}
 		/** Q: should be checked if the referenced message exists? ANSWER: NO
@@ -100,7 +101,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 	}
 
 	// TODO: stickers/activity
-	if (!allow_empty && (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length)) {
+	if (!allow_empty && !opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length) {
 		throw new HTTPError("Empty messages are not allowed", 50006);
 	}
 
@@ -110,7 +111,8 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 	let mention_user_ids = [] as string[];
 	let mention_everyone = false;
 
-	if (content) { // TODO: explicit-only mentions
+	if (content) {
+		// TODO: explicit-only mentions
 		message.content = content.trim();
 		for (const [_, mention] of content.matchAll(CHANNEL_MENTION)) {
 			if (!mention_channel_ids.includes(mention)) mention_channel_ids.push(mention);
@@ -158,7 +160,7 @@ export async function postHandleMessage(message: Message) {
 		try {
 			const request = await fetch(link, {
 				...DEFAULT_FETCH_OPTIONS,
-				size: Config.get().limits.message.maxEmbedDownloadSize,
+				size: Config.get().limits.message.maxEmbedDownloadSize
 			});
 
 			const text = await request.text();