d->m: Support bulk message deletion from bots
This commit is contained in:
parent
9efd6a49b8
commit
20bab453ef
3 changed files with 30 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
// @ts-check
|
||||
|
||||
const passthrough = require("../../passthrough")
|
||||
const {sync, db, select} = passthrough
|
||||
const {sync, db, select, from} = passthrough
|
||||
/** @type {import("../../matrix/api")} */
|
||||
const api = sync.require("../../matrix/api")
|
||||
|
||||
|
@ -21,4 +21,22 @@ async function deleteMessage(data) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("discord-api-types/v10").GatewayMessageDeleteBulkDispatchData} data
|
||||
*/
|
||||
async function deleteMessageBulk(data) {
|
||||
const roomID = select("channel_room", "room_id", {channel_id: data.channel_id}).pluck().get()
|
||||
if (!roomID) return
|
||||
|
||||
const sids = JSON.stringify(data.ids)
|
||||
const eventsToRedact = from("event_message").pluck("event_id").and("WHERE message_id IN (SELECT value FROM json_each(?)").all(sids)
|
||||
db.prepare("DELETE FROM message_channel WHERE message_id IN (SELECT value FROM json_each(?)").run(sids)
|
||||
db.prepare("DELETE FROM event_message WHERE message_id IN (SELECT value FROM json_each(?)").run(sids)
|
||||
for (const eventID of eventsToRedact) {
|
||||
// Awaiting will make it go slower, but since this could be a long-running operation either way, we want to leave rate limit capacity for other operations
|
||||
await api.redactEvent(roomID, eventID)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.deleteMessage = deleteMessage
|
||||
module.exports.deleteMessageBulk = deleteMessageBulk
|
||||
|
|
|
@ -153,6 +153,9 @@ const utils = {
|
|||
} else if (message.t === "MESSAGE_DELETE") {
|
||||
await eventDispatcher.onMessageDelete(client, message.d)
|
||||
|
||||
} else if (message.t === "MESSAGE_DELETE_BULK") {
|
||||
await eventDispatcher.onMessageDeleteBulk(client, message.d)
|
||||
|
||||
} else if (message.t === "TYPING_START") {
|
||||
await eventDispatcher.onTypingStart(client, message.d)
|
||||
|
||||
|
|
|
@ -252,6 +252,14 @@ module.exports = {
|
|||
await deleteMessage.deleteMessage(data)
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {import("./discord-client")} client
|
||||
* @param {DiscordTypes.GatewayMessageDeleteBulkDispatchData} data
|
||||
*/
|
||||
async onMessageDeleteBulk(client, data) {
|
||||
await deleteMessage.deleteMessageBulk(data)
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {import("./discord-client")} client
|
||||
* @param {DiscordTypes.GatewayTypingStartDispatchData} data
|
||||
|
|
Loading…
Reference in a new issue