Telegram bot canggih untuk scraping data dari DarkForums (https://darkforums.st/) menggunakan Playwright dengan implementasi yang aman dan scalable.
- Playwright Integration: Scraping dinamis dengan browser automation
- Anti-Detection: Stealth mode, rotating user agents, random delays
- Error Handling: Robust retry logic dan error recovery
- Screenshot Support: Capture bukti visual dari scraping
- Rich Commands: 10+ commands dengan inline keyboards
- Real-time Updates: Live data dari forum
- User Management: Authentication dan authorization
- Rate Limiting: Intelligent throttling untuk mencegah spam
- Data Encryption: Sensitive data protection
- User Authentication: Whitelist-based access control
- Proxy Support: Anonymous scraping capabilities
- Secure Logging: No sensitive data in logs
- SQLite/PostgreSQL: Flexible database options
- Intelligent Caching: Redis-compatible caching system
- Data Persistence: Reliable data storage
- Cleanup Automation: Automatic old data removal
- Prometheus Metrics: Comprehensive monitoring
- Grafana Dashboards: Beautiful visualizations
- Health Checks: System status monitoring
- Performance Tracking: Response times dan usage statistics
- Python 3.11+
- Docker & Docker Compose (optional)
- Telegram Bot Token
- DarkForums Account
# Clone repository
git clone <repository-url>
cd telegram-darkforums-bot
# Run automatic setup (Windows)
run.bat install
run.bat setup
# Or manual setup (Linux/Mac)
python run.py --setup# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
playwright install chromium
# Setup environment
cp .env.example .env
# Edit .env with your credentialsEdit .env file dengan credentials Anda:
# Telegram Bot
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_ADMIN_ID=your_admin_user_id
# DarkForums
DARKFORUMS_USERNAME=your_username
DARKFORUMS_PASSWORD=your_password
# Optional: Advanced settings
HEADLESS_MODE=true
RATE_LIMIT_REQUESTS=10
LOG_LEVEL=INFO# Windows
run.bat dev
# Linux/Mac
python run.py --dev# Windows
run.bat prod
# Linux/Mac
python run.py --prod# Build and run
docker-compose up -d
# View logs
docker-compose logs -f telegram-bot
# Stop
docker-compose down| Command | Description | Example |
|---|---|---|
/start |
Initialize bot dan show welcome message | /start |
/help |
Show available commands dan usage | /help |
/search <keyword> |
Search posts by keyword | /search python |
/latest [count] |
Get latest posts (default: 10) | /latest 5 |
/user <username> |
Get user profile information | /user john_doe |
/stats |
Show forum statistics | /stats |
| Command | Description | Example |
|---|---|---|
/history [count] |
Show your search history | /history 5 |
/clear |
Clear your search history | /clear |
| Command | Description | Example |
|---|---|---|
/status |
Show bot system status | /status |
/broadcast <message> |
Send message to all users | /broadcast Hello! |
/ban <user_id> |
Ban user from using bot | /ban 123456789 |
/unban <user_id> |
Unban user | /unban 123456789 |
/logs [lines] |
Show recent log entries | /logs 50 |
π telegram-darkforums-bot/
βββ π src/
β βββ π bot/ # Telegram bot logic
β βββ π scraper/ # Web scraping components
β βββ π database/ # Database models & operations
β βββ π utils/ # Utilities & helpers
β βββ π main.py # Application entry point
βββ π tests/ # Test suites
βββ π monitoring/ # Prometheus & Grafana configs
βββ π docker/ # Docker configurations
βββ π requirements.txt # Python dependencies
βββ π docker-compose.yml # Docker orchestration
βββ π run.py # Development runner
- Application: Main bot orchestration
- Handlers: Command dan message processing
- Middleware: Authentication, rate limiting, security
- Commands: Command definitions dan validation
- PlaywrightManager: Browser automation
- DarkForumsScraper: Forum-specific scraping logic
- DataParser: HTML parsing dan data extraction
- Models: SQLAlchemy ORM models
- Operations: Database CRUD operations
- Config: Environment configuration
- Logger: Structured logging
- Helpers: Common utilities
- telegram-bot: Main application
- db: PostgreSQL database (optional)
- redis: Caching layer (optional)
- prometheus: Metrics collection (optional)
- grafana: Monitoring dashboards (optional)
# Production with monitoring
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Scale bot instances
docker-compose up -d --scale telegram-bot=3
# Update deployment
docker-compose pull
docker-compose up -d --force-recreate- Bot uptime dan health status
- Command usage statistics
- Scraping success/failure rates
- Response times dan performance
- Memory dan CPU usage
- Database operations
- Rate limiting events
- Error rates dan types
- Grafana: http://localhost:3000 (admin/admin123)
- Prometheus: http://localhost:9090
# Run all tests
run.bat test
# or
python run.py --test
# Run specific test file
pytest tests/test_bot.py -v
# Run with coverage
pytest --cov=src --cov-report=html- Unit tests for all components
- Integration tests for bot commands
- Scraper functionality tests
- Database operations tests
- Mock external dependencies
# Install development dependencies
pip install -r requirements-dev.txt
# Install pre-commit hooks
pre-commit install
# Run code formatting
black src/ tests/
flake8 src/ tests/
mypy src/- Black: Code formatting
- Flake8: Linting
- MyPy: Type checking
- isort: Import sorting
- Fork repository
- Create feature branch
- Make changes dengan tests
- Run quality checks
- Submit pull request
- β No hardcoded credentials
- β Environment variable configuration
- β Input validation dan sanitization
- β Rate limiting dan throttling
- β User authentication
- β Secure logging (no sensitive data)
- β Docker security best practices
- β Proxy support for anonymity
- Anti-Detection: Stealth browsing techniques
- Rate Limiting: Prevent abuse dan detection
- Data Encryption: Protect sensitive information
- Access Control: Whitelist-based user management
- Audit Logging: Track all activities
TELEGRAM_BOT_TOKEN= # Your Telegram bot token
TELEGRAM_ADMIN_ID= # Your Telegram user ID
DARKFORUMS_USERNAME= # DarkForums username
DARKFORUMS_PASSWORD= # DarkForums password# Playwright Settings
HEADLESS_MODE=true # Run browser in headless mode
BROWSER_TYPE=chromium # Browser type (chromium/firefox/webkit)
PAGE_TIMEOUT=30000 # Page load timeout (ms)
# Rate Limiting
RATE_LIMIT_REQUESTS=10 # Max requests per window
RATE_LIMIT_WINDOW=60 # Rate limit window (seconds)
# Database
DATABASE_URL=sqlite:///data/bot.db # Database connection string
# Logging
LOG_LEVEL=INFO # Logging level
LOG_FILE=logs/bot.log # Log file path
# Caching
CACHE_TTL=3600 # Cache TTL (seconds)
CACHE_MAX_SIZE=1000 # Max cache entries
# Proxy (Optional)
PROXY_SERVER= # Proxy server URL
PROXY_USERNAME= # Proxy username
PROXY_PASSWORD= # Proxy password# Check logs
run.bat logs
# or
docker-compose logs telegram-bot
# Verify configuration
run.bat status- Check DarkForums credentials
- Verify internet connection
- Check if site is accessible
- Review rate limiting settings
# Reset database
rm data/bot.db
run.bat setup
# Check database status
sqlite3 data/bot.db ".tables"# Rebuild containers
docker-compose down
docker-compose build --no-cache
docker-compose up -d
# Check container logs
docker-compose logs -f- Adjust
CACHE_MAX_SIZE - Enable database cleanup
- Monitor container resources
- Adjust
PAGE_TIMEOUT - Use headless mode
- Optimize selectors
MIT License - see LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki
- Playwright - Web automation framework
- python-telegram-bot - Telegram Bot API wrapper
- SQLAlchemy - Database ORM
- Docker - Containerization platform
π Privacy: This bot does not store personal data beyond what's necessary for functionality. All data is encrypted dan handled securely.