Commit Graph

14 Commits

Author SHA1 Message Date
exostring 3a086d9e54 Add stale-donor alerting with per-route recipients and delivery fallback
New STALE_DONOR_ALERT_DAYS (.env, global threshold, 0=off) + per-route
stale_alert_enabled/stale_alert_ids (routes.json). Checked once per route
per cycle against MAX(posted_at) in the DB - self-resetting via a single
route_alerts.stale_alert_sent_at timestamp compared against the last post
time, so it fires once per quiet spell and re-arms automatically once the
donor posts again, no separate ack/clear step needed.

If a configured stale_alert_ids recipient can't be reached (never started
a chat with the bot), the global TG_ADMIN_IDS get a separate notice about
that delivery failure instead of the alert silently vanishing.
2026-08-18 19:13:01 +05:00
exostring ab69fff33b Fix admin report HTML-injection crash, add /id bot command
Error text and VK group names were inserted into admin Telegram reports
unescaped under parse_mode=HTML - any '<'/'>'/'&' in an exception message
(common) made Telegram reject the whole message with "can't parse
entities", silently swallowed as a warning log. Admins got nothing.
Escape everything user/exception-controlled before embedding.

Also adds a minimal /id command (long-polling, shares the existing bot
session) so people can DM the bot and get their Telegram ID in a
copy-paste-ready format, for configuring per-route notification recipients.
2026-08-18 18:53:44 +05:00
exostring 2b0481b6a1 Fix chat_kwargs() missing chat_id arg in multi-media send paths
Two call sites in send_media_post() (the >1-media-item send_media_group
branches) were missed when chat_kwargs() was parameterized for multi-route
support - broke TG posting for any post with more than one photo/video.
2026-08-18 18:23:42 +05:00
exostring 20135263c4 Add multi-route donor->recipient support, fix VK hashtag truncation
Posts can now be sourced from multiple VK groups, each routed to its own
Telegram/MAX destination(s) with independent on/off switches, configured
via data/routes.json (supports // line comments). Falls back to a single
route auto-generated from the legacy VK_SOURCE/TG_CHAT_ID/MAX_CHAT_ID env
vars if routes.json doesn't exist yet, so existing deployments keep working.

Routes are processed strictly sequentially within a cycle (no concurrency)
to keep flood control on VK/TG/MAX correct, since bot tokens are shared
across routes. DB schema gains route_id in the posts uniqueness key so the
same VK donor can safely feed multiple routes without status collisions.

Also removes the trailing-hashtag-stripping logic in text_formatter, which
was silently deleting VK posts' own hashtags whenever COMMON_TAGS wasn't
configured (it always wasn't) - posts are now forwarded unchanged.
2026-08-18 14:48:22 +05:00
exostring ec65aaf57d 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>
2026-08-15 12:17:47 +05:00
exostring be01558ddb Remove non-functional MAX auto-reaction, add real TG auto-reaction
MAX Bot API has no reaction endpoint (confirmed 404 in production logs),
so drop the dead code path entirely instead of eating a warning every post.

Telegram's setMessageReaction is a real Bot API method (verified against
aiogram 3.21.0, the pinned version) - wire it up as a non-fatal
best-effort call after a successful send, mirroring the same
try/except-and-log pattern MAX already used.
2026-08-14 22:14:31 +05:00
exostring 6a7a995d5f Fix duplicate posting, HTML escaping, restore sendRichMessage correctly
- Stop re-sending to a platform that already succeeded when the other
  platform failed (was causing duplicate posts on partial failure)
- Escape VK post text before sending with parse_mode=HTML instead of
  only escaping matched bracket-link substrings (bare & < > broke sends)
- Restore Telegram sendRichMessage (Bot API 10.1) ported faithfully from
  new_vk_parser's proven implementation, with fallback to standard
  send_photo/send_video/send_media_group
- Restore "media unavailable" note when a video/photo fails to download
  instead of silently dropping it
- Handle YouTube link attachments from VK posts (route into yt-dlp)
- MAX: chunk media beyond 10 items into follow-up messages instead of
  dropping them
- yt-dlp format selector no longer falls back to unconstrained height
- Wire up VK_RATE_LIMIT_RPS, drop unused Pillow dep and dead config fields
2026-08-14 21:21:57 +05:00
exostring d63d3fb937 docs: add full infrastructure, deploy, commands and architecture guide to README.md and .infra.md 2026-08-14 20:02:41 +05:00
exostring bcdb352cca Fix yt-dlp file creation and clean video pipeline 2026-08-14 19:59:33 +05:00
exostring 144dd3cb52 Support full 2GB/2h video downloads via Local Bot API, clean VK wiki links and remove fallback links 2026-08-14 19:46:16 +05:00
exostring 3ded8d3edd Ensure loguru logger import in all modules 2026-08-14 19:27:57 +05:00
exostring a1988f9d89 Restore logger import in main.py 2026-08-14 19:27:04 +05:00
exostring de8501045f Fix import resolution for direct execution 2026-08-14 19:21:52 +05:00
exostring 41722c0ffc Initial commit for RedAirsoft VK to TG and MAX poster 2026-08-14 19:10:27 +05:00