diff --git a/d2m/actions/register-pk-user.js b/d2m/actions/register-pk-user.js index da94f012..5bce6abb 100644 --- a/d2m/actions/register-pk-user.js +++ b/d2m/actions/register-pk-user.js @@ -92,8 +92,10 @@ async function ensureSimJoined(pkMessage, roomID) { * @param {Ty.PkMessage} pkMessage */ async function memberToStateContent(pkMessage) { - const systemname = pkMessage.system.tag || "" - const displayname = (pkMessage.member.display_name || pkMessage.member.name) + systemname + let displayname = (pkMessage.member.display_name || pkMessage.member.name) + if (pkMessage.system.tag) { + displayname = displayname + " " + pkMessage.system.tag + } const avatar = pkMessage.member.avatar_url || pkMessage.member.webhook_avatar_url || pkMessage.system.avatar_url const content = { diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index 878dcf5a..3b1a7d2d 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -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]) { diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index 4f1c1ddf..ddb5c589 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -1925,7 +1925,34 @@ test("event2message: mentioning matrix users works", async t => { messagesToEdit: [], messagesToSend: [{ username: "cadence [they]", - content: "I'm just [▲]() testing mentions", + content: "I'm just [@▲]() testing mentions", + avatar_url: undefined + }] + } + ) +}) + +test("event2message: mentioning matrix users works even when Element disambiguates the user", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "unascribed @unascribed:sleeping.town: if you want to run some experimental software, `11864f80cf` branch of OOYE has _vastly_ improved handling of PluralKit users. feel free to try it out, if you find bugs I'd appreciate you letting me know (just tag me at the place in chat where something went wrong)", + format: "org.matrix.custom.html", + formatted_body: "unascribed @unascribed:sleeping.town: if you want to run some experimental software, 11864f80cf branch of OOYE has vastly improved handling of PluralKit users. feel free to try it out, if you find bugs I'd appreciate you letting me know (just tag me at the place in chat where something went wrong)" + }, + event_id: "$17qTyvkDykSp_4Wkjeuh9Y6j9hPe20ZY_E6V3UKAyUE", + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "[@unascribed]() if you want to run some experimental software, `11864f80cf` branch of OOYE has _vastly_ improved handling of PluralKit users. feel free to try it out, if you find bugs I'd appreciate you letting me know (just tag me at the place in chat where something went wrong)", avatar_url: undefined }] } @@ -2264,7 +2291,7 @@ test("event2message: colon after mentions is stripped", async t => { messagesToEdit: [], messagesToSend: [{ username: "cadence [they]", - content: "<@114147806469554185> hey, I'm just [▲]() testing mentions", + content: "<@114147806469554185> hey, I'm just [@▲]() testing mentions", avatar_url: undefined }] }