A zero-boilerplate simple telegram bots
Project description
TgBotZero
Телеграм-боты в пару строчек кода. Простые телеграм-боты должно быть очень просто делать!
Примеры
Бот, показывающий твоё сообщение:
import tgbotzero
TOKEN = '123123123:tokenFromBotFatherInTelegram'
def on_message(msg: str):
return "Твоё сообщение: " + msg
Бот с кнопками:
from tgbotzero import *
TOKEN = '123:tokenHereFromBotFatherInTelegram'
def on_message(msg: str):
return [
"Твоё сообщение: " + msg,
Button('Кнопка', 'btn'),
]
def on_button_btn(data):
return 'Нажата кнопка. Отправьте любое сообщение для продолжения'
run_bot()
Бот с командами:
from tgbotzero import *
TOKEN = '123:tokenHereFromBotFatherInTelegram'
def on_message(msg: str):
return '''Доступны команды:
/show — показать
/plus — прибавить 1
/minus — вычесть 1'''
counter = 0
def on_command_show(cmd: str):
"""Показать значение"""
return f'{counter=}'
def on_command_plus(cmd: str):
"""Прибавить 1"""
global counter
counter += 1
return f'{counter=}'
def on_command_minus(cmd: str):
"""Вычесть 1"""
global counter
counter -= 1
return f'{counter=}'
run_bot()
Бот с картинками:
from tgbotzero import *
TOKEN = '123:tokenHereFromBotFatherInTelegram'
def on_message(msg: str):
return [
f"Мяу-гав!",
Image('cat.png'),
Image('dog.png'),
Button('Класс!', 'btn')
]
def on_button_btn(data):
return 'Ага!'
run_bot()
Обработка и модификация картинок:
from tgbotzero import *
TOKEN = '123:tokenHereFromBotFatherInTelegram'
def on_message(msg: str):
return 'Жду картинку с подписью!'
def on_image(msg: str, img: Image):
return img.put_text(msg, (255, 0, 0))
run_bot()
Установка
Введите в терминале:
pip install tgbotzero --upgrade --user
Или запустите эту программу:
import os, sys
python = sys.executable
user = '--user' if 'venv' not in python and 'envs' not in python else ''
cmd = f'"{python}" -m pip install tgbotzero --upgrade {user}'
os.system(cmd)
Contributing
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tgbotzero-0.0.5.tar.gz
(4.6 MB
view hashes)
Built Distribution
Close
Hashes for tgbotzero-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f40ad32b0d74c78cbc90f166fdb87deaa3b82083ea82b89cd53059afc71b3a1 |
|
MD5 | 393a8dc33125e27d32455683fabad949 |
|
BLAKE2b-256 | a88d27eaefeb94c3d040883af729f8873d4ffd1226313960f4ac9cf70a7951e4 |