diff --git a/telebot/__init__.py b/telebot/__init__.py index 5a3064c48..8b651a5b0 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -5564,7 +5564,7 @@ def create_invoice_link(self, # noinspection PyShadowingBuiltins def send_poll( - self, chat_id: Union[int, str], question: str, options: List[types.InputPollOption], + self, chat_id: Union[int, str], question: str, options: List[Union[str, types.InputPollOption]], is_anonymous: Optional[bool]=None, type: Optional[str]=None, allows_multiple_answers: Optional[bool]=None, correct_option_id: Optional[int]=None, @@ -5600,7 +5600,7 @@ def send_poll( :type question: :obj:`str` :param options: A JSON-serialized list of 2-10 answer options - :type options: :obj:`list` of :obj:`InputPollOption` + :type options: :obj:`list` of :obj:`InputPollOption` | :obj:`list` of :obj:`str` :param is_anonymous: True, if the poll needs to be anonymous, defaults to True :type is_anonymous: :obj:`bool` @@ -7578,9 +7578,8 @@ def set_state(self, user_id: int, state: Union[str, State], chat_id: Optional[in chat_id = user_id if bot_id is None: bot_id = self.bot_id - return self.current_states.set_state( - chat_id=chat_id, user_id=user_id, state=state, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return self.current_states.set_state(chat_id, user_id, state, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def reset_data(self, user_id: int, chat_id: Optional[int]=None, @@ -7611,8 +7610,8 @@ def reset_data(self, user_id: int, chat_id: Optional[int]=None, chat_id = user_id if bot_id is None: bot_id = self.bot_id - return self.current_states.reset_data(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return self.current_states.reset_data(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def delete_state(self, user_id: int, chat_id: Optional[int]=None, business_connection_id: Optional[str]=None, @@ -7630,6 +7629,15 @@ def delete_state(self, user_id: int, chat_id: Optional[int]=None, business_conne :param chat_id: Chat's identifier :type chat_id: :obj:`int` + :param bot_id: Bot's identifier, defaults to current bot id + :type bot_id: :obj:`int` + + :param business_connection_id: Business identifier + :type business_connection_id: :obj:`str` + + :param message_thread_id: Identifier of the message thread + :type message_thread_id: :obj:`int` + :return: True on success :rtype: :obj:`bool` """ @@ -7637,8 +7645,8 @@ def delete_state(self, user_id: int, chat_id: Optional[int]=None, business_conne chat_id = user_id if bot_id is None: bot_id = self.bot_id - return self.current_states.delete_state(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return self.current_states.delete_state(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def retrieve_data(self, user_id: int, chat_id: Optional[int]=None, business_connection_id: Optional[str]=None, @@ -7668,9 +7676,8 @@ def retrieve_data(self, user_id: int, chat_id: Optional[int]=None, business_conn chat_id = user_id if bot_id is None: bot_id = self.bot_id - return self.current_states.get_interactive_data(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, - message_thread_id=message_thread_id) + return self.current_states.get_interactive_data(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def get_state(self, user_id: int, chat_id: Optional[int]=None, @@ -7707,8 +7714,8 @@ def get_state(self, user_id: int, chat_id: Optional[int]=None, chat_id = user_id if bot_id is None: bot_id = self.bot_id - return self.current_states.get_state(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return self.current_states.get_state(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def add_data(self, user_id: int, chat_id: Optional[int]=None, @@ -7742,8 +7749,8 @@ def add_data(self, user_id: int, chat_id: Optional[int]=None, if bot_id is None: bot_id = self.bot_id for key, value in kwargs.items(): - self.current_states.set_data(chat_id=chat_id, user_id=user_id, key=key, value=value, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + self.current_states.set_data(chat_id, user_id, key, value, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def register_next_step_handler_by_chat_id( @@ -9848,4 +9855,3 @@ def _notify_command_handlers(self, handlers, new_messages, update_type): handlers=handlers, middlewares=middlewares, update_type=update_type) - diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 26e34934b..8c021b9a7 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -8,6 +8,7 @@ import sys # this imports are used to avoid circular import error +# noinspection PyUnresolvedReferences import telebot.util import telebot.types @@ -7008,7 +7009,7 @@ async def create_invoice_link(self, # noinspection PyShadowingBuiltins async def send_poll( - self, chat_id: Union[int, str], question: str, options: List[types.InputPollOption], + self, chat_id: Union[int, str], question: str, options: List[Union[str, types.InputPollOption]], is_anonymous: Optional[bool]=None, type: Optional[str]=None, allows_multiple_answers: Optional[bool]=None, correct_option_id: Optional[int]=None, @@ -7044,7 +7045,7 @@ async def send_poll( :type question: :obj:`str` :param options: A JSON-serialized list of 2-10 answer options - :type options: :obj:`list` of :obj:`InputPollOption` + :type options: :obj:`list` of :obj:`InputPollOption` | :obj:`list` of :obj:`str` :param is_anonymous: True, if the poll needs to be anonymous, defaults to True :type is_anonymous: :obj:`bool` @@ -8828,9 +8829,8 @@ async def set_state(self, user_id: int, state: Union[int, str, State], chat_id: chat_id = user_id if bot_id is None: bot_id = self.bot_id - return await self.current_states.set_state( - chat_id=chat_id, user_id=user_id, state=state, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return await self.current_states.set_state(chat_id, user_id, state, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) async def reset_data(self, user_id: int, chat_id: Optional[int]=None, @@ -8861,8 +8861,8 @@ async def reset_data(self, user_id: int, chat_id: Optional[int]=None, chat_id = user_id if bot_id is None: bot_id = self.bot_id - return await self.current_states.reset_data(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return await self.current_states.reset_data(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) async def delete_state(self, user_id: int, chat_id: Optional[int]=None, business_connection_id: Optional[str]=None, @@ -8876,14 +8876,23 @@ async def delete_state(self, user_id: int, chat_id: Optional[int]=None, business :param chat_id: Chat's identifier :type chat_id: :obj:`int` + :param bot_id: Bot's identifier, defaults to current bot id + :type bot_id: :obj:`int` + + :param business_connection_id: Business identifier + :type business_connection_id: :obj:`str` + + :param message_thread_id: Identifier of the message thread + :type message_thread_id: :obj:`int` + :return: None """ if chat_id is None: chat_id = user_id if bot_id is None: bot_id = self.bot_id - return await self.current_states.delete_state(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return await self.current_states.delete_state(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) def retrieve_data(self, user_id: int, chat_id: Optional[int]=None, business_connection_id: Optional[str]=None, @@ -8913,9 +8922,8 @@ def retrieve_data(self, user_id: int, chat_id: Optional[int]=None, business_conn chat_id = user_id if bot_id is None: bot_id = self.bot_id - return self.current_states.get_interactive_data(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, - message_thread_id=message_thread_id) + return self.current_states.get_interactive_data(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) async def get_state(self, user_id: int, chat_id: Optional[int]=None, @@ -8952,8 +8960,8 @@ async def get_state(self, user_id: int, chat_id: Optional[int]=None, chat_id = user_id if bot_id is None: bot_id = self.bot_id - return await self.current_states.get_state(chat_id=chat_id, user_id=user_id, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + return await self.current_states.get_state(chat_id, user_id, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) async def add_data(self, user_id: int, chat_id: Optional[int]=None, @@ -8987,5 +8995,5 @@ async def add_data(self, user_id: int, chat_id: Optional[int]=None, if bot_id is None: bot_id = self.bot_id for key, value in kwargs.items(): - await self.current_states.set_data(chat_id=chat_id, user_id=user_id, key=key, value=value, bot_id=bot_id, - business_connection_id=business_connection_id, message_thread_id=message_thread_id) + await self.current_states.set_data(chat_id, user_id, key, value, + bot_id=bot_id, business_connection_id=business_connection_id, message_thread_id=message_thread_id) diff --git a/telebot/asyncio_storage/base_storage.py b/telebot/asyncio_storage/base_storage.py index 20d0b0587..191ac45f4 100644 --- a/telebot/asyncio_storage/base_storage.py +++ b/telebot/asyncio_storage/base_storage.py @@ -5,7 +5,11 @@ class StateStorageBase: def __init__(self) -> None: pass - async def set_data(self, chat_id, user_id, key, value): + async def set_data(self, chat_id, user_id, key, value, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Set data for a user in a particular chat. """ @@ -17,7 +21,11 @@ async def get_data(self, chat_id, user_id): """ raise NotImplementedError - async def set_state(self, chat_id, user_id, state): + async def set_state(self, chat_id, user_id, state, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Set state for a particular user. @@ -28,22 +36,38 @@ async def set_state(self, chat_id, user_id, state): """ raise NotImplementedError - async def delete_state(self, chat_id, user_id): + async def delete_state(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Delete state for a particular user. """ raise NotImplementedError - async def reset_data(self, chat_id, user_id): + async def reset_data(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Reset data for a particular user in a chat. """ raise NotImplementedError - async def get_state(self, chat_id, user_id): + async def get_state(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): raise NotImplementedError - def get_interactive_data(self, chat_id, user_id): + def get_interactive_data(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Should be sync, but should provide a context manager with __aenter__ and __aexit__ methods. diff --git a/telebot/states/asyncio/context.py b/telebot/states/asyncio/context.py index 4c9ad61a3..50f252021 100644 --- a/telebot/states/asyncio/context.py +++ b/telebot/states/asyncio/context.py @@ -1,4 +1,4 @@ -from telebot.states import State, StatesGroup +from telebot.states import State from telebot.types import CallbackQuery, Message from telebot.async_telebot import AsyncTeleBot from telebot.states import resolve_context @@ -21,7 +21,7 @@ async def start_ex(message: types.Message, state_context: StateContext): # also, state_context.data(), .add_data(), .reset_data(), .delete() methods available. """ - def __init__(self, message: Union[Message, CallbackQuery], bot: str) -> None: + def __init__(self, message: Union[Message, CallbackQuery], bot: AsyncTeleBot) -> None: self.message: Union[Message, CallbackQuery] = message self.bot: AsyncTeleBot = bot self.bot_id = self.bot.bot_id diff --git a/telebot/storage/base_storage.py b/telebot/storage/base_storage.py index 9956c7ab9..033f63231 100644 --- a/telebot/storage/base_storage.py +++ b/telebot/storage/base_storage.py @@ -5,7 +5,11 @@ class StateStorageBase: def __init__(self) -> None: pass - def set_data(self, chat_id, user_id, key, value): + def set_data(self, chat_id, user_id, key, value, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Set data for a user in a particular chat. """ @@ -17,7 +21,11 @@ def get_data(self, chat_id, user_id): """ raise NotImplementedError - def set_state(self, chat_id, user_id, state): + def set_state(self, chat_id, user_id, state, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Set state for a particular user. @@ -28,22 +36,38 @@ def set_state(self, chat_id, user_id, state): """ raise NotImplementedError - def delete_state(self, chat_id, user_id): + def delete_state(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Delete state for a particular user. """ raise NotImplementedError - def reset_data(self, chat_id, user_id): + def reset_data(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): """ Reset data for a particular user in a chat. """ raise NotImplementedError - def get_state(self, chat_id, user_id): + def get_state(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): raise NotImplementedError - def get_interactive_data(self, chat_id, user_id): + def get_interactive_data(self, chat_id, user_id, + business_connection_id=None, + message_thread_id=None, + bot_id=None, + ): raise NotImplementedError def save(self, chat_id, user_id, data):