summary refs log tree commit diff
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
commit19f3e9b5542676e6a7dfb979143a4dd2988a5cb6 (patch)
treef27658a947c98dccd881dee50bedb2ea2a623cf6
parentUpdate read state on message create (diff)
downloadserver-19f3e9b5542676e6a7dfb979143a4dd2988a5cb6.tar.xz
Prevent URL embedding and mentions when in codeblock
-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 };