m2d reactions (untested)

This commit is contained in:
Cadence Ember 2023-07-04 17:19:17 +12:00
parent 39cdba9f90
commit 61120d92c6
7 changed files with 58 additions and 11 deletions

View file

@ -0,0 +1,25 @@
// @ts-check
const assert = require("assert").strict
const Ty = require("../../types")
const passthrough = require("../../passthrough")
const { discord, sync, db } = passthrough
/**
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>} event
*/
async function addReaction(event) {
const channelID = db.prepare("SELECT channel_id FROM channel_room WHERE room_id = ?").pluck().get(event.room_id)
if (!channelID) return // We just assume the bridge has already been created
const messageID = db.prepare("SELECT message_id FROM event_message WHERE event_id = ? AND part = 0").pluck().get(event.content["m.relates_to"].event_id) // 0 = primary
if (!messageID) return // Nothing can be done if the parent message was never bridged.
// no need to sync the matrix member to the other side. but if I did need to, this is where I'd do it
const emoji = event.content["m.relates_to"].key // TODO: handle custom text or emoji reactions
return discord.snow.channel.createReaction(channelID, messageID, emoji)
}
module.exports.addReaction = addReaction

View file

@ -1,5 +1,6 @@
// @ts-check
const Ty = require("../../types")
const DiscordTypes = require("discord-api-types/v10")
const markdown = require("discord-markdown")
@ -9,7 +10,7 @@ const { sync, db, discord } = passthrough
const file = sync.require("../../matrix/file")
/**
* @param {import("../../types").Event.Outer<import("../../types").Event.M_Room_Message>} event
* @param {Ty.Event.Outer<Ty.Event.M_Room_Message>} event
*/
function eventToMessage(event) {
/** @type {(DiscordTypes.RESTPostAPIWebhookWithTokenJSONBody & {files?: {name: string, file: Buffer}[]})[]} */

View file

@ -4,19 +4,30 @@
* Grab Matrix events we care about, check them, and bridge them.
*/
const Ty = require("../types")
const {sync, as} = require("../passthrough")
/** @type {import("./actions/send-event")} */
const sendEvent = sync.require("./actions/send-event")
/** @type {import("./actions/add-reaction")} */
const addReaction = sync.require("./actions/add-reaction")
/** @type {import("./converters/utils")} */
const utils = sync.require("./converters/utils")
sync.addTemporaryListener(as, "type:m.room.message",
/**
* @param {import("../types").Event.Outer<import("../types").Event.M_Room_Message>} event it is a m.room.message because that's what this listener is filtering for
* @param {Ty.Event.Outer<Ty.Event.M_Room_Message>} event it is a m.room.message because that's what this listener is filtering for
*/
async event => {
if (utils.eventSenderIsFromDiscord(event.sender)) return
const messageResponses = await sendEvent.sendEvent(event)
})
sync.addTemporaryListener(as, "type:m.reaction",
/**
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>} event it is a m.reaction because that's what this listener is filtering for
*/
async event => {
if (utils.eventSenderIsFromDiscord(event.sender)) return
await addReaction.addReaction(event)
})