Fix duplicate-post and timeout bugs in TG/MAX posting pipeline

- Stop blindly retrying send_photo/send_video/send_media_group and MAX
  send_message on ambiguous network timeouts - a timeout doesn't prove
  the message wasn't delivered, and retrying risked posting duplicates
  (observed live: a video posted 3-5x after repeated timeout retries).
- Raise/rework timeouts that were too short for real large-file transfer
  speeds: TG media upload timeout, and yt-dlp download now uses stall
  detection (killed only on true silence) instead of a flat ceiling that
  was cutting off legitimately slow-but-successful video downloads.
- Fix sendRichMessage: ok=true with an unparseable message_id no longer
  triggers a fallback send (Telegram already created the message).
- MAX: videos over the documented 250MB cap are now sent as a "watch via
  link" note instead of silently failing the upload.
- Add PRAGMA busy_timeout to all DB connections.
- Remove unused MAX_MEDIA_CHANNEL_ID (MAX's /uploads returns a portable
  token directly, no staging channel needed, unlike Telegram).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-15 12:17:47 +05:00
parent be01558ddb
commit ec65aaf57d
9 changed files with 276 additions and 108 deletions
+23
View File
@@ -176,6 +176,29 @@ def build_media_unavailable_note(link_only_items: list, parse_mode: str = "html"
return header + "\n" + "\n".join(lines)
def build_oversized_video_note(items: list, parse_mode: str = "html") -> str:
"""Like build_media_unavailable_note, but for videos that were deliberately
skipped for exceeding a platform's size limit (e.g. MAX's 250MB video cap) -
friendlier tone since this isn't a failure, just a known platform limit."""
if not items:
return ""
lines = []
for item in items:
url = str(getattr(item, "original_url", "") or "").strip()
if not url:
continue
if parse_mode == "html":
lines.append(f'- <a href="{html.escape(url, quote=True)}">видео по ссылке</a>')
else:
lines.append(f"- видео по ссылке: {url}")
if not lines:
return ""
header = "Видео слишком большое для платформы, посмотреть можно здесь:"
if parse_mode == "html":
header = f"<i>{html.escape(header)}</i>"
return header + "\n" + "\n".join(lines)
def format_post_text(
raw_text: str,
*,