An upgraded Telegram bot for community news submission with a full moderation pipeline, security layer, photo support, scheduled publishing, and inline editing. A complete rewrite of the original predlozhkatg bot.
| Feature | v1 (predlozhkatg) | v2 (newbot) |
|---|---|---|
| Security layer | Manual checks | SecurityManager class |
| Rate limiting | None | 60s cooldown per user |
| Flood detection | None | ✅ Auto-block on >5 messages / 10s |
| Content filtering | None | ✅ Regex blacklist + pattern detection |
| User blocking | None | ✅ Persistent blocked users set |
| Token validation | Existence check only | ✅ Regex format validation |
| Photo support | ❌ | ✅ Optional photo attachment |
| Scheduled publishing | ❌ | ✅ 1h / 3h / custom delay |
| Inline editing | ❌ | ✅ Moderator can edit before publish |
| Spam marking | ❌ | ✅ Dedicated SPAM button |
| Conversation steps | 2 (title → text) | 3 (title → text → photo) |
| Logging | Console only | ✅ File + console with timestamps |
| Config via env | Partial | ✅ Fully configurable via .env |
Each submission arrives in the moderation group with a full inline keyboard:
[ Опубликовать ] [ Отклонить ]
[ Редактировать ] [ СПАМ ]
[ 1ч ] [ 3ч ] [ Свое время ]
- Publish — posts immediately to the channel, notifies author
- Reject — notifies author with rejection message
- Edit — moderator edits the post inline before publishing
- SPAM — marks as spam, blocks the submitting user
- Delay — schedules publication at 1h / 3h / custom time
Incoming user message
│
├─ is_user_blocked() → hard block, no processing
├─ check_flood() → >5 msgs in 10s → auto-block
├─ check_rate_limit() → 60s cooldown between submissions
├─ check_content()
│ ├─ regex blacklist (BLACKLISTED_WORDS from env)
│ ├─ repeated character pattern (spam detection)
│ ├─ max length (MAX_NEWS_LENGTH)
│ └─ max URLs per post (MAX_URLS)
│
└─ Passed → enter ConversationHandler
- 3-step submission flow — title → body text → optional photo
- Photo support — attach image to news post, or skip
- Configurable limits — all thresholds via
.env, no hardcoding - Structured logging —
bot.logfile + console, with timestamps and levels - Admin whitelist —
ADMIN_USER_IDSset from environment - Stale submission guard — processed submissions removed from memory, replay-safe
python-telegram-bot20.x (fully async)python-dotenv- Standard library:
re,asyncio,datetime,typing
pip install -r requirements.txt
cp .env.example .env # fill in values
python bot.pyBOT_TOKEN= # Telegram bot token (validated on startup)
MODERATION_GROUP_ID= # Group ID for moderation queue
CHANNEL_ID= # Target channel ID for published posts
ADMIN_USER_IDS= # Comma-separated admin Telegram IDs
MAX_NEWS_LENGTH=4000 # Max body text length
MAX_TITLE_LENGTH=200 # Max title length
MAX_URLS=3 # Max URLs allowed per submission
BLACKLISTED_WORDS= # Comma-separated banned word patterns (regex)newbot/
├── bot.py ← full bot logic + SecurityManager class
├── requirements.txt
├── .env.example
└── .gitignore ← .env excluded from version control