This commit is contained in:
mihalin 2021-09-10 00:32:36 +03:00
parent 92d0968276
commit 44fe878f08

View File

@ -47,16 +47,15 @@ async def cmd_start(message, *args, **kwargs):
class CustomRequestHandler(WebhookRequestHandler): 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:] key = self.request.url.path[1:]
# TODO: async bot = await Bot.filter(code=key).first()
bot = asyncio.new_event_loop().run_until_complete(Bot.filter(code=key).first())
if not bot: if not bot:
return None return None
@ -66,6 +65,20 @@ class CustomRequestHandler(WebhookRequestHandler):
return dp 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(): def main():
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()