forked from cadence/out-of-your-element
Support m->d redacting messages and reactions
This commit is contained in:
parent
2e68c7edf5
commit
8d3ac665c9
7 changed files with 74 additions and 2 deletions
39
m2d/actions/redact.js
Normal file
39
m2d/actions/redact.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
// @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) {
|
||||
const row = from("event_message").join("message_channel", "message_id").select("channel_id", "message_id").and("WHERE event_id = ?").get(event.event_id)
|
||||
if (!row) return
|
||||
return discord.snow.channel.deleteMessage(row.channel_id, row.message_id, event.content.reason)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Ty.Event.Outer_M_Room_Redaction} event
|
||||
*/
|
||||
async function removeReaction(event) {
|
||||
const hash = utils.getEventIDHash(event.redacts)
|
||||
const row = from("reaction").join("message_channel", "message_id").select("channel_id", "message_id", "encoded_emoji").and("WHERE hashed_event_id = ?").get(hash)
|
||||
if (!row) return
|
||||
return discord.snow.channel.deleteReactionSelf(row.channel_id, row.message_id, row.encoded_emoji)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
Loading…
Add table
Add a link
Reference in a new issue