Skip to main content

Working with VK by this homogenetic way and it's awesome!

Project description

VKBottle - high quality VK Tool

downloads service-test status

VKBottle - это многофункциональный модуль для работы с VK Api и создания ботов. Проект все еще тестируется на различных нагрузках


Установка

  1. С помощью установщика pip из PyPi:

    Новейшая версия:

    pip install vkbottle
    

    Последний стабильный релиз:

    pip install vkbottle==2.7.1
    
  2. С помощью установщика pip из GitHub:

    pip install https://github.com/timoniq/vkbottle/archive/master.zip --upgrade
    

Кастомизация

После установки vkbottle рекомендуется сразу же установить дополнительные модули uvloop и loguru, без них фреймворк работает медленне и логи не настраиваемы. О возможностях этих модулей можно прочитать в их документации

downloads downloads

Установите uvloop и loguru с помощью команд:

pip install loguru
pip install uvloop

Кроме того вы можете установить любую библиотеку для ускорения json из предложенных: ujson, hyperjson, orjson

Фишки

  • Удобная и быстрая доставка сообщений через regex
  • Быстрый API враппер
  • Быстрый LongPoll фреймворк для ботов
  • Маленький объем кода со стороны пользователя
  • Полностью асинхронно
  • Ветки стейтов - Branches
  • Блокирующая обработка - Middlewares
  • Правила - Rules
  • User LongPoll API

Longpoll

from vkbottle import Bot, Message

bot = Bot("my-token")


@bot.on.message(text="My name is <name>", lower=True)
async def wrapper(ans: Message, name):
    await ans("Hello, {}".format(name))


bot.run_polling(skip_updates=False)

Callback

from vkbottle import Bot, Message
from aiohttp import web

bot = Bot(token="my-token", secret="my-secret")
app = web.Application()


async def executor(request: web.Request):
    event = await request.json()
    emulation = await bot.emulate(event=event, confirmation_token="ConfirmationToken")
    return web.Response(text=emulation)


@bot.on.message(text="test", lower=True)
async def wrapper(ans: Message):
    return "Tested!"


app.router.add_route(
        path='/',
        method='POST',
        handler=executor
    )
web.run_app(app=app, host=host, port=port)

Rules

from vkbottle import Bot, Message
from vkbottle.rule import AttachmentRule

bot = Bot("my-token")

@bot.on.message(AttachmentRule("photo"))
async def wrapper():
    return "What a beautiful photo!"
    
bot.run_polling()

User LongPoll

from vkbottle.user import User, types
from vkbottle.rule import VBMLUserRule

user = User("user-token", 123)

@user.on.message_new(VBMLUserRule("can i ask you about <theme>?",))
async def wrapper(ans: types.Message, theme):
    if theme in ["examples", "how to do smt", "depression", "insomnia"]:
        await ans("You can ask me about it in telegram @timoniq or make an issue on github!")
    else:
        await ans("Ok, sooner or later i ll respond you")

user.run_polling()

Больше примеров в папке /examples

Документация

Полная документация:

Based on

aiohttp - longpoll и запросы к API
pydantic - все датаклассы
vbml - встроенная поддержка лучшего парсера сообщений

Для оптимальной работы фреймворка, рекомендуется использовать только асинхронные библиотеки

Contributing

ПР поддерживаются! Мне приятно видеть ваш вклад в развитие библиотеки
Задавайте вопросы в блоке Issues и в чате VK!

Лицензия

Copyright © 2019-2020 timoniq.
Этот проект имеет GPL-3.0 лицензию.

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

vkbottle-2.7.1.tar.gz (124.3 kB view details)

Uploaded Source

File details

Details for the file vkbottle-2.7.1.tar.gz.

File metadata

  • Download URL: vkbottle-2.7.1.tar.gz
  • Upload date:
  • Size: 124.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for vkbottle-2.7.1.tar.gz
Algorithm Hash digest
SHA256 0d6a89ae2fcb45cdf76755d26e12b3a70b1950fd00ff793fb90b579ffcd60551
MD5 aa6a9d6b40a42080184a65e6079395fc
BLAKE2b-256 c60e967f0d574c8dd44b0024de2b3f42c7da4994329475824818f10c3b580992

See more details on using hashes here.

Supported by

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