forked from cadence/out-of-your-element
add error handler and message deleter
This commit is contained in:
parent
e3737997ec
commit
6de13338a8
3 changed files with 100 additions and 8 deletions
29
d2m/actions/delete-message.js
Normal file
29
d2m/actions/delete-message.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
// @ts-check
|
||||
|
||||
const passthrough = require("../../passthrough")
|
||||
const { sync, db } = passthrough
|
||||
/** @type {import("../converters/edit-to-changes")} */
|
||||
const editToChanges = sync.require("../converters/edit-to-changes")
|
||||
/** @type {import("../../matrix/api")} */
|
||||
const api = sync.require("../../matrix/api")
|
||||
|
||||
/**
|
||||
* @param {import("discord-api-types/v10").GatewayMessageDeleteDispatchData} data
|
||||
*/
|
||||
async function deleteMessage(data) {
|
||||
/** @type {string?} */
|
||||
const roomID = db.prepare("SELECT channel_id FROM channel_room WHERE channel_id = ?").pluck().get(data.channel_id)
|
||||
if (!roomID) return
|
||||
|
||||
/** @type {string[]} */
|
||||
const eventsToRedact = db.prepare("SELECT event_id FROM event_message WHERE message_id = ?").pluck().all(data.id)
|
||||
|
||||
for (const eventID of eventsToRedact) {
|
||||
// Unfortuately, we can't specify a sender to do the redaction as, unless we find out that info via the audit logs
|
||||
await api.redactEvent(roomID, eventID)
|
||||
db.prepare("DELETE from event_message WHERE event_id = ?").run(eventID)
|
||||
// TODO: Consider whether this code could be reused between edited messages and deleted messages.
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.deleteMessage = deleteMessage
|
Loading…
Add table
Add a link
Reference in a new issue