diff --git a/src/protections/MessageIsMedia.ts b/src/protections/MessageIsMedia.ts index ac7ea76..7349913 100644 --- a/src/protections/MessageIsMedia.ts +++ b/src/protections/MessageIsMedia.ts @@ -35,7 +35,11 @@ export class MessageIsMedia extends Protection { public async handleEvent(mjolnir: Mjolnir, roomId: string, event: any): Promise { if (event['type'] === 'm.room.message') { - const content = event['content'] || {}; + let content = event['content'] || {}; + const relation = content["m.relates_to"] + if (relation?.["rel_type"] === "m.replace") { + content = content?.["m.new_content"] ?? content; + } const msgtype = content['msgtype'] || 'm.text'; const formattedBody = content['formatted_body'] || ''; const isMedia = msgtype === 'm.image' || msgtype === 'm.video' || msgtype === 'm.sticker' || formattedBody.toLowerCase().includes(' new Promise((resolve, reject) => { + client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => { + if (event.content.body.includes("Redacting event")) { + resolve(event); + } + })) + }); + await reply; + + await client.sendMessage(room, {body: "", msgtype: "m.text", "m.new_content": {msgtype: "m.image", body: ""}, "m.relates_to": {"rel_type": "m.replace"}}) + let reply2 = () => new Promise((resolve, reject) => { + client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => { + if (event.content.body.includes("Redacting event")) { + resolve(event); + } + })) + }); + await reply2; + }); });