From 8cb893285103427ea89a68774c35191cfa38898b Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Mon, 19 Aug 2024 23:59:57 +0000 Subject: [PATCH] Add hyperlinks for mentions --- src/instawebhooks/__main__.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/instawebhooks/__main__.py b/src/instawebhooks/__main__.py index 218bce2..f3d3017 100644 --- a/src/instawebhooks/__main__.py +++ b/src/instawebhooks/__main__.py @@ -144,15 +144,17 @@ async def create_embed(post: Post): post_image_file = File(io.BytesIO(post_image_bytes), "post_image.webp") profile_pic_file = File(io.BytesIO(profile_pic_bytes), "profile_pic.webp") - # Replace hashtags with clickable links - if post.caption is None: - post_caption = "" - else: - post_caption = re.sub( - r"#([a-zA-Z0-9]+\b)", - r"[#\1](https://www.instagram.com/explore/tags/\1)", - post.caption, - ) + # Format the post caption with clickable links for mentions and hashtags + post_caption = re.sub( + r"#([a-zA-Z0-9]+\b)", + r"[#\1](https://www.instagram.com/explore/tags/\1)", + post.caption, + ) + post_caption = re.sub( + r"@([a-zA-Z0-9_]+\b)", + r"[@\1](https://www.instagram.com/\1)", + post_caption, + ) embed = Embed( color=13500529,