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)
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -6111,13 +6114,14 @@ class TeleBot:
|
||||
if not process_handler: continue
|
||||
for i in inspect.signature(handler['function']).parameters:
|
||||
params.append(i)
|
||||
result = None
|
||||
if len(params) == 1:
|
||||
handler['function'](message)
|
||||
result = handler['function'](message)
|
||||
elif "data" in params:
|
||||
if len(params) == 2:
|
||||
handler['function'](message, data)
|
||||
result = handler['function'](message, data)
|
||||
elif len(params) == 3:
|
||||
handler['function'](message, data=data, bot=self)
|
||||
result = handler['function'](message, data=data, bot=self)
|
||||
else:
|
||||
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
|
||||
return
|
||||
@ -6132,8 +6136,9 @@ class TeleBot:
|
||||
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']))
|
||||
return
|
||||
handler["function"](message, **data_copy)
|
||||
break
|
||||
result = handler["function"](message, **data_copy)
|
||||
if not isinstance(result, ContinueHandling):
|
||||
break
|
||||
except Exception as e:
|
||||
handler_error = e
|
||||
if self.exception_handler:
|
||||
|
@ -14,7 +14,7 @@ import telebot.types
|
||||
|
||||
# storages
|
||||
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
|
||||
|
||||
@ -493,16 +493,14 @@ class AsyncTeleBot:
|
||||
if not process_update: continue
|
||||
for i in signature(handler['function']).parameters:
|
||||
params.append(i)
|
||||
result = None
|
||||
if len(params) == 1:
|
||||
await handler['function'](message)
|
||||
break
|
||||
result = await handler['function'](message)
|
||||
elif "data" in params:
|
||||
if len(params) == 2:
|
||||
await handler['function'](message, data)
|
||||
break
|
||||
result = await handler['function'](message, data)
|
||||
elif len(params) == 3:
|
||||
await handler['function'](message, data=data, bot=self)
|
||||
break
|
||||
result = await handler['function'](message, data=data, bot=self)
|
||||
else:
|
||||
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
|
||||
return
|
||||
@ -517,7 +515,8 @@ class AsyncTeleBot:
|
||||
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_copy)
|
||||
result = await handler["function"](message, **data_copy)
|
||||
if not isinstance(result, ContinueHandling):
|
||||
break
|
||||
except Exception as e:
|
||||
if self.exception_handler:
|
||||
|
@ -174,7 +174,6 @@ class State:
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
|
||||
class StatesGroup:
|
||||
"""
|
||||
@ -192,9 +191,6 @@ class StatesGroup:
|
||||
value.name = ':'.join((cls.__name__, name))
|
||||
value.group = cls
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class BaseMiddleware:
|
||||
"""
|
||||
@ -254,8 +250,6 @@ class SkipHandler:
|
||||
but will skip execution of handler.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
class CancelUpdate:
|
||||
"""
|
||||
@ -266,5 +260,9 @@ class CancelUpdate:
|
||||
of post_process in middlewares.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
class ContinueHandling:
|
||||
"""
|
||||
Class for continue updates in handlers.
|
||||
Just return instance of this class
|
||||
in handlers to continue process.
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user