From 6b26e8a29742b22f02a39f98659d67816b5654cc Mon Sep 17 00:00:00 2001 From: abslimit Date: Sun, 20 Sep 2020 15:30:56 +0300 Subject: [PATCH] some chunking issues fixed --- bridge.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bridge.py b/bridge.py index 7ada5cd..676bb28 100644 --- a/bridge.py +++ b/bridge.py @@ -92,11 +92,13 @@ class BridgeBot: # Post text if tg message lenght is lt mstdn post limit post_text: str = tg_message_url + full_text[reply_start:mstdn_post_size] # Set reply_start to non zero for future chunking and make mstdn post with continuaniton note + logging.debug("full_text_size: " + str(full_text_size)) if full_text_size > mstdn_post_size: long_post_tail = "\n\n[Откройте оригинальный пост по ссылке, либо прочитайте продолжение в ответах к посту.]" mstdn_post_size = mstdn_post_size - len(long_post_tail) reply_start = full_text.rfind(' ', reply_start, mstdn_post_size) post_text: str = tg_message_url + full_text[0:reply_start] + long_post_tail + logging.debug("start reply_start: " + str(reply_start)) temp_file_path: str = "" # Downloading media if tg post contains it if (event.message.photo or event.message.video or event.message.gif) and not hasattr(event.message.media, "webpage"): @@ -118,20 +120,24 @@ class BridgeBot: else: mstdn_media_meta = None # First root mstdn post + reply_to = current_mastodon_client.status_post(post_text, media_ids=[mstdn_media_meta], visibility=current_mstdn_acc_visibility) tg_message_url = f"[Продолжение https://t.me/{channel.username}/" + str(event.message.id) + "]\n\n" # Chunking post into mstdn limit chunks and reply to root post i = 0 while reply_start + mstdn_post_limit < full_text_size: - reply_end = full_text.rfind(' ', reply_start, reply_start + mstdn_post_limit - len(tg_message_url)) + logging.debug("while reply_start:" + str(reply_start)) + reply_end = full_text.rfind(' ', reply_start, reply_start + mstdn_post_limit - (len(tg_message_url)*2)) post_text: str = tg_message_url + full_text[reply_start+1:reply_end] reply_to = current_mastodon_client.status_post(post_text, in_reply_to_id=reply_to, visibility=current_mstdn_acc_visibility) reply_start = reply_end i = i + 1 if i > 15: + logging.debug("Breaking very long reply thread") break # Final chunk to reply to root post if reply_start > 0: + logging.debug("final reply_start: " + str(reply_start)) post_text: str = tg_message_url + full_text[reply_start+1:full_text_size] reply_to = current_mastodon_client.status_post(post_text, in_reply_to_id=reply_to, visibility=current_mstdn_acc_visibility) # Delete media attach