@@ -44,7 +44,7 @@ def get_best_criteria(video, nb_criteria):
4444 return [(crit .criteria , crit .score ) for crit in criteria_list ]
4545
4646
47- def prepare_tweet (video : Entity , dest : Literal ["twitter" , "bluesky" ]):
47+ def prepare_text (video : Entity , dest : Literal ["twitter" , "bluesky" ]):
4848 """Create the tweet text from the video."""
4949
5050 uploader = video .metadata ["uploader" ]
@@ -68,11 +68,12 @@ def prepare_tweet(video: Entity, dest: Literal["twitter", "bluesky"]):
6868 CriteriaLocale .objects .filter (language = language ).values_list ("criteria__name" , "label" )
6969 )
7070
71- # Replace "@" by a smaller "@" to avoid false mentions in the tweet
72- video_title = video .metadata ["name" ].replace ("@" , "﹫" )
71+ if dest == "twitter" :
72+ # Replace "@" by a smaller "@" to avoid false mentions in the tweet
73+ video_title = video .metadata ["name" ].replace ("@" , "﹫" )
7374
74- # Replace "." in between words to avoid in the tweet false detection of links
75- video_title = re .sub (r"\b(?:\.)\b" , "․" , video_title )
75+ # Replace "." in between words to avoid in the tweet false detection of links
76+ video_title = re .sub (r"\b(?:\.)\b" , "․" , video_title )
7677
7778 # Generate the text of the tweet
7879 poll_rating = video .all_poll_ratings .get (poll__name = DEFAULT_POLL_NAME )
@@ -103,7 +104,8 @@ def prepare_tweet(video: Entity, dest: Literal["twitter", "bluesky"]):
103104 video_id = video_id ,
104105 )
105106
106- if dest == "twitter" :
107+ if dest != "bluesky" :
108+ # on Bluesky the URL preview is attached separately as "embed"
107109 tweet_text += f"\n { get_video_short_url (video )} "
108110
109111 return tweet_text
@@ -194,11 +196,11 @@ def tweet_video_recommendation(bot_name, dest: list[str], assumeyes=False):
194196 atproto_uri = None
195197 # Tweet the video
196198 if "twitter" in dest :
197- tweet_text = prepare_tweet (video , dest = "twitter" )
199+ tweet_text = prepare_text (video , dest = "twitter" )
198200 tweet_id = twitterbot .create_tweet (text = tweet_text )
199201
200202 if "bluesky" in dest :
201- text = prepare_tweet (video , dest = "bluesky" )
203+ text = prepare_text (video , dest = "bluesky" )
202204 atproto_uri = twitterbot .create_bluesky_post (text = text , embed_video = video )
203205
204206 # Add the video to the TweetInfo table
@@ -268,7 +270,7 @@ def generate_top_contributor_figure(top_contributors_qs, language="en") -> Path:
268270 return figure_path
269271
270272
271- def tweet_top_contributor_graph (bot_name , assumeyes = False ):
273+ def tweet_top_contributor_graph (bot_name , dest : list [ str ], assumeyes = False ):
272274 """Tweet the top contibutor graph of last month.
273275
274276 Args:
@@ -297,15 +299,28 @@ def tweet_top_contributor_graph(bot_name, assumeyes=False):
297299 if confirmation not in ["y" , "yes" ]:
298300 return
299301
300- tweet_id = twitterbot .create_tweet (
301- text = settings .top_contrib_tweet_text_template [language ],
302- media_files = [top_contributor_figure ]
303- )
302+ message_url = None
303+ if "twitter" in dest :
304+ tweet_id = twitterbot .create_tweet (
305+ text = settings .top_contrib_tweet_text_template [language ],
306+ media_files = [top_contributor_figure ]
307+ )
308+ message_url = f"https://twitter.com/{ bot_name } /status/{ tweet_id } "
304309
305- # Post the tweet on Discord
306- discord_channel = settings .TWITTERBOT_DISCORD_CHANNEL
307- if discord_channel :
308- write_in_channel (
309- discord_channel ,
310- message = f"https://twitter.com/{ bot_name } /status/{ tweet_id } " ,
310+ if "bluesky" in dest :
311+ post_uri = twitterbot .create_bluesky_post (
312+ text = settings .top_contrib_tweet_text_template [language ],
313+ image_files = [top_contributor_figure ],
314+ image_alts = [settings .top_contrib_tweet_image_alt [language ]]
311315 )
316+ post_id = post_uri .rsplit ("/" , 1 )[- 1 ]
317+ message_url = f'https://bsky.app/profile/{ twitterbot .bluesky_handle } /post/{ post_id } '
318+
319+ if message_url is not None :
320+ # Post the tweet on Discord
321+ discord_channel = settings .TWITTERBOT_DISCORD_CHANNEL
322+ if discord_channel :
323+ write_in_channel (
324+ discord_channel ,
325+ message = message_url ,
326+ )
0 commit comments