diff --git a/d2m/converters/message-to-event.test.js b/d2m/converters/message-to-event.test.js index 07a45f7..323dc78 100644 --- a/d2m/converters/message-to-event.test.js +++ b/d2m/converters/message-to-event.test.js @@ -23,6 +23,12 @@ test("message2event: stickers", async t => { }, }, { $type: "m.sticker", - todo: "todo" + body: "pomu puff - damn that tiny lil bitch really chuffing. puffing that fat ass dart", + info: { + mimetype: "image/png" + // thumbnail_url + // thumbnail_info + }, + url: "mxc://" }]) }) diff --git a/db/ooye.db b/db/ooye.db index 924e599..e62e0af 100644 Binary files a/db/ooye.db and b/db/ooye.db differ diff --git a/matrix/file.js b/matrix/file.js index 62a4550..a373676 100644 --- a/matrix/file.js +++ b/matrix/file.js @@ -80,8 +80,24 @@ function emoji(emojiID, animated) { else return base + ".png" } +const stickerFormat = new Map([ + [1, {label: "PNG", ext: "png", mime: "image/png"}], + [2, {label: "APNG", ext: "png", mime: "image/apng"}], + [3, {label: "LOTTIE", ext: "json", mime: "application/json"}], + [4, {label: "GIF", ext: "gif", mime: "image/gif"}] +]) + +function sticker(sticker) { + const format = stickerFormat.get(sticker.format_type) + if (!format) throw new Error(`No such format ${sticker.format_type} for sticker ${JSON.stringify(sticker)}`) + const ext = format.ext + return `/stickers/${sticker.id}.${ext}` +} + module.exports.guildIcon = guildIcon module.exports.userAvatar = userAvatar module.exports.memberAvatar = memberAvatar module.exports.emoji = emoji +module.exports.stickerFormat = stickerFormat +module.exports.sticker = sticker module.exports.uploadDiscordFileToMxc = uploadDiscordFileToMxc diff --git a/notes.md b/notes.md index e63d9e5..3491682 100644 --- a/notes.md +++ b/notes.md @@ -60,6 +60,22 @@ The context-sensitive /invite command will invite Matrix users to the correspond # d2m events +## Login - backfill + +Need to backfill any messages that were missed while offline. + +After logging in, check last_message_id on each channel and compare against database to see if anything has been missed. However, mustn't interpret old channels from before the bridge was created as being "new". So, something has been missed if: + +- The last_message_id is not in the table of bridged messages +- The channel is already set up with a bridged room +- A message has been bridged in that channel before + +(If either of the last two conditions is false, that means the channel predates the bridge and we haven't actually missed anything there.) + +For channels that have missed messages, use the getChannelMessages function, and bridge each in turn. + +Can use custom transaction ID (?) to send the original timestamps to Matrix. See appservice docs for details. + ## Message sent 1. Transform content. diff --git a/test/data.js b/test/data.js index c94d132..9704c8d 100644 --- a/test/data.js +++ b/test/data.js @@ -47,7 +47,18 @@ module.exports = { general: { owner_id: "112760500130975744", premium_tier: 3, - stickers: [], + stickers: [{ + version: 1683838696974, + type: 2, + tags: "sunglasses", + name: "pomu puff", + id: "1106323941183717586", + guild_id: "112760669178241024", + format_type: 1, + description: "damn that tiny lil bitch really chuffing. puffing that fat ass dart", + available: true, + asset: "" + }], max_members: 500000, splash: "86a34ed02524b972918bef810087f8e7", explicit_content_filter: 0,