mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Pass only the necessary data
This commit is contained in:
parent
a2893945b2
commit
6e8abc709e
@ -4022,12 +4022,19 @@ class TeleBot:
|
||||
return
|
||||
|
||||
else:
|
||||
if handler.get('pass_bot'): data["bot"] = self
|
||||
if len(data) > len(params) - 1: # remove the message parameter
|
||||
|
||||
data_copy = data.copy()
|
||||
|
||||
for key in list(data_copy):
|
||||
# remove data from data_copy if handler does not accept it
|
||||
if key not in params:
|
||||
del data_copy[key]
|
||||
if handler.get('pass_bot'): data_copy["bot"] = self
|
||||
if len(data_copy) > len(params) - 1: # remove the message parameter
|
||||
logger.error("You are passing more data than the handler needs. Check your handler: {}".format(handler['function']))
|
||||
return
|
||||
|
||||
handler["function"](message, **data)
|
||||
handler["function"](message, **data_copy)
|
||||
|
||||
except Exception as e:
|
||||
handler_error = e
|
||||
@ -4038,8 +4045,6 @@ class TeleBot:
|
||||
logging.error(str(e))
|
||||
return
|
||||
# remove the bot from data
|
||||
if "bot" in data:
|
||||
del data["bot"]
|
||||
if middlewares:
|
||||
for middleware in middlewares:
|
||||
middleware.post_process(message, data, handler_error)
|
||||
|
@ -309,13 +309,20 @@ class AsyncTeleBot:
|
||||
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
|
||||
return
|
||||
|
||||
else:
|
||||
|
||||
if handler.get('pass_bot'): data["bot"] = self
|
||||
if len(data) > len(params) - 1:
|
||||
else:
|
||||
|
||||
data_copy = data.copy()
|
||||
|
||||
for key in list(data_copy):
|
||||
# remove data from data_copy if handler does not accept it
|
||||
if key not in params:
|
||||
del data_copy[key]
|
||||
if handler.get('pass_bot'): data_copy["bot"] = self
|
||||
if len(data_copy) > len(params) - 1: # remove the message parameter
|
||||
logger.error("You are passing more data than the handler needs. Check your handler: {}".format(handler['function']))
|
||||
return
|
||||
await handler["function"](message, **data)
|
||||
|
||||
handler["function"](message, **data_copy)
|
||||
except Exception as e:
|
||||
handler_error = e
|
||||
|
||||
@ -324,9 +331,6 @@ class AsyncTeleBot:
|
||||
return self.exception_handler.handle(e)
|
||||
logging.error(str(e))
|
||||
return
|
||||
# remove the bot from data
|
||||
if "bot" in data:
|
||||
del data["bot"]
|
||||
|
||||
if middlewares:
|
||||
for middleware in middlewares:
|
||||
|
Loading…
Reference in New Issue
Block a user