From f26c8fde6caf2b5536e902aed71cb446939cdafc Mon Sep 17 00:00:00 2001 From: deadcade Date: Tue, 9 Aug 2022 10:09:20 +0200 Subject: [PATCH] Add subreddit link replacer --- main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.py b/main.py index 7d3df55..95b33a4 100644 --- a/main.py +++ b/main.py @@ -361,6 +361,11 @@ async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) -> for to_replace in text_replace.keys(): if ";" + to_replace + ";" in new_body: new_body = new_body.replace(";" + to_replace + ";", text_replace[to_replace]) + # Subreddit linker (type r/subreddit to get [r/subreddit](https://reddit.com/r/subreddit)) + if event.body.count("r/") > 0: + for part in event.body.split(" "): + if part.startswith("r/"): + new_body = new_body.replace(part, f"{part}") # If anything was changed processing the message, edit it if not new_body == orig_body: await edit_message(room.room_id, event, new_body)