From 44fe878f08b3f9d01f755ae11258f5204cab8186 Mon Sep 17 00:00:00 2001 From: mihalin Date: Fri, 10 Sep 2021 00:32:36 +0300 Subject: [PATCH] test --- server/server.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/server/server.py b/server/server.py index 6e0befc..bc99a64 100644 --- a/server/server.py +++ b/server/server.py @@ -47,16 +47,15 @@ async def cmd_start(message, *args, **kwargs): class CustomRequestHandler(WebhookRequestHandler): - def get_dispatcher(self): - """ - Get Dispatcher instance from environment - :return: :class:`aiogram.Dispatcher` - """ + def __init__(self, *args, **kwargs): + self._dispatcher = None + super(CustomRequestHandler, self).__init__(*args, **kwargs) + + def _create_dispatcher(self): key = self.request.url.path[1:] - # TODO: async - bot = asyncio.new_event_loop().run_until_complete(Bot.filter(code=key).first()) + bot = await Bot.filter(code=key).first() if not bot: return None @@ -66,6 +65,20 @@ class CustomRequestHandler(WebhookRequestHandler): return dp + def post(self): + # TODO: refactor + self._dispatcher = self._create_dispatcher() + super(CustomRequestHandler, self).post() + self._dispatcher = None + + def get_dispatcher(self): + """ + Get Dispatcher instance from environment + + :return: :class:`aiogram.Dispatcher` + """ + return self._dispatcher + def main(): loop = asyncio.get_event_loop()