Prevent URL embedding and mentions when in codeblock

This commit is contained in:
Madeline 2022-09-29 15:46:02 +10:00
parent 357ec51f1c
commit 357aada969

View File

@ -9,7 +9,6 @@ import {
getPermission, getPermission,
getRights, getRights,
CHANNEL_MENTION, CHANNEL_MENTION,
Snowflake,
USER_MENTION, USER_MENTION,
ROLE_MENTION, ROLE_MENTION,
Role, Role,
@ -59,7 +58,6 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
? await Sticker.find({ where: { id: In(opts.sticker_ids) } }) ? await Sticker.find({ where: { id: In(opts.sticker_ids) } })
: undefined; : undefined;
const message = Message.create({ const message = Message.create({
id: Snowflake.generate(),
...opts, ...opts,
sticker_items: stickers, sticker_items: stickers,
guild_id: channel.guild_id, guild_id: channel.guild_id,
@ -148,6 +146,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
if (content) { if (content) {
// TODO: explicit-only mentions // TODO: explicit-only mentions
message.content = content.trim(); message.content = content.trim();
content = content.replace(/ *\`[^)]*\` */g, ""); // remove codeblocks
for (const [_, mention] of content.matchAll(CHANNEL_MENTION)) { for (const [_, mention] of content.matchAll(CHANNEL_MENTION)) {
if (!mention_channel_ids.includes(mention)) if (!mention_channel_ids.includes(mention))
mention_channel_ids.push(mention); mention_channel_ids.push(mention);
@ -192,7 +191,8 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
// TODO: cache link result in db // TODO: cache link result in db
export async function postHandleMessage(message: Message) { 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; if (!links) return;
const data = { ...message }; const data = { ...message };