Implement Pravda: Truth Social to Discord relay service
Some checks failed
Build and Push Docker Image / build (push) Failing after 1m59s

- Add core modules: database (SQLite), media (ffmpeg), discord (webhook), poller (truthbrush), server (FastAPI)
- Support video transcoding to H.264/AAC with automatic size management
- Handle message splitting for Discord limits (2000 chars, 10 attachments)
- Include interactive buttons (Delete, View Raw, Original Post)
- Add Dockerfile with ffmpeg and entrypoint script
- Add Gitea Actions workflow for CI/CD
- Configure code style tools (black, ruff, mypy)
- Include basic unit tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 01:01:59 -05:00
parent af530372f3
commit c75856ff44
17 changed files with 1491 additions and 0 deletions

144
README.md Normal file
View File

@@ -0,0 +1,144 @@
# Pravda
A Python-based Dockerized service that monitors Truth Social feeds and relays posts to Discord via webhooks. Features intelligent media handling (transcoding/splitting) and interactive message components.
## Features
- Monitors Truth Social feeds using the `truthbrush` library
- Relays posts to Discord with full media support
- Automatic video transcoding to H.264/AAC for Discord compatibility
- Smart file size management (keeps videos under 50MB)
- Message splitting for long posts (Discord's 2000 char limit)
- Interactive buttons for deleting messages and viewing raw post data
- SQLite database for tracking processed posts
- FastAPI server for handling Discord interaction webhooks
## Requirements
- Python 3.12+
- Docker (for containerized deployment)
- ffmpeg (for video transcoding)
- A Discord webhook URL
- A Discord application (for interaction components)
## Environment Variables
| Variable | Description | Required |
|----------|-------------|----------|
| `DISCORD_WEBHOOK` | Discord Webhook URL for posting messages | Yes |
| `DISCORD_APPLICATION_ID` | Discord Application ID for components | Yes |
| `DISCORD_PUBLIC_KEY` | Public Key for verifying interaction signatures | Yes (if using interactions) |
| `POLL_INTERVAL` | Seconds between checks (default: 300) | No |
| `TRUTH_USER` | Target username (default: realDonaldTrump) | No |
| `DB_PATH` | Path to SQLite DB (default: /data/seen.db) | No |
## Quick Start
### Local Development
```bash
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export DISCORD_WEBHOOK="your_webhook_url"
export DISCORD_APPLICATION_ID="your_app_id"
export DISCORD_PUBLIC_KEY="your_public_key"
# Run locally
python main.py
```
### Docker
```bash
# Build image
docker build -t pravda .
# Run in daemon mode (Poller + Server)
docker run -d \
-e DISCORD_WEBHOOK="your_webhook_url" \
-e DISCORD_APPLICATION_ID="your_app_id" \
-e DISCORD_PUBLIC_KEY="your_public_key" \
-v $(pwd)/data:/data \
-p 8080:8080 \
pravda
# One-off mode: relay a specific post
docker run --rm \
-e DISCORD_WEBHOOK="your_webhook_url" \
pravda https://truthsocial.com/@realDonaldTrump/posts/123456789
```
## Architecture
The application runs two concurrent processes:
1. **The Poller**: Loops infinitely, checking for new posts. Processed posts are cached in SQLite to prevent duplicates.
2. **The Server**: A FastAPI instance listening on port 8080 to handle Discord interaction webhooks (button clicks).
### Interaction Endpoints
- `POST /interactions` - Discord interaction webhook handler
- `GET /health` - Health check endpoint
## Discord Components
Messages include interactive buttons:
- **Delete**: Removes the message (requires MANAGE_MESSAGES permission)
- **View Raw**: Shows the raw post JSON (ephemeral)
- **Original Post**: Links to the original Truth Social post
## Media Handling
- **Images**: Downloaded and attached directly
- **Videos**: Transcoded to H.264/AAC MP4 format
- Automatically scaled down if over 50MB
- Resolution reduced progressively (720p, then 480p) if needed
## Development
```bash
# Install dev dependencies
pip install -r requirements.txt
pip install black ruff mypy pytest
# Format code
black .
# Lint
ruff check .
# Type check
mypy .
# Run tests
pytest
```
## Project Structure
```
pravda/
├── main.py # Application entrypoint
├── src/
│ ├── __init__.py
│ ├── database.py # SQLite operations
│ ├── discord.py # Discord webhook handling
│ ├── media.py # Media processing (ffmpeg)
│ ├── poller.py # Truth Social polling
│ └── server.py # FastAPI interaction handler
├── Dockerfile
├── entrypoint.sh
├── requirements.txt
├── pyproject.toml
└── .gitea/
└── workflows/
└── build-push.yaml
```
## License
MIT