m->d: Fix glitched mention when Element disambigs

This commit is contained in:
Cadence Ember 2024-01-22 23:10:33 +13:00
parent a71c9515ec
commit 4591b5ae03
3 changed files with 36 additions and 5 deletions

View file

@ -109,6 +109,8 @@ turndownService.addRule("inlineLink", {
const href = node.getAttribute("href")
let brackets = ["", ""]
if (href.startsWith("https://matrix.to")) brackets = ["<", ">"]
if (href.startsWith("https://matrix.to/#/@")) content = "@" + content
content = content.replace(/ @.*/, "")
return "[" + content + "](" + brackets[0] + href + brackets[1] + ")"
}
})
@ -621,7 +623,7 @@ async function eventToMessage(event, guild, di) {
content = displayNameRunoff + replyLine + content
// Handling written @mentions: we need to look for candidate Discord members to join to the room
let writtenMentionMatch = content.match(/(?:^|[^"<>/A-Za-z0-9])@([A-Za-z][A-Za-z0-9._\[\]\(\)-]+):?/d) // /d flag for indices requires node.js 16+
let writtenMentionMatch = content.match(/(?:^|[^"[<>/A-Za-z0-9])@([A-Za-z][A-Za-z0-9._\[\]\(\)-]+):?/d) // /d flag for indices requires node.js 16+
if (writtenMentionMatch) {
const results = await di.snow.guild.searchGuildMembers(guild.id, {query: writtenMentionMatch[1]})
if (results[0]) {