mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Middleware update: everything in data will be passed to handler if needed.
This commit is contained in:
parent
24b1129c8a
commit
1686ce4f44
@ -3999,6 +3999,7 @@ class TeleBot:
|
|||||||
elif isinstance(result, SkipHandler) and skip_handler is False:
|
elif isinstance(result, SkipHandler) and skip_handler is False:
|
||||||
skip_handler = True
|
skip_handler = True
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if handlers and not skip_handler:
|
if handlers and not skip_handler:
|
||||||
for handler in handlers:
|
for handler in handlers:
|
||||||
@ -4009,23 +4010,22 @@ class TeleBot:
|
|||||||
params.append(i)
|
params.append(i)
|
||||||
if len(params) == 1:
|
if len(params) == 1:
|
||||||
handler['function'](message)
|
handler['function'](message)
|
||||||
|
else:
|
||||||
elif len(params) == 2:
|
if "data" in params:
|
||||||
if handler.get('pass_bot') is True:
|
if len(params) == 2:
|
||||||
handler['function'](message, self)
|
|
||||||
|
|
||||||
elif handler.get('pass_bot') is False:
|
|
||||||
handler['function'](message, data)
|
handler['function'](message, data)
|
||||||
|
|
||||||
elif len(params) == 3:
|
elif len(params) == 3:
|
||||||
if params[2] == 'bot' and handler.get('pass_bot') is True:
|
handler['function'](message, data=data, bot=self)
|
||||||
handler['function'](message, data, self)
|
else:
|
||||||
|
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
|
||||||
elif not handler.get('pass_bot'):
|
return
|
||||||
raise RuntimeError('Your handler accepts 3 parameters but pass_bot is False. Please re-check your handler.')
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
handler['function'](message, self, data)
|
if len(data) > len(params) -2:
|
||||||
|
logger.error("You are passing more data than the handler needs. Check your handler: {}".format(handler['function']))
|
||||||
|
return
|
||||||
|
if handler.get('pass_bot'): data["bot"] = self
|
||||||
|
handler["function"](message, **data)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
handler_error = e
|
handler_error = e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user