From efa0171172f1b1cf0e3cdf844a4df7cf5829f6de Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 3 Sep 2023 16:03:37 +1200 Subject: [PATCH] =?UTF-8?q?can=20retry=20actions=20with=20=F0=9F=94=81=20e?= =?UTF-8?q?moji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- d2m/event-dispatcher.js | 12 ++++++++---- m2d/event-dispatcher.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/d2m/event-dispatcher.js b/d2m/event-dispatcher.js index bbfc5a0..c73b95b 100644 --- a/d2m/event-dispatcher.js +++ b/d2m/event-dispatcher.js @@ -61,10 +61,14 @@ module.exports = { formatted_body: "\u26a0 Bridged event from Discord not delivered" + `
Gateway event: ${gatewayMessage.t}` + `
${e.toString()}` - + `
Error trace` - + `
${stackLines.join("\n")}
` - + `
Original payload` - + `
${util.inspect(gatewayMessage.d, false, 4, false)}
`, + + `
Error trace` + + `
${stackLines.join("\n")}
` + + `
Original payload` + + `
${util.inspect(gatewayMessage.d, false, 4, false)}
`, + "moe.cadence.ooye.error": { + source: "discord", + payload: gatewayMessage + }, "m.mentions": { user_ids: ["@cadence:cadence.moe"] } diff --git a/m2d/event-dispatcher.js b/m2d/event-dispatcher.js index 29319d8..d81e7cf 100644 --- a/m2d/event-dispatcher.js +++ b/m2d/event-dispatcher.js @@ -6,7 +6,7 @@ const util = require("util") const Ty = require("../types") -const {db, sync, as} = require("../passthrough") +const {discord, db, sync, as} = require("../passthrough") /** @type {import("./actions/send-event")} */ const sendEvent = sync.require("./actions/send-event") @@ -16,6 +16,8 @@ const addReaction = sync.require("./actions/add-reaction") const utils = sync.require("./converters/utils") /** @type {import("../matrix/api")}) */ const api = sync.require("../matrix/api") +/** @type {import("../matrix/read-registration")}) */ +const reg = sync.require("../matrix/read-registration") let lastReportedEvent = 0 @@ -40,10 +42,14 @@ function guard(type, fn) { formatted_body: "\u26a0 Matrix event not delivered to Discord" + `
Event type: ${type}` + `
${e.toString()}` - + `
Error trace` - + `
${stackLines.join("\n")}
` - + `
Original payload` - + `
${util.inspect(event, false, 4, false)}
`, + + `
Error trace` + + `
${stackLines.join("\n")}
` + + `
Original payload` + + `
${util.inspect(event, false, 4, false)}
`, + "moe.cadence.ooye.error": { + source: "matrix", + payload: event + }, "m.mentions": { user_ids: ["@cadence:cadence.moe"] } @@ -52,6 +58,17 @@ function guard(type, fn) { } } +async function retry(roomID, eventID) { + const event = await api.getEvent(roomID, eventID) + const error = event.content["moe.cadence.ooye.error"] + if (event.sender !== `@${reg.sender_localpart}:${reg.ooye.server_name}` || !error) return + if (error.source === "matrix") { + as.emit("type:" + error.payload.type, error.payload) + } else if (error.source === "discord") { + discord.cloud.emit("event", error.payload) + } +} + sync.addTemporaryListener(as, "type:m.room.message", guard("m.room.message", /** * @param {Ty.Event.Outer_M_Room_Message | Ty.Event.Outer_M_Room_Message_File} event it is a m.room.message because that's what this listener is filtering for @@ -76,7 +93,12 @@ sync.addTemporaryListener(as, "type:m.reaction", guard("m.reaction", */ async event => { if (utils.eventSenderIsFromDiscord(event.sender)) return - await addReaction.addReaction(event) + if (event.content["m.relates_to"].key === "🔁") { + // Try to bridge a failed event again? + await retry(event.room_id, event.content["m.relates_to"].event_id) + } else { + await addReaction.addReaction(event) + } })) sync.addTemporaryListener(as, "type:m.room.avatar", guard("m.room.avatar",