Welcome to CommandMk2’s documentation!
Installation
pip install command-mk2
Wheels are also available on PyPI https://pypi.org/project/command-mk2/#files
Usage
Filter CommandMk2 supports the argument mask in the command:
from command_mk2 import CommandMk2
CommandMk2('add { note } { timestamp }')
This variables can be optionally provided by the user. Variables after “timestamp” will not be parsed.
@router.message(CommandMk2('add { note } { timestamp }'))
async def add_note(message: Message, note: Optional[str], timestamp: Optional[str]) -> None:
"""Typical handler.
Note and timestamp is str for now, in next examples i will show typed arguments.
"""
You can describe the types of arguments using Pydantic model
class AddingNote(BaseModel):
note: str
timestamp: Optional[date]
CommandMk2('add { note } { timestamp }', response_model=AddingNote)
You will recieve ValidatonError if note from command will be empty, because note is not Optional.You can user aiogram error_handler for that error.
@router.message(CommandMk2('add { note } { timestamp }', response_model=AddingNote, response_model_name='vars'))
async def add_note(message: Message, note: str, timestamp: Optional[date]) -> None:
"""Typical handler.
Note and timestamp is typed properly.
"""