diff --git a/d2m/converters/user-to-mxid.test.js b/d2m/converters/user-to-mxid.test.js index 1b31260a..e7094736 100644 --- a/d2m/converters/user-to-mxid.test.js +++ b/d2m/converters/user-to-mxid.test.js @@ -17,7 +17,7 @@ test("user2name: works on emojis", t => { }) test("user2name: works on single emoji at the end", t => { - t.equal(userToSimName({username: "Amanda 🎵", discriminator: "2192"}), "amanda") + t.equal(userToSimName({username: "Melody 🎵", discriminator: "2192"}), "melody") }) test("user2name: works on crazy name", t => { diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index e7bbda57..5f6f3e6c 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -352,7 +352,7 @@ async function eventToMessage(event, guild, di) { const contentPreviewChunks = chunk( entities.decodeHTML5Strict( // Remove entities like & " repliedToContent.replace(/.*<\/mx-reply>/, "") // Remove everything before replies, so just use the actual message body - .replace(/
.*?<\/blockquote>/, "") // If the message starts with a blockquote, don't count it and use the message body afterwards + .replace(/^\s*
.*?<\/blockquote>(.....)/s, "$1") // If the message starts with a blockquote, don't count it and use the message body afterwards .replace(/(?:\n|
)+/g, " ") // Should all be on one line .replace(/]*data-mx-spoiler\b[^>]*>.*?<\/span>/g, "[spoiler]") // Good enough method of removing spoiler content. (I don't want to break out the HTML parser unless I have to.) .replace(/<[^>]+>/g, "") // Completely strip all HTML tags and formatting. diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index 1a1c3f04..074da1de 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -813,6 +813,86 @@ test("event2message: should include a reply preview when message ends with a blo ) }) +test("event2message: should include a reply preview when replying to a description-only bot embed", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "> <@_ooye_amanda:cadence.moe> > It looks like this queue has ended.\n\nso you're saying on matrix side I would have to edit ^this^ to add \"Timed out\" before the blockquote?", + format: "org.matrix.custom.html", + formatted_body: "
In reply to @_ooye_amanda:cadence.moe
It looks like this queue has ended.
so you're saying on matrix side I would have to edit ^this^ to add "Timed out" before the blockquote?", + "m.relates_to": { + "m.in_reply_to": { + event_id: "$zJFjTvNn1w_YqpR4o4ISKUFisNRgZcu1KSMI_LADPVQ" + } + } + }, + event_id: "$qCOlszCawu5hlnF2a2PGyXeGGvtoNJdXyRAEaTF0waA", + room_id: "!CzvdIdUQXgUjDVKxeU:cadence.moe" + }, data.guild.general, { + api: { + getEvent: mockGetEvent(t, "!CzvdIdUQXgUjDVKxeU:cadence.moe", "$zJFjTvNn1w_YqpR4o4ISKUFisNRgZcu1KSMI_LADPVQ", { + type: "m.room.message", + room_id: "!edUxjVdzgUvXDUIQCK:cadence.moe", + sender: "@_ooye_amanda:cadence.moe", + content: { + "m.mentions": {}, + msgtype: "m.notice", + body: "> Now Playing: [**LOADING**](https://amanda.moe)\n" + + "> \n" + + "> `[​====[LOADING]=====]`", + format: "org.matrix.custom.html", + formatted_body: '
Now Playing: LOADING

[​====[LOADING]=====]
' + }, + unsigned: { + "m.relations": { + "m.replace": { + type: "m.room.message", + room_id: "!edUxjVdzgUvXDUIQCK:cadence.moe", + sender: "@_ooye_amanda:cadence.moe", + content: { + "m.mentions": {}, + msgtype: "m.notice", + body: "* > It looks like this queue has ended.", + format: "org.matrix.custom.html", + formatted_body: "*
It looks like this queue has ended.
", + "m.new_content": { + "m.mentions": {}, + msgtype: "m.notice", + body: "> It looks like this queue has ended.", + format: "org.matrix.custom.html", + formatted_body: "
It looks like this queue has ended.
" + }, + "m.relates_to": { + rel_type: "m.replace", + event_id: "$zJFjTvNn1w_YqpR4o4ISKUFisNRgZcu1KSMI_LADPVQ" + } + }, + event_id: "$nrLF310vALFIXPNk6MEIy0lYiGXi210Ok0DATSaF5jQ", + user_id: "@_ooye_amanda:cadence.moe", + } + }, + user_id: "@_ooye_amanda:cadence.moe", + } + }) + } + }), + { + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/497161350934560778/1162625810109317170 <@1109360903096369153>:" + + "\n> It looks like this queue has ended." + + `\nso you're saying on matrix side I would have to edit ^this^ to add "Timed out" before the blockquote?`, + avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU" + }] + } + ) +}) + test("event2message: entities are not escaped in main message or reply preview", async t => { // Intended result: Testing? in italics, followed by the sequence "':.`[]&things t.deepEqual( diff --git a/test/ooye-test-data.sql b/test/ooye-test-data.sql index f8039cc1..4fba4800 100644 --- a/test/ooye-test-data.sql +++ b/test/ooye-test-data.sql @@ -18,7 +18,8 @@ INSERT INTO sim (user_id, sim_name, localpart, mxid) VALUES ('771520384671416320', 'bojack_horseman', '_ooye_bojack_horseman', '@_ooye_bojack_horseman:cadence.moe'), ('112890272819507200', '.wing.', '_ooye_.wing.', '@_ooye_.wing.:cadence.moe'), ('114147806469554185', 'extremity', '_ooye_extremity', '@_ooye_extremity:cadence.moe'), -('111604486476181504', 'kyuugryphon', '_ooye_kyuugryphon', '@_ooye_kyuugryphon:cadence.moe');; +('111604486476181504', 'kyuugryphon', '_ooye_kyuugryphon', '@_ooye_kyuugryphon:cadence.moe'), +('1109360903096369153', 'amanda', '_ooye_amanda', '@_ooye_amanda:cadence.moe'); INSERT INTO sim_member (mxid, room_id, hashed_profile_content) VALUES ('@_ooye_bojack_horseman:cadence.moe', '!hYnGGlPHlbujVVfktC:cadence.moe', NULL); @@ -38,7 +39,8 @@ INSERT INTO message_channel (message_id, channel_id) VALUES ('1145688633186193479', '1100319550446252084'), ('1145688633186193480', '1100319550446252084'), ('1145688633186193481', '1100319550446252084'), -('1162005526675193909', '1162005314908999790'); +('1162005526675193909', '1162005314908999790'), +('1162625810109317170', '497161350934560778'); INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES ('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 1), @@ -60,7 +62,9 @@ INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part ('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs', 'm.room.message', 'm.text', '1145688633186193479', 0, 0), ('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt', 'm.room.message', 'm.text', '1145688633186193480', 0, 0), ('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt', 'm.room.message', 'm.text', '1145688633186193481', 1, 0), -('$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo', 'm.room.message', 'm.text', '1162005526675193909', 0, 0); +('$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo', 'm.room.message', 'm.text', '1162005526675193909', 0, 0), +('$0wEdIP8fhTq-P68xwo_gyUw-Zv0KA2aS2tfhdFSrLZc', 'm.room.message', 'm.text', '1162625810109317170', 1, 1), +('$zJFjTvNn1w_YqpR4o4ISKUFisNRgZcu1KSMI_LADPVQ', 'm.room.message', 'm.notice', '1162625810109317170', 1, 1); INSERT INTO file (discord_url, mxc_url) VALUES ('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'), @@ -91,7 +95,8 @@ INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES ('!BpMdOUkWWhFxmTrENV:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'malformed mxc'), ('!fGgIymcYWOqjbSRUdV:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'), ('!BnKuBPCvyfOkhcUjEu:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'), -('!maggESguZBqGBZtSnr:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'); +('!maggESguZBqGBZtSnr:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'), +('!CzvdIdUQXgUjDVKxeU:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'); INSERT INTO "auto_emoji" ("name","emoji_id","guild_id") VALUES ('L1','1144820033948762203','529176156398682115'),