From 9ea7198291323f66a622b0299aa117219b3165b2 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Sun, 15 Nov 2020 21:02:55 +0530 Subject: [PATCH] Add support for redacting discord messages --- main.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 317884c..c931062 100644 --- a/main.py +++ b/main.py @@ -70,12 +70,14 @@ async def on_message(message): content += f"\n{attachment.url}" if str(message.channel.id) == config["channel_id"]: - await message_send(content) + matrix_message = await message_send(content) + message_cache[message.id] = matrix_message @discord_client.event async def on_message_delete(message): - pass + if message.id in message_cache: + await message_redact(message_cache[message.id]) @discord_client.event @@ -202,7 +204,7 @@ async def create_matrix_client(): async def message_send(message): - await matrix_client.room_send( + message = await matrix_client.room_send( room_id=config["room_id"], message_type="m.room.message", content={ @@ -211,6 +213,16 @@ async def message_send(message): } ) + return message.event_id + + +async def message_redact(message): + await matrix_client.room_redact( + room_id=config["room_id"], + event_id=message, + reason="Message deleted" + ) + async def message_callback(room, event): # Don't act on activities in other rooms