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.
This commit is contained in:
2026-08-18 14:48:22 +05:00
parent ec65aaf57d
commit 20135263c4
11 changed files with 596 additions and 233 deletions
+1 -14
View File
@@ -34,18 +34,6 @@ def clean_dividers(lines: list[str]) -> list[str]:
return ["" if sep_pattern.match(line) else line for line in lines]
def strip_trailing_hashtags(text: str) -> str:
lines = text.rstrip().splitlines()
while lines and not lines[-1].strip():
lines.pop()
if not lines:
return ""
parts = lines[-1].split()
if parts and all(part.startswith("#") for part in parts):
lines.pop()
return "\n".join(lines).rstrip()
# Matches VK bracket markup: [club123|Name], [id123|Name], [public123|Name],
# [event123|Name] or a raw-URL bracket link [https://example.com|Title]
_VK_LINK_RE = re.compile(
@@ -213,8 +201,7 @@ def format_post_text(
footer = normalize_wrapper_text(settings.footer_text if footer is None else footer, parse_mode)
tags = normalize_wrapper_text(settings.common_tags if tags is None else tags, parse_mode)
body = strip_trailing_hashtags(raw_text)
lines = clean_dividers(body.splitlines())
lines = clean_dividers(raw_text.splitlines())
title_idx: Optional[int] = None
for idx, line in enumerate(lines):