mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Support ContinueHandling
This commit is contained in:
parent
82ad37fed8
commit
30aaf8d0f1
@ -37,7 +37,10 @@ logger.addHandler(console_output_handler)
|
|||||||
logger.setLevel(logging.ERROR)
|
logger.setLevel(logging.ERROR)
|
||||||
|
|
||||||
from telebot import apihelper, util, types
|
from telebot import apihelper, util, types
|
||||||
from telebot.handler_backends import HandlerBackend, MemoryHandlerBackend, FileHandlerBackend, BaseMiddleware, CancelUpdate, SkipHandler, State
|
from telebot.handler_backends import (
|
||||||
|
HandlerBackend, MemoryHandlerBackend, FileHandlerBackend, BaseMiddleware,
|
||||||
|
CancelUpdate, SkipHandler, State, ContinueHandling
|
||||||
|
)
|
||||||
from telebot.custom_filters import SimpleCustomFilter, AdvancedCustomFilter
|
from telebot.custom_filters import SimpleCustomFilter, AdvancedCustomFilter
|
||||||
|
|
||||||
|
|
||||||
@ -6111,13 +6114,14 @@ class TeleBot:
|
|||||||
if not process_handler: continue
|
if not process_handler: continue
|
||||||
for i in inspect.signature(handler['function']).parameters:
|
for i in inspect.signature(handler['function']).parameters:
|
||||||
params.append(i)
|
params.append(i)
|
||||||
|
result = None
|
||||||
if len(params) == 1:
|
if len(params) == 1:
|
||||||
handler['function'](message)
|
result = handler['function'](message)
|
||||||
elif "data" in params:
|
elif "data" in params:
|
||||||
if len(params) == 2:
|
if len(params) == 2:
|
||||||
handler['function'](message, data)
|
result = handler['function'](message, data)
|
||||||
elif len(params) == 3:
|
elif len(params) == 3:
|
||||||
handler['function'](message, data=data, bot=self)
|
result = handler['function'](message, data=data, bot=self)
|
||||||
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
|
||||||
@ -6132,8 +6136,9 @@ class TeleBot:
|
|||||||
if len(data_copy) > len(params) - 1: # remove the message parameter
|
if len(data_copy) > len(params) - 1: # remove the message parameter
|
||||||
logger.error("You are passing more parameters than the handler needs. Check your handler: {}".format(handler['function']))
|
logger.error("You are passing more parameters than the handler needs. Check your handler: {}".format(handler['function']))
|
||||||
return
|
return
|
||||||
handler["function"](message, **data_copy)
|
result = handler["function"](message, **data_copy)
|
||||||
break
|
if not isinstance(result, ContinueHandling):
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
handler_error = e
|
handler_error = e
|
||||||
if self.exception_handler:
|
if self.exception_handler:
|
||||||
|
@ -14,7 +14,7 @@ import telebot.types
|
|||||||
|
|
||||||
# storages
|
# storages
|
||||||
from telebot.asyncio_storage import StateMemoryStorage, StatePickleStorage, StateStorageBase
|
from telebot.asyncio_storage import StateMemoryStorage, StatePickleStorage, StateStorageBase
|
||||||
from telebot.asyncio_handler_backends import BaseMiddleware, CancelUpdate, SkipHandler, State
|
from telebot.asyncio_handler_backends import BaseMiddleware, CancelUpdate, SkipHandler, State, ContinueHandling
|
||||||
|
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
|
|
||||||
@ -493,16 +493,14 @@ class AsyncTeleBot:
|
|||||||
if not process_update: continue
|
if not process_update: continue
|
||||||
for i in signature(handler['function']).parameters:
|
for i in signature(handler['function']).parameters:
|
||||||
params.append(i)
|
params.append(i)
|
||||||
|
result = None
|
||||||
if len(params) == 1:
|
if len(params) == 1:
|
||||||
await handler['function'](message)
|
result = await handler['function'](message)
|
||||||
break
|
|
||||||
elif "data" in params:
|
elif "data" in params:
|
||||||
if len(params) == 2:
|
if len(params) == 2:
|
||||||
await handler['function'](message, data)
|
result = await handler['function'](message, data)
|
||||||
break
|
|
||||||
elif len(params) == 3:
|
elif len(params) == 3:
|
||||||
await handler['function'](message, data=data, bot=self)
|
result = 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
|
||||||
@ -517,7 +515,8 @@ class AsyncTeleBot:
|
|||||||
if len(data_copy) > len(params) - 1: # remove the message parameter
|
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']))
|
logger.error("You are passing more data than the handler needs. Check your handler: {}".format(handler['function']))
|
||||||
return
|
return
|
||||||
await handler["function"](message, **data_copy)
|
result = await handler["function"](message, **data_copy)
|
||||||
|
if not isinstance(result, ContinueHandling):
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.exception_handler:
|
if self.exception_handler:
|
||||||
|
@ -174,7 +174,6 @@ class State:
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class StatesGroup:
|
class StatesGroup:
|
||||||
"""
|
"""
|
||||||
@ -192,9 +191,6 @@ class StatesGroup:
|
|||||||
value.name = ':'.join((cls.__name__, name))
|
value.name = ':'.join((cls.__name__, name))
|
||||||
value.group = cls
|
value.group = cls
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseMiddleware:
|
class BaseMiddleware:
|
||||||
"""
|
"""
|
||||||
@ -254,8 +250,6 @@ class SkipHandler:
|
|||||||
but will skip execution of handler.
|
but will skip execution of handler.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class CancelUpdate:
|
class CancelUpdate:
|
||||||
"""
|
"""
|
||||||
@ -266,5 +260,9 @@ class CancelUpdate:
|
|||||||
of post_process in middlewares.
|
of post_process in middlewares.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
class ContinueHandling:
|
||||||
pass
|
"""
|
||||||
|
Class for continue updates in handlers.
|
||||||
|
Just return instance of this class
|
||||||
|
in handlers to continue process.
|
||||||
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user