add command params
This commit is contained in:
@@ -2,7 +2,7 @@ from aiogram.types import Message, CallbackQuery
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.utils.i18n import I18n
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from typing import Any, Callable, TYPE_CHECKING, Literal
|
||||
from typing import Any, Callable, TYPE_CHECKING, Literal, Union
|
||||
from babel.support import LazyProxy
|
||||
from dataclasses import dataclass, field
|
||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
@@ -18,22 +18,21 @@ if TYPE_CHECKING:
|
||||
|
||||
EntityCaptionCallable = Callable[["EntityDescriptor"], str]
|
||||
EntityItemCaptionCallable = Callable[["EntityDescriptor", Any], str]
|
||||
EntityFieldCaptionCallable = Callable[["EntityFieldDescriptor", Any, Any], str]
|
||||
EntityFieldCaptionCallable = Callable[["FieldDescriptor", Any, Any], str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class FieldEditButton:
|
||||
field_name: str
|
||||
visibility: Callable[[Any], bool] | None = None
|
||||
caption: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
visibility: Callable[[Any], bool] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class CommandButton:
|
||||
command: str
|
||||
caption: str | LazyProxy | EntityItemCaptionCallable | None = None
|
||||
command: ContextData | Callable[[ContextData, Any], ContextData] | str
|
||||
caption: str | LazyProxy | EntityItemCaptionCallable
|
||||
visibility: Callable[[Any], bool] | None = None
|
||||
context_data: ContextData | Callable[[ContextData, Any], ContextData] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -81,7 +80,7 @@ class EntityForm:
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class _BaseEntityFieldDescriptor:
|
||||
class _BaseFieldDescriptor:
|
||||
icon: str = None
|
||||
caption: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
description: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
@@ -99,18 +98,24 @@ class _BaseEntityFieldDescriptor:
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class EntityField(_BaseEntityFieldDescriptor):
|
||||
class EntityField(_BaseFieldDescriptor):
|
||||
name: str | None = None
|
||||
sm_descriptor: Any = None
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Setting(_BaseEntityFieldDescriptor):
|
||||
class Setting(_BaseFieldDescriptor):
|
||||
name: str | None = None
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class EntityFieldDescriptor(_BaseEntityFieldDescriptor):
|
||||
class FormField(_BaseFieldDescriptor):
|
||||
name: str | None = None
|
||||
type_: type
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class FieldDescriptor(_BaseFieldDescriptor):
|
||||
name: str
|
||||
field_name: str
|
||||
type_: type
|
||||
@@ -118,6 +123,7 @@ class EntityFieldDescriptor(_BaseEntityFieldDescriptor):
|
||||
is_list: bool = False
|
||||
is_optional: bool = False
|
||||
entity_descriptor: "EntityDescriptor" = None
|
||||
command: "BotCommand" = None
|
||||
|
||||
def __hash__(self):
|
||||
return self.name.__hash__()
|
||||
@@ -162,7 +168,7 @@ class EntityDescriptor(_BaseEntityDescriptor):
|
||||
name: str
|
||||
class_name: str
|
||||
type_: type["BotEntity"]
|
||||
fields_descriptors: dict[str, EntityFieldDescriptor]
|
||||
fields_descriptors: dict[str, FieldDescriptor]
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
@@ -179,24 +185,21 @@ class CommandCallbackContext[UT: UserBase]:
|
||||
app: "QBotApp"
|
||||
state_data: dict[str, Any]
|
||||
state: FSMContext
|
||||
form_data: dict[str, Any]
|
||||
i18n: I18n
|
||||
kwargs: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class _BotCommand:
|
||||
class BotCommand:
|
||||
name: str
|
||||
caption: str | dict[str, str] | None = None
|
||||
pre_check: Callable[[Union[Message, CallbackQuery], Any], bool] | None = None
|
||||
show_in_bot_commands: bool = False
|
||||
register_navigation: bool = True
|
||||
clear_navigation: bool = False
|
||||
clear_state: bool = True
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class BotCommand(_BotCommand):
|
||||
param_form: dict[str, FieldDescriptor] | None = None
|
||||
show_cancel_in_param_form: bool = True
|
||||
show_back_in_param_form: bool = True
|
||||
handler: Callable[[CommandCallbackContext], None]
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Command(_BotCommand): ...
|
||||
|
||||
Reference in New Issue
Block a user