Add subreddit link replacer

This commit is contained in:
deadcade 2022-08-09 10:09:20 +02:00
parent cbddda9a76
commit f26c8fde6c

View file

@ -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"<a href=\"https://reddit.com/{part}\">{part}</a>")
# If anything was changed processing the message, edit it
if not new_body == orig_body:
await edit_message(room.room_id, event, new_body)