can retry actions with 🔁 emoji
This commit is contained in:
		@@ -61,10 +61,14 @@ module.exports = {
 | 
				
			|||||||
			formatted_body: "\u26a0 <strong>Bridged event from Discord not delivered</strong>"
 | 
								formatted_body: "\u26a0 <strong>Bridged event from Discord not delivered</strong>"
 | 
				
			||||||
				+ `<br>Gateway event: ${gatewayMessage.t}`
 | 
									+ `<br>Gateway event: ${gatewayMessage.t}`
 | 
				
			||||||
				+ `<br>${e.toString()}`
 | 
									+ `<br>${e.toString()}`
 | 
				
			||||||
				+ `<div><details><summary>Error trace</summary>`
 | 
									+ `<br><details><summary>Error trace</summary>`
 | 
				
			||||||
				+ `<pre>${stackLines.join("\n")}</pre></details></div>`
 | 
									+ `<pre>${stackLines.join("\n")}</pre></details>`
 | 
				
			||||||
				+ `<div><details><summary>Original payload</summary>`
 | 
									+ `<details><summary>Original payload</summary>`
 | 
				
			||||||
				+ `<pre>${util.inspect(gatewayMessage.d, false, 4, false)}</pre></details></div>`,
 | 
									+ `<pre>${util.inspect(gatewayMessage.d, false, 4, false)}</pre></details>`,
 | 
				
			||||||
 | 
								"moe.cadence.ooye.error": {
 | 
				
			||||||
 | 
									source: "discord",
 | 
				
			||||||
 | 
									payload: gatewayMessage
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
			"m.mentions": {
 | 
								"m.mentions": {
 | 
				
			||||||
				user_ids: ["@cadence:cadence.moe"]
 | 
									user_ids: ["@cadence:cadence.moe"]
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const util = require("util")
 | 
					const util = require("util")
 | 
				
			||||||
const Ty = require("../types")
 | 
					const Ty = require("../types")
 | 
				
			||||||
const {db, sync, as} = require("../passthrough")
 | 
					const {discord, db, sync, as} = require("../passthrough")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** @type {import("./actions/send-event")} */
 | 
					/** @type {import("./actions/send-event")} */
 | 
				
			||||||
const sendEvent = sync.require("./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")
 | 
					const utils = sync.require("./converters/utils")
 | 
				
			||||||
/** @type {import("../matrix/api")}) */
 | 
					/** @type {import("../matrix/api")}) */
 | 
				
			||||||
const api = sync.require("../matrix/api")
 | 
					const api = sync.require("../matrix/api")
 | 
				
			||||||
 | 
					/** @type {import("../matrix/read-registration")}) */
 | 
				
			||||||
 | 
					const reg = sync.require("../matrix/read-registration")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let lastReportedEvent = 0
 | 
					let lastReportedEvent = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,10 +42,14 @@ function guard(type, fn) {
 | 
				
			|||||||
				formatted_body: "\u26a0 <strong>Matrix event not delivered to Discord</strong>"
 | 
									formatted_body: "\u26a0 <strong>Matrix event not delivered to Discord</strong>"
 | 
				
			||||||
					+ `<br>Event type: ${type}`
 | 
										+ `<br>Event type: ${type}`
 | 
				
			||||||
					+ `<br>${e.toString()}`
 | 
										+ `<br>${e.toString()}`
 | 
				
			||||||
					+ `<div><details><summary>Error trace</summary>`
 | 
										+ `<br><details><summary>Error trace</summary>`
 | 
				
			||||||
					+ `<pre>${stackLines.join("\n")}</pre></details></div>`
 | 
										+ `<pre>${stackLines.join("\n")}</pre></details>`
 | 
				
			||||||
					+ `<div><details><summary>Original payload</summary>`
 | 
										+ `<details><summary>Original payload</summary>`
 | 
				
			||||||
					+ `<pre>${util.inspect(event, false, 4, false)}</pre></details></div>`,
 | 
										+ `<pre>${util.inspect(event, false, 4, false)}</pre></details>`,
 | 
				
			||||||
 | 
									"moe.cadence.ooye.error": {
 | 
				
			||||||
 | 
										source: "matrix",
 | 
				
			||||||
 | 
										payload: event
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
				"m.mentions": {
 | 
									"m.mentions": {
 | 
				
			||||||
					user_ids: ["@cadence:cadence.moe"]
 | 
										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",
 | 
					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
 | 
					 * @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 => {
 | 
					async event => {
 | 
				
			||||||
	if (utils.eventSenderIsFromDiscord(event.sender)) return
 | 
						if (utils.eventSenderIsFromDiscord(event.sender)) return
 | 
				
			||||||
 | 
						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)
 | 
							await addReaction.addReaction(event)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}))
 | 
					}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sync.addTemporaryListener(as, "type:m.room.avatar", guard("m.room.avatar",
 | 
					sync.addTemporaryListener(as, "type:m.room.avatar", guard("m.room.avatar",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user