Move DTO definitions from dto/ to schemas/ and update imports. Add buy handler with FSM state management for device selection, whitelist toggling, and duration choice. Include pricing logic, inline keyboards, and new configuration fields.
27 lines
793 B
Python
27 lines
793 B
Python
from typing import Callable, Awaitable, Any
|
|
from aiogram import BaseMiddleware
|
|
from aiogram.types import TelegramObject
|
|
from sqlalchemy.ext.asyncio import async_sessionmaker
|
|
|
|
from schemas.di import DependenciesDTO
|
|
|
|
|
|
class DIMiddleware(BaseMiddleware):
|
|
def __init__(
|
|
self, deps: DependenciesDTO, session_factory: async_sessionmaker
|
|
) -> None:
|
|
self.deps = deps
|
|
self.session_factory = session_factory
|
|
|
|
async def __call__(
|
|
self,
|
|
handler: Callable[[TelegramObject, dict[str, Any]], Awaitable[Any]],
|
|
event: TelegramObject,
|
|
data: dict[str, Any],
|
|
) -> Any:
|
|
data["deps"] = self.deps
|
|
|
|
async with self.session_factory() as session:
|
|
data["session"] = session
|
|
return await handler(event, data)
|