Framework to creating bots
Project description
botomorph
This framework is designed for writing bots that can use various frameworks to interact with the messenger API.
Install
pip install botomorph
GitHub: https://github.com/rezschikovivan/botomorph
Why use
The framework allows you to run bots written in it on different platforms, using different frameworks to interact with their APIs. The class-based approach to writing handlers allows you to use inheritance to extract common logic or define a family of similar bots.
Features
- Multiplatform bots
- Inheritance of handlers
- A class-based approach to writing bots
- Has type hints
- Asynchronous
Example
from botomorph import Filter, Handler, BaseMsg, Sender, Keyboard, start_bots
from botomorph.vkbottle_component import VKBottleComponent
from botomorph.aiogram_component import AiogramComponent
# If necessary, you can create your own handler class that will perform certain actions when methods are registered, such as checking for the presence of specific attributes or automatically registering methods in a registry. To do this, you need to create a class that inherits from ClsHandler and implement the before and after methods. The before method will be called before the handler class is created, and the after method will be called after the handler class is created. These methods allow you to perform any necessary actions with the handler class or its attributes. However, it is important to return the result of the parent call to avoid breaking the core's logic.
class F(ClsHandler):
def before(cls, mcs, name, bases, attrs):
print(f"A handler class is being created {name}...")
return super().before(mcs, name, bases, attrs)
def after(cls, new_cls, mcs, name, bases, attrs):
print(f"The {name} handler class has been successfully created!")
return super().after(new_cls, mcs, name, bases, attrs)
set_handlers_registrator(F())
class Echo:
@Handler(Filter().in_text("hi"))
async def cab8(cls, message:BaseMsg):
await message.answer("Вы воспользовались кнопкой!")
@Handler(Filter().in_text("Привет"))
async def cab2(cls, message:BaseMsg):
await message.send_reply_kboard(keyboard=Keyboard([ [["name1", "data1"], ["name","data2"]] ]),text="реплай клавиатура")
class VKEcho(Echo, VKBottleComponent):
TOKEN = vk_token
@Handler(Filter().text("кабинет"))
async def cab3(cls, message:BaseMsg):
await message.answer("Кфбинет №11")
# An example of a handler method that displays information about the message and its sender in the console. In this method, we retrieve the sender object of the message and check for different types of attachments (photos, documents, audio, etc.), displaying this information in the console.
# @Handler()
# async def cab2(cls, message:BaseMsg):
# user:Sender = await message.sender
# print(user.first_name)
# print("ФОТО: ", message.photo)
# print("ДОКУМЕНТ: ", message.document)
# print("АУДИО: ", message.audio)
# print("ГОЛОСОВОЕ: ", message.voice)
# print("ВИДЕО: ", message.video)
# print("ТЕКСТ: ", message.text)
# print("data: ", message.date)
class TGEcho(Echo, AiogramComponent):
TOKEN = tgram_token
@Handler(Filter().text("кабинет"))
async def cab3(cls, message:BaseMsg):
await message.answer("Кфбинет №22")
import asyncio
print("works")
asyncio.run(start_bots())
summary
Basic functionality is now available using aiogram and vkbottle. It currently lacks features such as inline_buttons and FSM, but it is ideal for writing bots that do not require complex user interaction but still support multi-platform
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file botomorph-1.0.0.tar.gz.
File metadata
- Download URL: botomorph-1.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e27e9bb8dd3a9a2b8922e4a6a5eece45599c6b9d5c1e5070e8a95deaae239959
|
|
| MD5 |
d96e346d78a82a26c789237dcd582a20
|
|
| BLAKE2b-256 |
c2bc9777d5944bd319c3932a681357214d86a408285d5c029232401b629992a7
|
File details
Details for the file botomorph-1.0.0-py3-none-any.whl.
File metadata
- Download URL: botomorph-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83bd30165b31a27300d0e508f4b4044a035187eb967e122d201bd1fcaccb6392
|
|
| MD5 |
4b9fbd9c8b85a4ae868ca55afd07d210
|
|
| BLAKE2b-256 |
50e91299d398b0c6af8807e4c91ebd466157a2d6d842dbffff024bb8ffbfa2a9
|