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",