2023-07-04 05:19:17 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const assert = require("assert").strict
|
|
|
|
const Ty = require("../../types")
|
|
|
|
|
|
|
|
const passthrough = require("../../passthrough")
|
2023-09-18 10:51:59 +00:00
|
|
|
const {discord, sync, db, select} = passthrough
|
2023-09-25 03:26:48 +00:00
|
|
|
/** @type {import("../converters/utils")} */
|
|
|
|
const utils = sync.require("../converters/utils")
|
2023-09-25 10:15:36 +00:00
|
|
|
/** @type {import("../converters/emoji")} */
|
|
|
|
const emoji = sync.require("../converters/emoji")
|
2023-07-04 05:19:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>} event
|
|
|
|
*/
|
|
|
|
async function addReaction(event) {
|
2023-10-05 23:31:10 +00:00
|
|
|
const channelID = select("channel_room", "channel_id", {room_id: event.room_id}).pluck().get()
|
2023-07-04 05:19:17 +00:00
|
|
|
if (!channelID) return // We just assume the bridge has already been created
|
2023-10-14 09:08:10 +00:00
|
|
|
const messageID = select("event_message", "message_id", {event_id: event.content["m.relates_to"].event_id}, "ORDER BY reaction_part").pluck().get()
|
2023-07-04 05:19:17 +00:00
|
|
|
if (!messageID) return // Nothing can be done if the parent message was never bridged.
|
|
|
|
|
2023-10-06 03:58:44 +00:00
|
|
|
const key = event.content["m.relates_to"].key
|
2023-09-25 10:15:36 +00:00
|
|
|
const discordPreferredEncoding = emoji.encodeEmoji(key, event.content.shortcode)
|
|
|
|
if (!discordPreferredEncoding) return
|
2023-09-19 12:37:15 +00:00
|
|
|
|
2023-09-25 03:26:48 +00:00
|
|
|
await discord.snow.channel.createReaction(channelID, messageID, discordPreferredEncoding) // acting as the discord bot itself
|
|
|
|
|
|
|
|
db.prepare("REPLACE INTO reaction (hashed_event_id, message_id, encoded_emoji) VALUES (?, ?, ?)").run(utils.getEventIDHash(event.event_id), messageID, discordPreferredEncoding)
|
2023-07-04 05:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.addReaction = addReaction
|