Official Telegram bot for the main Italian Python group and local sub-groups in Italy.
Electus — named after Neo's Latin epithet ("the chosen one") from The Matrix. The bot personality blends Matrix and Python themes, guiding users through verification and community moderation in Italian.
- 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
- Spam detection: Rate limiting and duplicate message detection with automatic deletion
- Moderation: Ban, mute, and report commands (admin-only for ban/mute)
- Database abstraction: In-memory storage by default; persistent database can be added later
- Python 3.14+
- UV package manager
-
Install UV if needed:
curl -LsSf https://astral.sh/uv/install.sh | sh -
Install dependencies:
uv sync
-
Copy the environment template and configure:
cp .env.example .env # Edit .env and set TELEGRAM_BOT_TOKEN -
(Optional) Set the bot name and description in @BotFather:
/setname→Electus/setdescription→Guardiano della comunità Python Italia
-
If using PostgreSQL (
DATABASE_URLset), create the schema:psql "$DATABASE_URL" -f schema.sql -
Run the bot:
uv run python-italy-bot # or: uv run python -m python_italy_bot.main
Start the bot:
uv run python-italy-botThe bot starts polling for updates. You should see:
INFO - Starting bot...
INFO - Application started
Stop with Ctrl+C.
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Yes | Bot token from @BotFather |
DATABASE_URL |
No | PostgreSQL URL (Neon or other). When set, uses PostgresRepository; otherwise in-memory. |
CAPTCHA_SECRET_COMMAND |
No | Secret command for captcha (default: python-italy) |
CAPTCHA_FILE_PATH |
No | Path to rules file (default: assets/regolamento.md) |
MAIN_GROUP_ID |
No | Main group ID for multi-group logic |
LOCAL_GROUP_IDS |
No | Comma-separated sub-group IDs |
| Command | Who | Description |
|---|---|---|
/id |
Anyone | Returns chat ID and your user ID. |
/ban |
Admin | Ban a user. |
/unban |
Admin | Unban a user. |
/mute |
Admin | Mute a user (optionally for N minutes). |
/unmute |
Admin | Unmute a user. |
/report |
Anyone | Report a message. |
@admin |
Anyone | Request admin intervention (no reply needed). |
- Ban:
/ban @username,/ban user_id [reason], or reply to a message with/ban [reason] - Unban:
/unban @username,/unban user_id, or reply to user's message - Mute:
/mute @username [minutes] [reason], or reply to message. Omit minutes for indefinite mute. - Unmute:
/unmute @username,/unmute user_id, or reply to user's message - Report: Reply to the offending message with
/report [reason] - Admin request: Type
@adminor@admin [message]to notify admins (no reply needed)
New members must send the secret command in DM to the bot. Default: python-italy (configurable via CAPTCHA_SECRET_COMMAND). Send it as plain text in a private chat with the bot.
-
Add the bot to a group: Make the bot an admin so it can restrict members and ban/mute users.
-
Test captcha:
- Join the group with a test account (not admin).
- You should be restricted (read-only).
- Open a private chat with the bot and send the secret command (e.g.
python-italy). - You should be unrestricted in the group.
-
Test moderation (as admin):
/ban @usernameor reply to a message with/ban [reason]/unban @usernameto unban/mute @username 60to mute for 60 minutes/unmute @usernameto unmute
-
Test report (as any member):
- Reply to a message with
/report spam(or any reason).
- Reply to a message with
-
Test @admin (as any member):
- Type
@adminor@admin need helpto request admin intervention (no reply needed).
- Type
src/python_italy_bot/
├── main.py # Entry point, Application setup
├── config.py # Settings from env
├── handlers/ # Telegram update handlers
│ ├── welcome.py # New member + captcha flow
│ ├── moderation.py # Ban, mute, report commands
│ └── spam.py # Spam detection
├── services/ # Business logic
│ ├── captcha.py # Captcha verification
│ ├── spam_detector.py
│ └── moderation.py
├── db/ # Persistence abstraction
│ ├── base.py # Repository interface
│ ├── models.py # Domain models
│ └── in_memory.py # In-memory implementation
└── assets/ # Captcha/rules file
- User joins group → Bot restricts them (read-only)
- Bot sends welcome message with instructions
- User reads the rules file and finds the secret command
- User sends the secret command to the bot in private chat
- Bot verifies and removes restrictions in the group
MIT