From 29d93658b38e40c809bcefe87db6740da4d01327 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Mon, 16 Nov 2020 14:08:27 +0530 Subject: [PATCH] Update matrix message redaction --- main.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 933b92a..64bc3e1 100644 --- a/main.py +++ b/main.py @@ -34,8 +34,6 @@ intents.members = True discord_client = discord.Client(intents=intents) logging.basicConfig(level=logging.INFO) - -deletion_queue = [] message_cache = {} @@ -53,12 +51,6 @@ async def on_message(message): if message.author.bot: return - # Delete redacted messages - for webhook_message in deletion_queue: - message_ = message_cache[webhook_message] - await message_.delete() - deletion_queue.remove(webhook_message) - # Replace Discord IDs with mentions and emotes content = await process_discord(message.content) @@ -275,7 +267,12 @@ async def redaction_callback(room, event): if event.sender == matrix_client.user: return - deletion_queue.append(event.redacts) + # Redact webhook message + try: + message = message_cache[event.redacts] + await message.delete() + except KeyError: + pass async def typing_callback(room, event):