out-of-your-element/d2m/actions/delete-message.js

24 lines
856 B
JavaScript
Raw Normal View History

2023-08-17 13:22:14 +00:00
// @ts-check
const passthrough = require("../../passthrough")
const {sync, db, select} = passthrough
2023-08-17 13:22:14 +00:00
/** @type {import("../../matrix/api")} */
const api = sync.require("../../matrix/api")
/**
* @param {import("discord-api-types/v10").GatewayMessageDeleteDispatchData} data
*/
async function deleteMessage(data) {
2023-10-05 23:31:10 +00:00
const roomID = select("channel_room", "room_id", {channel_id: data.channel_id}).pluck().get()
2023-08-17 13:22:14 +00:00
if (!roomID) return
2023-10-05 23:31:10 +00:00
const eventsToRedact = select("event_message", "event_id", {message_id: data.id}).pluck().all()
2023-08-17 13:22:14 +00:00
for (const eventID of eventsToRedact) {
2023-09-06 00:31:38 +00:00
// Unfortunately, we can't specify a sender to do the redaction as, unless we find out that info via the audit logs
2023-08-17 13:22:14 +00:00
await api.redactEvent(roomID, eventID)
db.prepare("DELETE FROM event_message WHERE event_id = ?").run(eventID)
2023-08-17 13:22:14 +00:00
}
}
module.exports.deleteMessage = deleteMessage