Fix Arch pkg and AUR pkg link replacer not working without spaces

This commit is contained in:
deadcade 2022-08-29 14:15:13 +02:00
parent a592871047
commit 0ae0720663
1 changed files with 6 additions and 6 deletions

12
main.py
View File

@ -462,14 +462,14 @@ async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) ->
if part.startswith("r/"):
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('}')
for part in event.body.split("{pkg|"):
if "}" in part:
pkg = part.split("}")[0]
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('}')
for part in event.body.split("{aur|"):
if "}" in part:
pkg = part.split("}")[0]
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