feat(v2): complete mattata v2.0 modernization
Full rewrite of the mattata Telegram bot for v2.0 with PostgreSQL,
Redis, connection pooling, middleware pipeline, and comprehensive
test coverage.
Core:
- Database connection pooling with auto-reconnect and transactions
- Redis auto-reconnect with exponential backoff, SCAN replaces KEYS
- Middleware pipeline (blocklist, rate limit, federation, captcha, user tracker, language, stats)
- Lazy admin check in router (API call only when needed)
- Session caching helpers (get_cached_setting, get_cached_list)
- Stats middleware with Redis counters and 5-min PostgreSQL flush
Migrations:
- 001: Initial schema (users, chats, chat_members, chat_settings, warnings, filters, triggers, disabled_plugins, admin_actions)
- 002: Federation tables (corrected schema: id/owner_id/federation_id)
- 003: Statistics tables (message_stats, command_stats)
- 004: Performance indexes (9 indexes for hot query paths)
Plugins (144 source files):
- Admin: ban, kick, mute, warn, tempban, tempmute, promote, demote, purge, pin, antilink, wordfilter, filter, triggers, captcha, etc.
- Federation: newfed, delfed, joinfed, leavefed, fban, unfban, fbaninfo, fpromote, fdemote, fadmins, fallowlist, myfeds, feds
- Utility: help, ping, stats, commandstats, afk, remind, weather, translate, currency, search, wikipedia, and more
- Fun: slap, flip, dice, mock, aesthetic, quote, copypasta, etc.
- Media: cats, gif, youtube, spotify, itunes, sticker
- AI: OpenAI/Anthropic integration with conversation history
Security:
- All admin plugins check bot permissions before acting
- Parameterized queries in migration runner (no SQL injection)
- User tracker debouncing (~95% DB write reduction)
- Rate limiting with automatic blocklist at threshold
Tests (27 files, ~270 test cases):
- Mock helpers for Telegram API, PostgreSQL, and Redis
- Core module tests (config, database, redis, session, permissions, router, middleware, loader, i18n, logger)
- Middleware tests (blocklist, rate_limit, user_tracker, language, federation, captcha, stats)
- Plugin tests (ban, federation, help, ping, flip)
- Migration SQL validation tests