Multipurpose Telegram Bot for Python group
- Send links on command (chat rules, FAQs, libraries etc.)
- Ban users and delete messages
- Remind dates
- Report Daily statistics (how many banned, deleted, sent messages)
- Search for the Zen of Python quotes (inline query)
- Help users with googling their queries
- Make faces when doubtful bloggers are mentioned
- Etc.
You can use this project as a pre-coded customizable bot. Original (and currently working example) bot Telegram username: @LutzPyBot
- Clone repository on your linux server into
lutzpybot
user's home directory. - Create virtual environment, activate virtual environment, install required packages from
requirements.txt
. - Create
.env
file inlutzbot
directory with 3 variables:LUTZPYBOT
(Bot Token),whitelist
(White usernames, comma separated),whiteids
(White IDs, comma separated) - Install
gunicorn
package additionally withpip install gunicorn
- Set webhook using Python interactive shell with
bot.set_webhook()
or manually according Telegram Bot API Documentation. - Configure nginx as a reverse proxy.
- Configure the bot as a daemon.
- Create daemon unit file in
/etc/systemd/system/lutz.service
with the content (replaceinferno
with your username):
[Unit]
Description=@Lutz Telegram Bot
After=network.target
[Service]
User=inferno
Group=inferno
WorkingDirectory=/home/inferno/lutzpybot
Environment="PATH=/home/inferno/lutzpybot/venv/bin"
ExecStart=/bin/bash -c 'source /home/inferno/lutzpybot/venv/bin/activate; gunicorn --bind unix:/tmp/lutz.sock wsgi:app' #Restart=on-failure
[Install]
WantedBy=multi-user.target
- Enable and start with
systemctl enable lutz.service
,systemctl start lutz.service
.
Bot is easily understandable reading in-code comments of the handler functions, additionally read PyTelegramBotAPI documentation for library help.
Continuous log reading on Linux:
# journalctl --unit=lutz.service -f
Bot can receive commands and behave depending on chat situation.
Standard command pack for bot father includes:
- nobot - Telebot shouldn't be your first Python project
- nogui - GUI app shouldn't be your first Python project
- nometa - Don't ask meta questions
- neprivet - Don't hello
- bdmtss - Rim shot
- quote - Random quote
- add - Add quote
- g - Google it [Request text can be any text from replied message or arguments if there's text after
\g example
] - rules - Chat rules
- faq - FAQ
- books - Pythonista's Library
- lutz - Send Lutz book