Add subreddit link replacer
This commit is contained in:
parent
cbddda9a76
commit
f26c8fde6c
1 changed files with 5 additions and 0 deletions
5
main.py
5
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"<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)
|
||||
|
|
Loading…
Reference in a new issue