|
1 | 1 | # Python Italy Telegram Bot |
2 | 2 |
|
3 | | -Fresh rewrite — start here. |
| 3 | +Official Telegram bot for the main Italian Python group and local sub-groups in Italy. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Welcome captcha**: New members must read a rules file and send a secret command to the bot in private chat before they can post in the group |
| 8 | +- **Spam detection**: Rate limiting and duplicate message detection with automatic deletion |
| 9 | +- **Moderation**: Ban, mute, and report commands (admin-only for ban/mute) |
| 10 | +- **Database abstraction**: In-memory storage by default; persistent database can be added later |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +- Python 3.14+ |
| 15 | +- [UV](https://docs.astral.sh/uv/) package manager |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +1. Install UV if needed: |
| 20 | + ```bash |
| 21 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Install dependencies: |
| 25 | + ```bash |
| 26 | + uv sync |
| 27 | + ``` |
| 28 | + |
| 29 | +3. Copy the environment template and configure: |
| 30 | + ```bash |
| 31 | + cp .env.example .env |
| 32 | + # Edit .env and set TELEGRAM_BOT_TOKEN |
| 33 | + ``` |
| 34 | + |
| 35 | +4. Run the bot: |
| 36 | + ```bash |
| 37 | + uv run python-italy-bot |
| 38 | + # or: uv run python -m python_italy_bot.main |
| 39 | + ``` |
| 40 | + |
| 41 | +## Configuration |
| 42 | + |
| 43 | +| Variable | Required | Description | |
| 44 | +|----------|----------|-------------| |
| 45 | +| `TELEGRAM_BOT_TOKEN` | Yes | Bot token from [@BotFather](https://t.me/BotFather) | |
| 46 | +| `DATABASE_URL` | No | Database URL (placeholder for future use) | |
| 47 | +| `CAPTCHA_SECRET_COMMAND` | No | Secret command for captcha (default: `python-italy`) | |
| 48 | +| `CAPTCHA_FILE_PATH` | No | Path to rules file (default: `assets/regolamento.md`) | |
| 49 | +| `MAIN_GROUP_ID` | No | Main group ID for multi-group logic | |
| 50 | +| `LOCAL_GROUP_IDS` | No | Comma-separated sub-group IDs | |
| 51 | + |
| 52 | +## Commands |
| 53 | + |
| 54 | +- `/ban` – Ban a user (admin only). Usage: `/ban @username`, `/ban user_id [reason]`, or reply to message with `/ban [reason]` |
| 55 | +- `/unban` – Unban a user (admin only) |
| 56 | +- `/mute` – Mute a user (admin only). Usage: `/mute @username [minutes] [reason]` |
| 57 | +- `/unmute` – Unmute a user (admin only) |
| 58 | +- `/report` – Report a message. Reply to the message with `/report [reason]` |
| 59 | + |
| 60 | +## Architecture |
| 61 | + |
| 62 | +``` |
| 63 | +src/python_italy_bot/ |
| 64 | +├── main.py # Entry point, Application setup |
| 65 | +├── config.py # Pydantic settings from env |
| 66 | +├── handlers/ # Telegram update handlers |
| 67 | +│ ├── welcome.py # New member + captcha flow |
| 68 | +│ ├── moderation.py # Ban, mute, report commands |
| 69 | +│ └── spam.py # Spam detection |
| 70 | +├── services/ # Business logic |
| 71 | +│ ├── captcha.py # Captcha verification |
| 72 | +│ ├── spam_detector.py |
| 73 | +│ └── moderation.py |
| 74 | +├── db/ # Persistence abstraction |
| 75 | +│ ├── base.py # Repository interface |
| 76 | +│ ├── models.py # Domain models |
| 77 | +│ └── in_memory.py # In-memory implementation |
| 78 | +└── assets/ # Captcha/rules file |
| 79 | +``` |
| 80 | + |
| 81 | +## Captcha Flow |
| 82 | + |
| 83 | +1. User joins group → Bot restricts them (read-only) |
| 84 | +2. Bot sends welcome message with instructions |
| 85 | +3. User reads the rules file and finds the secret command |
| 86 | +4. User sends the secret command to the bot in private chat |
| 87 | +5. Bot verifies and removes restrictions in the group |
| 88 | + |
| 89 | +## License |
| 90 | + |
| 91 | +MIT |
0 commit comments