Skip to content

Commit 31ed2a0

Browse files
authored
Use type refinement for post_caption
1 parent 8cb8932 commit 31ed2a0

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/instawebhooks/__main__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,18 @@ async def create_embed(post: Post):
145145
profile_pic_file = File(io.BytesIO(profile_pic_bytes), "profile_pic.webp")
146146

147147
# Format the post caption with clickable links for mentions and hashtags
148-
post_caption = re.sub(
149-
r"#([a-zA-Z0-9]+\b)",
150-
r"[#\1](https://www.instagram.com/explore/tags/\1)",
151-
post.caption,
152-
)
153-
post_caption = re.sub(
154-
r"@([a-zA-Z0-9_]+\b)",
155-
r"[@\1](https://www.instagram.com/\1)",
156-
post_caption,
157-
)
148+
post_caption = post.caption
149+
if post_caption is str:
150+
post_caption = re.sub(
151+
r"#([a-zA-Z0-9]+\b)",
152+
r"[#\1](https://www.instagram.com/explore/tags/\1)",
153+
post_caption,
154+
)
155+
post_caption = re.sub(
156+
r"@([a-zA-Z0-9_]+\b)",
157+
r"[@\1](https://www.instagram.com/\1)",
158+
post_caption,
159+
)
158160

159161
embed = Embed(
160162
color=13500529,

0 commit comments

Comments
 (0)