From c7ddf638dbd658057ec6a7a018a23b0693a97890 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 19 Sep 2023 23:02:51 +1200 Subject: [PATCH] d->m custom emoji reactions --- d2m/actions/add-reaction.js | 20 +++++++++++++++++++- d2m/event-dispatcher.js | 1 - 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/d2m/actions/add-reaction.js b/d2m/actions/add-reaction.js index a08d5843..c9e99a5a 100644 --- a/d2m/actions/add-reaction.js +++ b/d2m/actions/add-reaction.js @@ -17,16 +17,34 @@ const createRoom = sync.require("../actions/create-room") async function addReaction(data) { const user = data.member?.user assert.ok(user && user.username) + const parentID = select("event_message", "event_id", "WHERE message_id = ? AND part = 0").pluck().get(data.message_id) // 0 = primary if (!parentID) return // Nothing can be done if the parent message was never bridged. assert.equal(typeof parentID, "string") + + let key + if (data.emoji.id) { + // Custom emoji + const mxc = select("emoji", "mxc_url", "WHERE emoji_id = ?").pluck().get(data.emoji.id) + if (mxc) { + // The custom emoji is registered and we should send it + key = mxc + } else { + // The custom emoji is not registered. We *could* register it right now and it would work, but for now I'm just going to send the name. It's whatever. TODO change this probably. + key = "<" + data.emoji.name + ">" + } + } else { + // Default emoji + key = data.emoji.name + } + const roomID = await createRoom.ensureRoom(data.channel_id) const senderMxid = await registerUser.ensureSimJoined(user, roomID) const eventID = await api.sendEvent(roomID, "m.reaction", { "m.relates_to": { rel_type: "m.annotation", event_id: parentID, - key: data.emoji.name + key } }, senderMxid) return eventID diff --git a/d2m/event-dispatcher.js b/d2m/event-dispatcher.js index 93f74688..82c6adb0 100644 --- a/d2m/event-dispatcher.js +++ b/d2m/event-dispatcher.js @@ -207,7 +207,6 @@ module.exports = { async onReactionAdd(client, data) { if (data.user_id === client.user.id) return // m2d reactions are added by the discord bot user - do not reflect them back to matrix. discordCommandHandler.onReactionAdd(data) - if (data.emoji.id !== null) return // TODO: image emoji reactions await addReaction.addReaction(data) },