diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index f8f9b57..6fdf32e 100644 --- a/d2m/converters/message-to-event.js +++ b/d2m/converters/message-to-event.js @@ -247,8 +247,19 @@ async function messageToEvent(message, guild, options = {}, di) { : attachment.content_type?.startsWith("text/") ? "📝" : attachment.content_type?.startsWith("audio/") ? "🎶" : "📄" + // no native media spoilers in Element, so we'll post a link instead, forcing it to not preview using a blockquote + if (attachment.filename.startsWith("SPOILER_")) { + return { + $type: "m.room.message", + "m.mentions": mentions, + msgtype: "m.text", + body: `${emoji} Uploaded SPOILER file: ${attachment.url} (${pb(attachment.size)})`, + format: "org.matrix.custom.html", + formatted_body: `
${emoji} Uploaded SPOILER file: View (${pb(attachment.size)})` + } + } // for large files, always link them instead of uploading so I don't use up all the space in the content repo - if (attachment.size > reg.ooye.max_file_size) { + else if (attachment.size > reg.ooye.max_file_size) { return { $type: "m.room.message", "m.mentions": mentions, diff --git a/d2m/converters/message-to-event.test.js b/d2m/converters/message-to-event.test.js index 117cdac..0f9260b 100644 --- a/d2m/converters/message-to-event.test.js +++ b/d2m/converters/message-to-event.test.js @@ -104,6 +104,18 @@ test("message2event: attachment with no content", async t => { }]) }) +test("message2event: spoiler attachment", async t => { + const events = await messageToEvent(data.message.spoiler_attachment, data.guild.general, {}) + t.deepEqual(events, [{ + $type: "m.room.message", + "m.mentions": {}, + msgtype: "m.text", + body: "📄 Uploaded SPOILER file: https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci (74 KB)", + format: "org.matrix.custom.html", + formatted_body: "
📄 Uploaded SPOILER file: View (74 KB)" + }]) +}) + test("message2event: stickers", async t => { const events = await messageToEvent(data.message.sticker, data.guild.general, {}) t.deepEqual(events, [{ diff --git a/test/data.js b/test/data.js index 32ee3b0..98c943a 100644 --- a/test/data.js +++ b/test/data.js @@ -531,6 +531,44 @@ module.exports = { flags: 0, components: [] }, + spoiler_attachment: { + type: 0, + tts: false, + timestamp: '2023-09-02T09:38:29.480000+00:00', + referenced_message: null, + pinned: false, + nonce: '1147465562901708800', + mentions: [], + mention_roles: [], + mention_everyone: false, + id: '1147465564600676383', + flags: 0, + embeds: [], + edited_timestamp: null, + content: '', + components: [], + channel_id: '1100319550446252084', + author: { + username: 'cadence.worm', + public_flags: 0, + id: '772659086046658620', + global_name: 'cadence', + discriminator: '0', + avatar_decoration_data: null, + avatar: '4b5c4b28051144e4c111f0113a0f1cf1' + }, + attachments: [ + { + url: 'https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci', + size: 73792, + proxy_url: 'https://media.discordapp.net/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci', + id: '1147465564307079258', + flags: 8, + filename: 'SPOILER_69-GNDP-CADENCE.nfs.gci' + } + ], + guild_id: '1100319549670301727' + }, skull_webp_attachment_with_content: { type: 0, tts: false,