11from urllib .parse import urlparse , unquote
2-
32from atproto import Client
4-
53from .base import ParserCommand , irc_color
64from .registry import register_parser
75
@@ -28,19 +26,34 @@ def parse(self, msg):
2826 client = Client ()
2927 client .login (self .config ['bluesky_username' ], self .config ['bluesky_password' ])
3028
31- # resolve handle to DID
3229 res = client .com .atproto .identity .resolve_handle ({'handle' : handle })
3330 did = res ['did' ]
3431
3532 uri = f"at://{ did } /app.bsky.feed.post/{ post_rkey } "
3633 post_thread = client .app .bsky .feed .get_post_thread ({'uri' : uri , 'depth' : 0 })
3734
38- # extract post content
39- content = post_thread ['thread' ]['post' ]['record' ]['text' ]
35+ # handle post
36+ record = post_thread ['thread' ]['post' ]['record' ]
37+ content = record .get ('text' , '' )
4038 display_handle = irc_color (f'@{ handle } ' , 'blue' , reset = True )
41- lines .append (f"{ display_handle } : { content } " )
39+ line = f"{ display_handle } : { content } "
40+
41+ # handle images
42+ images = record .get ('images' , [])
43+ if images :
44+ image_urls = [img .get ('url' ) for img in images if img .get ('url' )]
45+ if image_urls :
46+ line += " " + " " .join (image_urls )
47+
48+ # handle external links
49+ if record .get ('external' ):
50+ external_url = record ['external' ].get ('uri' )
51+ if external_url :
52+ line += f" { external_url } "
53+
54+ lines .append (line )
4255
43- except Exception : #nosec
56+ except Exception :
4457 pass
4558
4659 return lines
0 commit comments