Commit Graph
27 Commits
Author SHA1 Message Date
Mak5er d4595a7e13 feat(guest-mode): add Telegram Bot API 9.0 guest mode support and media download flow
- Add guest_message router and handler for guest mentions in chats where bot is not a member
- Support link detection from direct messages, replies, quotes, and text_link entities
- Integrate with inline media senders for supported platforms and deep-linking for audio/albums
- Add guest rate-limiting and ban enforcement in antiflood and ban middlewares
- Update chat tracker to track guest users without saving non-member group data
- Bypass private chat guard for guest messages
- Add /start settings, /start stats, and /start dl_<token> deep-link handlers
- Add comprehensive test suite in tests/test_guest_mode.py
2026-09-14 14:35:09 +03:00
Mak5er ff08a681fd feat(broadcast): add token bucket rate limiter, forum topic support, and broadcast delivery report 2026-09-08 17:16:51 +03:00
Mak5er c960fc1ae1 feat: add automatic detection and migration when groups upgrade to supergroups 2026-09-08 17:00:48 +03:00
Mak5er b4d9d000b0 feat: separate users and groups, track group membership, and improve admin stats 2026-09-08 16:11:12 +03:00
Mak5er d18a4fa93b fix: replace CancelledError with handler-skip pattern in ban middleware 2026-06-18 18:42:31 +03:00
Mak5er 62050a0f2c perf: comprehensive production audit and hardening (Phase 1-4)
43 files changed, 828 insertions, 408 deletions. Key changes:

== Phase 1 - Critical fixes ==
- Fix shared mutable state in ResilientDownloader (class-level _inflight_downloads)
- Add threading.Lock to request dedup (race condition on concurrent claims)
- Fix ban_middleware fail-closed: DB error -> fallback to 'active' instead of 'restricted'
- Fix COUNT(*) anti-pattern: 5 methods fetched entire user table into memory
- Remove 6 duplicated function definitions in user_messages.py (silent shadowing)
- Extract metadata from Cobalt responses (Instagram no longer discards descriptions)
- Add SSRF validation for COBALT_API_URL (private IP blocking, scheme enforcement)
- Docker: healthcheck, resource limits, restart: on-failure:5
- Fix migration crash-loop (try/except guardrails + dialect detection bug)

== Phase 2 - Performance hardening ==
- Exponential backoff+jitter in cobalt_client and retry_async_operation (removed 9 fixed delays)
- Add asyncio.wait_for timeouts to Instagram/Pinterest downloads
- TikTok preflight size check before download
- SQLAlchemy pool event listeners (perf metrics on checkout/overflow)
- DownloadedFile TTL cleanup (date_added index + daily cron cleanup)
- Per-request UUID request_id in ChatTrackerMiddleware for end-to-end tracing
- private_chat_guard caching (60s TTL, reduces Telegram API calls)
- Antiflood O(k) eviction instead of O(n) full scan
- TikTok: Semaphore(3)+sliding-window rate limiter instead of global asyncio.Lock

== Phase 3 - CI hardening ==
- CI: lint job (ruff + mypy), docker smoke tests migrations, --cov-fail-under=80
- Upgrade dependency-audit Python 3.12 -> 3.14
- Fix 7 '# type: ignore' decorators with ParamSpec
- Migration 000005: ix_analytics_events_user_id + ix_downloaded_files_date_added
- Race-condition tests for dedup, queue shutdown, per-user slots

== Phase 4 - Architecture ==
- .dockerignore (exclude .git, tests, __pycache__, .env from Docker image)
- Consolidate 3 FakeYoutubeDL/DummyYDL classes into conftest.py
- Extract _download_youtube_media() from 70-line closure
- BasePlatformMediaService ABC in services/platforms/__init__.py
- Remove empty profiling/ directory

Tests: 349 passed, 0 failed (4 skipped: PostgreSQL-dependent)
2026-06-16 01:01:06 +03:00
Mak5er ab6404657b fix(antiflood): scope limits per chat
Track antiflood state by user and chat for message and callback events so the same user can work in multiple chats without false positives.

Add regression and user journey tests covering cross-chat behavior and the group-to-DM recovery flow.
2026-04-10 18:46:16 +03:00
Mak5er 77c4cda0b8 Refactor logging paths and stabilize db tests 2026-04-10 00:42:21 +03:00
Mak5er c4fd448f37 fix: dedupe repeated media link requests 2026-04-09 02:08:46 +03:00
Mak5er 57012b387e perf: harden update backpressure and antiflood 2026-04-09 01:31:47 +03:00
Mak5er 1e8296dd10 fix: avoid persisting raw pending request text 2026-04-08 23:45:00 +03:00
Mak5er bb964728a7 refactor: organize services into domain subpackages 2026-04-07 01:08:39 +03:00
Mak5er 29795b9710 refactor: move runtime dependencies into app context 2026-04-07 00:24:38 +03:00
Mak5er 729bf9be73 fix: centralize supported link detection across bot flows
- add a shared supported-link detector for all currently handled platforms
- use the shared detector in private chat guard and pending private-message replay
- cover soundcloud and pinterest group-to-dm flows and refresh the review backlog
2026-04-06 23:38:26 +03:00
Mak5er 784aee9747 fix: harden inline delivery and bot runtime safeguards
- secure admin callbacks and inline token ownership checks
- stabilize private chat handoff and fail-soft user settings reads
- improve inline album previews with captions, photo file_ids, and API-safe payloads
- fix download manager dedup, resume validation, and size-limit propagation
- add regression coverage for admin, db, runtime, inline, and download flows
2026-04-06 23:07:26 +03:00
Mak5er 3964d96158 Refactor database interactions and improve URL handling
- Updated user management in `admin.py` to use `get_all_users_info` and streamline user status updates.
- Refactored TikTok URL processing in `tiktok.py` to use asynchronous HTTP requests and caching.
- Enhanced Twitter handler in `twitter.py` to support async operations and improved error handling.
- Simplified user information updates in `user.py` with a new `upsert_chat` method.
- Optimized utility functions in `utils.py` for better performance and added caching for message edits.
- Updated middleware in `chat_tracker.py` to utilize the new `upsert_chat` method for user tracking.
- Improved test coverage for TikTok and Twitter handlers, ensuring async compatibility and error handling.
2026-03-14 13:43:56 +02:00
mak5er 83b425393c feat: add adaptive download queue, retries, and session observability 2026-02-11 17:01:46 +02:00
mak5er 1bb272fe70 Implement user settings resolution for group chats, add private chat guard middleware, and enhance message handling across various platforms 2026-01-14 01:14:49 +02:00
Mak5er 55bd0bf03e Add ChatTrackerMiddleware for user and chat tracking, update analytics event handling, and improve admin functionalities 2025-11-03 11:08:55 +02:00
Mak5er 67f591207f Add user settings management and logging enhancements 2025-11-02 21:38:51 +02:00
Mak5er bf7950a737 Refactor Twitter media handling to include likes, comments, and retweets in replies 2025-07-13 02:00:08 +03:00
Mak5er 3c13ce22c6 Remove SubscriptionMiddleware and CHANNEL_USERNAME from configuration 2025-07-13 01:37:02 +03:00
Mak5er 3d3aad3a94 Refactor error handling to use logging instead of print statements and update Python SDK version in project files 2025-04-10 23:02:27 +03:00
Mak5er c583010514 Add subscription middleware to enforce channel subscription for bot usage 2025-04-10 21:05:49 +03:00
Mak5er 27af4d6ffe add ban middleware 2024-07-12 13:04:15 +03:00
Mak5er a1e6eb5c2a fix middleware bug 2024-06-21 17:45:55 +03:00
Mak5er 743a89f81b add antiflood middleware 2024-06-21 17:36:56 +03:00