Add AUR and Arch package link shortcuts

This commit is contained in:
deadcade 2022-08-25 20:27:44 +02:00
parent f26c8fde6c
commit eed3adc4a3

11
main.py
View file

@ -366,6 +366,17 @@ async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) ->
for part in event.body.split(" "): for part in event.body.split(" "):
if part.startswith("r/"): if part.startswith("r/"):
new_body = new_body.replace(part, f"<a href=\"https://reddit.com/{part}\">{part}</a>") new_body = new_body.replace(part, f"<a href=\"https://reddit.com/{part}\">{part}</a>")
if event.body.count("{pkg|") > 0:
for part in event.body.split(" "):
if part.startswith("{pkg|") and part.endswith("}"):
pkg = part.split('|')[1].rstrip('}')
new_body = new_body.replace(part, "<a href=\"https://archlinux.org/packages/?name=" + pkg + "\">" + pkg + "</a>")
if event.body.count("{aur|") > 0:
for part in event.body.split(" "):
if part.startswith("{aur|") and part.endswith("}"):
pkg = part.split('|')[1].rstrip('}')
new_body = new_body.replace(part, "<a href=\"https://aur.archlinux.org/packages?K=" + pkg + "\">" + pkg + "</a>")
# If anything was changed processing the message, edit it # If anything was changed processing the message, edit it
if not new_body == orig_body: if not new_body == orig_body:
await edit_message(room.room_id, event, new_body) await edit_message(room.room_id, event, new_body)