diff --git a/src/d2m/converters/edit-to-changes.test.js b/src/d2m/converters/edit-to-changes.test.js index 842c24e..b78ee9e 100644 --- a/src/d2m/converters/edit-to-changes.test.js +++ b/src/d2m/converters/edit-to-changes.test.js @@ -343,19 +343,18 @@ test("edit2changes: generated embed", async t => { t.deepEqual(eventsToSend, [{ $type: "m.room.message", msgtype: "m.notice", - body: "| via hthrflwrs on cohost" - + "\n| \n| ## This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO https://cohost.org/jkap/post/4794219-empty" + body: "| ## This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO https://cohost.org/jkap/post/4794219-empty" + "\n| \n| 1v1 physical card game. Each player gets one standard deck of cards with a different backing to differentiate. Every turn proceeds as follows:" + "\n| \n| * Both players draw eight cards" + "\n| * Both players may choose up to eight cards to discard, then draw that number of cards to put back in their hand" - + "\n| * Both players present their best five-or-less-card pok...", + + "\n| * Both players present their best five-or-less-card pok..." + + "\n| via hthrflwrs on cohost", format: "org.matrix.custom.html", - formatted_body: `

hthrflwrs on cohost` - + `

This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO` + formatted_body: `

This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO` + `

1v1 physical card game. Each player gets one standard deck of cards with a different backing to differentiate. Every turn proceeds as follows:` + `

`, + + `
  • Both players present their best five-or-less-card pok...
  • hthrflwrs on cohost
    `, "m.mentions": {} }]) t.deepEqual(promotions, [{ diff --git a/src/d2m/converters/message-to-event.js b/src/d2m/converters/message-to-event.js index aeda572..b96f645 100644 --- a/src/d2m/converters/message-to-event.js +++ b/src/d2m/converters/message-to-event.js @@ -1055,15 +1055,6 @@ async function messageToEvent(message, guild, options = {}, di) { continue } - // Provider - if (embed.provider?.name && embed.provider.name !== "Tenor") { - if (embed.provider.url) { - rep.addParagraph(`via ${embed.provider.name} ${embed.provider.url}`, tag`${embed.provider.name}`) - } else { - rep.addParagraph(`via ${embed.provider.name}`, tag`${embed.provider.name}`) - } - } - // Author and URL into a paragraph let authorNameText = embed.author?.name || "" if (authorNameText && embed.author?.icon_url) authorNameText = `⏺️ ${authorNameText}` // using the emoji instead of an image @@ -1113,7 +1104,18 @@ async function messageToEvent(message, guild, options = {}, di) { if (embed.video?.url) rep.addParagraph(`🎞️ ${dUtils.getPublicUrlForCdn(embed.video.url)}`) - if (embed.footer?.text) rep.addLine(`β€” ${embed.footer.text}`, tag`β€” ${embed.footer.text}`) + // Provider and footer (moved to bottom, below author/title, to improve room preview line) + if (embed.provider?.name && embed.provider.name !== "Tenor" && embed.provider.name !== "YouTube") { + const insertableFooterText = embed.footer?.text ? ` β€” ${embed.footer.text}` : "" + if (embed.provider.url) { + rep.addLine(`via ${embed.provider.name}${insertableFooterText || " " + embed.provider.url}`, tag`${embed.provider.name}${insertableFooterText}`) + } else { + rep.addLine(`via ${embed.provider.name}${insertableFooterText}`, tag`${embed.provider.name}${insertableFooterText}`) + } + } else if (embed.footer?.text) { + rep.addLine(`β€” ${embed.footer.text}`, tag`β€” ${embed.footer.text}`) + } + let {body, formatted_body: html} = rep.get() body = body.split("\n").map(l => "| " + l).join("\n") html = `
    ${html}
    ` diff --git a/src/d2m/converters/message-to-event.test.embeds.js b/src/d2m/converters/message-to-event.test.embeds.js index 91bbe2b..3764c83 100644 --- a/src/d2m/converters/message-to-event.test.embeds.js +++ b/src/d2m/converters/message-to-event.test.embeds.js @@ -204,6 +204,34 @@ test("message2event embeds: author url without name", async t => { }]) }) +test("message2event embeds: provider and footer", async t => { + const events = await messageToEvent(data.message_with_embeds.embed_provider_and_footer, data.guild.general) + t.deepEqual(events, [{ + $type: "m.room.message", + msgtype: "m.text", + body: "https://cohost.org/jkap/post/4794219-empty", + format: "org.matrix.custom.html", + formatted_body: `https://cohost.org/jkap/post/4794219-empty`, + "m.mentions": {} + }, { + $type: "m.room.message", + msgtype: "m.notice", + body: "| ## This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO https://cohost.org/jkap/post/4794219-empty" + + "\n| \n| 1v1 physical card game. Each player gets one standard deck of cards with a different backing to differentiate. Every turn proceeds as follows:" + + "\n| \n| * Both players draw eight cards" + + "\n| * Both players may choose up to eight cards to discard, then draw that number of cards to put back in their hand" + + "\n| * Both players present their best five-or-less-card pok..." + + "\n| via hthrflwrs on cohost β€” 29/2/2024, 2:17 PM", + format: "org.matrix.custom.html", + formatted_body: `

    This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO` + + `

    1v1 physical card game. Each player gets one standard deck of cards with a different backing to differentiate. Every turn proceeds as follows:` + + `

    hthrflwrs on cohost β€” 29/2/2024, 2:17 PM
    `, + "m.mentions": {} + }]) +}) + test("message2event embeds: 4 images", async t => { const events = await messageToEvent(data.message_with_embeds.four_images, data.guild.general) t.deepEqual(events, [{ @@ -254,9 +282,7 @@ test("message2event embeds: vx image", async t => { }, { $type: "m.room.message", msgtype: "m.notice", - body: "| via vxTwitter / fixvx https://github.com/dylanpdx/BetterTwitFix" - + "\n| " - + "\n| ## Twitter https://twitter.com/tomorrowcorp/status/1760330671074287875" + body: "| ## Twitter https://twitter.com/tomorrowcorp/status/1760330671074287875" + "\n| " + "\n| ## Tomorrow Corporation (@TomorrowCorp) https://vxtwitter.com/TomorrowCorp/status/1760330671074287875" + "\n| " @@ -266,15 +292,16 @@ test("message2event embeds: vx image", async t => { + "\n| " + "\n| πŸ’– 123 πŸ” 36" + "\n| " - + "\n| πŸ“Έ https://pbs.twimg.com/media/GG3zUMGbIAAxs3h.jpg", + + "\n| πŸ“Έ https://pbs.twimg.com/media/GG3zUMGbIAAxs3h.jpg" + + "\n| via vxTwitter / fixvx https://github.com/dylanpdx/BetterTwitFix", format: "org.matrix.custom.html", - formatted_body: `

    vxTwitter / fixvx` - + `

    Twitter` + formatted_body: `

    Twitter` + `

    Tomorrow Corporation (@TomorrowCorp)` + `

    Mark your calendar with a wet black stain! World of Goo 2 releases on May 23, 2024 on Nintendo Switch, Epic Games Store (Win/Mac), and http://WorldOfGoo2.com (Win/Mac/Linux).` + `

    https://tomorrowcorporation.com/posts/world-of-goo-2-now-with-100-more-release-dates-and-platforms` + `

    πŸ’– 123 πŸ” 36` - + `

    πŸ“Έ https://pbs.twimg.com/media/GG3zUMGbIAAxs3h.jpg

    `, + + `

    πŸ“Έ https://pbs.twimg.com/media/GG3zUMGbIAAxs3h.jpg

    ` + + `vxTwitter / fixvx
    `, "m.mentions": {} }]) }) @@ -291,16 +318,16 @@ test("message2event embeds: vx video", async t => { }, { $type: "m.room.message", msgtype: "m.notice", - body: "| via vxTwitter / fixvx https://github.com/dylanpdx/BetterTwitFix" - + "\n| \n| ## McDonald’s🀝@studiopierrot" + body: "| ## McDonald’s🀝@studiopierrot" + "\n| \n| πŸ’– 89 πŸ” 21 https://twitter.com/McDonalds/status/1759971752254341417" + "\n| \n| ## McDonald's (@McDonalds) https://vxtwitter.com/McDonalds/status/1759971752254341417" - + "\n| \n| 🎞️ https://video.twimg.com/ext_tw_video/1759967449548541952/pu/vid/avc1/1280x720/XN1LFIJqAFBdtaoh.mp4?tag=12", + + "\n| \n| 🎞️ https://video.twimg.com/ext_tw_video/1759967449548541952/pu/vid/avc1/1280x720/XN1LFIJqAFBdtaoh.mp4?tag=12" + + "\n| via vxTwitter / fixvx https://github.com/dylanpdx/BetterTwitFix", format: "org.matrix.custom.html", - formatted_body: `

    vxTwitter / fixvx` - + `

    McDonald’s🀝@studiopierrot\n\nπŸ’– 89 πŸ” 21` + formatted_body: `

    McDonald’s🀝@studiopierrot\n\nπŸ’– 89 πŸ” 21` + `

    McDonald's (@McDonalds)` - + `

    🎞️ https://video.twimg.com/ext_tw_video/1759967449548541952/pu/vid/avc1/1280x720/XN1LFIJqAFBdtaoh.mp4?tag=12

    `, + + `

    🎞️ https://video.twimg.com/ext_tw_video/1759967449548541952/pu/vid/avc1/1280x720/XN1LFIJqAFBdtaoh.mp4?tag=12

    ` + + `vxTwitter / fixvx
    `, "m.mentions": {} }]) }) @@ -317,8 +344,7 @@ test("message2event embeds: youtube video", async t => { }, { $type: "m.room.message", msgtype: "m.notice", - body: "| via YouTube https://www.youtube.com" - + "\n| \n| ## Happy O Funny https://www.youtube.com/channel/UCEpQ9aEb1NafpvWp5Aoizrg" + body: "| ## Happy O Funny https://www.youtube.com/channel/UCEpQ9aEb1NafpvWp5Aoizrg" + "\n| \n| ## Shoebill stork clattering sounds like machine guun~!! (Japan Matsue... https://www.youtube.com/watch?v=kDMHHw8JqLE" + "\n| \n| twitter" + "\n| https://twitter.com/matsuevogelpark" @@ -327,8 +353,7 @@ test("message2event embeds: youtube video", async t => { + "\n| \n| #shoebill #livingdinosaur #happyofunny #weirdcreature #weirdsoun..." + "\n| \n| 🎞️ https://www.youtube.com/embed/kDMHHw8JqLE", format: "org.matrix.custom.html", - formatted_body: `

    YouTube

    ` - + `

    Happy O Funny` + formatted_body: `

    Happy O Funny` + `

    Shoebill stork clattering sounds like machine guun~!! (Japan Matsue...` + `

    twitter
    https://twitter.com/matsuevogelpark

    The shoebill (Balaeniceps rex) also known as whalehead, whale-headed stork, or shoe-billed stork, is a very large stork-like bird. It derives its name from its enormous shoe-shaped bill
    some people also called them the living dinosaur~~

    #shoebill #livingdinosaur #happyofunny #weirdcreature #weirdsoun...` + `

    🎞️ https://www.youtube.com/embed/kDMHHw8JqLE` diff --git a/test/data.js b/test/data.js index eab9a63..8b6e052 100644 --- a/test/data.js +++ b/test/data.js @@ -5296,6 +5296,60 @@ module.exports = { } } ] + }, + embed_provider_and_footer: { + type: 0, + content: "https://cohost.org/jkap/post/4794219-empty", + author: { + id: "113340068197859328", + username: "kumaccino", + avatar: "b48302623a12bc7c59a71328f72ccb39", + discriminator: "0", + public_flags: 128, + premium_type: 0, + flags: 128, + banner: null, + accent_color: null, + global_name: "kumaccino", + avatar_decoration_data: null, + banner_color: null + }, + attachments: [], + channel_id: "112760669178241024", + embeds: [ + { + color: 8594767, + description: "1v1 physical card game. Each player gets one standard deck of cards with a different backing to differentiate. Every turn proceeds as follows:\n\n * Both players draw eight cards\n * Both players may choose up to eight cards to discard, then draw that number of cards to put back in their hand\n * Both players present their best five-or-less-card pok...", + provider: { + name: "hthrflwrs on cohost" + }, + footer: { + text: "29/2/2024, 2:17 PM" + }, + thumbnail: { + height: 1587, + placeholder: "GpoKP5BJZphshnhwmmmYlmh3l7+m+mwJ", + placeholder_version: 1, + proxy_url: "https://images-ext-2.discordapp.net/external/9vTXIzlXU4wyUZvWfmlmQkck8nGLUL-A090W4lWsZ48/https/staging.cohostcdn.org/avatar/292-6b64b03c-4ada-42f6-8452-109275bfe68d-profile.png", + url: "https://staging.cohostcdn.org/avatar/292-6b64b03c-4ada-42f6-8452-109275bfe68d-profile.png", + width: 1644 + }, + title: "This post nerdsniped me, so here's some RULES FOR REAL-LIFE BALATRO", + type: "link", + url: "https://cohost.org/jkap/post/4794219-empty" + } + ], + guild_id: "112760669178241024", + id: "1210387798297682020", + mentions: [], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2024-02-21T18:15:43.353000+00:00", + edited_timestamp: null, + flags: 0, + components: [] } }, message_with_components: {