summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-29 15:46:02 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-29 15:53:13 +1000
commit357aada96953cd301f5883bd80d32c289e873227 (patch)
tree4944c6c209e012c80cce14acb6095902504ca3a1 /src
parentUpdate read state on message create (diff)
downloadserver-357aada96953cd301f5883bd80d32c289e873227.tar.xz
Prevent URL embedding and mentions when in codeblock
Diffstat (limited to 'src')
-rw-r--r--src/api/util/handlers/Message.ts6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index fbf10a8a..005d9d23 100644
--- a/src/api/util/handlers/Message.ts
+++ b/src/api/util/handlers/Message.ts
@@ -9,7 +9,6 @@ import {
 	getPermission,
 	getRights,
 	CHANNEL_MENTION,
-	Snowflake,
 	USER_MENTION,
 	ROLE_MENTION,
 	Role,
@@ -59,7 +58,6 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 		? await Sticker.find({ where: { id: In(opts.sticker_ids) } })
 		: undefined;
 	const message = Message.create({
-		id: Snowflake.generate(),
 		...opts,
 		sticker_items: stickers,
 		guild_id: channel.guild_id,
@@ -148,6 +146,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 	if (content) {
 		// TODO: explicit-only mentions
 		message.content = content.trim();
+		content = content.replace(/ *\`[^)]*\` */g, ""); // remove codeblocks
 		for (const [_, mention] of content.matchAll(CHANNEL_MENTION)) {
 			if (!mention_channel_ids.includes(mention))
 				mention_channel_ids.push(mention);
@@ -192,7 +191,8 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 
 // TODO: cache link result in db
 export async function postHandleMessage(message: Message) {
-	var links = message.content?.match(LINK_REGEX);
+	const content = message.content?.replace(/ *\`[^)]*\` */g, "");	// remove markdown
+	var links = content?.match(LINK_REGEX);
 	if (!links) return;
 
 	const data = { ...message };