1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Fix handler execution and #1594

This commit is contained in:
_run 2022-07-02 21:07:00 +05:00
parent c920809fa9
commit 1fb14e28d4

View File

@ -118,7 +118,20 @@ class AsyncTeleBot:
""" """
await asyncio_helper.session_manager.session.close() await asyncio_helper.session_manager.session.close()
async def get_updates(self, offset: Optional[int]=None, limit: Optional[int]=None, async def get_updates(self, offset: Optional[int]=None, limit: Optional[int]=None,
timeout: Optional[int]=None, allowed_updates: Optional[List]=None, request_timeout: Optional[int]=None) -> List[types.Update]: timeout: Optional[int]=20, allowed_updates: Optional[List]=None, request_timeout: Optional[int]=None) -> List[types.Update]:
"""
Use this method to receive incoming updates using long polling (wiki).
An Array of Update objects is returned.
Telegram documentation: https://core.telegram.org/bots/api#making-requests
:param allowed_updates: Array of string. List the types of updates you want your bot to receive.
:param offset: Integer. Identifier of the first update to be returned.
:param limit: Integer. Limits the number of updates to be retrieved.
:param timeout: Integer. Request connection timeout
:param request_timeout: Timeout in seconds for a request.
:return: array of Updates
"""
json_updates = await asyncio_helper.get_updates(self.token, offset, limit, timeout, allowed_updates, request_timeout) json_updates = await asyncio_helper.get_updates(self.token, offset, limit, timeout, allowed_updates, request_timeout)
return [types.Update.de_json(ju) for ju in json_updates] return [types.Update.de_json(ju) for ju in json_updates]
@ -299,12 +312,15 @@ class AsyncTeleBot:
params.append(i) params.append(i)
if len(params) == 1: if len(params) == 1:
await handler['function'](message) await handler['function'](message)
break
else: else:
if "data" in params: if "data" in params:
if len(params) == 2: if len(params) == 2:
await handler['function'](message, data) await handler['function'](message, data)
break
elif len(params) == 3: elif len(params) == 3:
await handler['function'](message, data=data, bot=self) await handler['function'](message, data=data, bot=self)
break
else: else:
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function'])) logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
return return
@ -323,14 +339,13 @@ class AsyncTeleBot:
return return
await handler["function"](message, **data_copy) await handler["function"](message, **data_copy)
break
except Exception as e: except Exception as e:
handler_error = e handler_error = e
if not middlewares: if self.exception_handler:
if self.exception_handler: self.exception_handler.handle(e)
return self.exception_handler.handle(e) else: logger.error(str(e))
logging.error(str(e))
return
if middlewares: if middlewares:
for middleware in middlewares: for middleware in middlewares: