Skip to main content

A zero-boilerplate simple telegram bots

Project description

PyPI PyPI - Python Version GitHub

TgBotZero

Телеграм-боты в пару строчек кода. Простые телеграм-боты должно быть очень просто делать!

Примеры

Бот, показывающий твоё сообщение:

import tgbotzero

TOKEN = '123123123:tokenFromBotFatherInTelegram'

def on_message(msg: str):
    return "Твоё сообщение: " + msg
echobot

Бот с кнопками:

from tgbotzero import *

TOKEN = '123:tokenHereFromBotFatherInTelegram'

def on_message(msg: str):
    return [
        "Твоё сообщение: " + msg,
        Button('Кнопка', 'btn'),
    ]

def on_button_btn(data):
    return 'Нажата кнопка. Отправьте любое сообщение для продолжения'

run_bot()
echobot

Бот с командами:

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()
commands

Бот с картинками:

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()
gallery

Обработка и модификация картинок:

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()
puttext

Установка

Введите в терминале:

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)

Uploaded Source

Built Distribution

tgbotzero-0.0.5-py3-none-any.whl (3.4 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page