2023-09-25 03:26:48 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const assert = require("assert").strict
|
|
|
|
const Ty = require("../../types")
|
|
|
|
|
|
|
|
const passthrough = require("../../passthrough")
|
|
|
|
const {discord, sync, db, select, from} = passthrough
|
|
|
|
/** @type {import("../converters/utils")} */
|
|
|
|
const utils = sync.require("../converters/utils")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Ty.Event.Outer_M_Room_Redaction} event
|
|
|
|
*/
|
|
|
|
async function deleteMessage(event) {
|
2023-10-05 23:31:10 +00:00
|
|
|
const rows = from("event_message").join("message_channel", "message_id").select("channel_id", "message_id").where({event_id: event.redacts}).all()
|
2024-01-10 02:48:13 +00:00
|
|
|
db.prepare("DELETE FROM event_message WHERE event_id = ?").run(event.event_id)
|
2023-10-02 09:10:50 +00:00
|
|
|
for (const row of rows) {
|
2024-01-10 02:48:13 +00:00
|
|
|
db.prepare("DELETE FROM message_channel WHERE message_id = ?").run(row.message_id)
|
2024-05-14 11:07:54 +00:00
|
|
|
await discord.snow.channel.deleteMessage(row.channel_id, row.message_id, event.content.reason)
|
2023-10-02 09:10:50 +00:00
|
|
|
}
|
2023-09-25 03:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Ty.Event.Outer_M_Room_Redaction} event
|
|
|
|
*/
|
|
|
|
async function removeReaction(event) {
|
|
|
|
const hash = utils.getEventIDHash(event.redacts)
|
2023-10-05 23:31:10 +00:00
|
|
|
const row = from("reaction").join("message_channel", "message_id").select("channel_id", "message_id", "encoded_emoji").where({hashed_event_id: hash}).get()
|
2023-09-25 03:26:48 +00:00
|
|
|
if (!row) return
|
2023-09-25 09:20:23 +00:00
|
|
|
await discord.snow.channel.deleteReactionSelf(row.channel_id, row.message_id, row.encoded_emoji)
|
|
|
|
db.prepare("DELETE FROM reaction WHERE hashed_event_id = ?").run(hash)
|
2023-09-25 03:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try everything that could possibly be redacted.
|
|
|
|
* @param {Ty.Event.Outer_M_Room_Redaction} event
|
|
|
|
*/
|
|
|
|
async function handle(event) {
|
|
|
|
await deleteMessage(event)
|
|
|
|
await removeReaction(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.handle = handle
|