2018-09-20 22:50:40 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2021-01-03 06:10:24 +01:00
|
|
|
# Copyright (C) 2015-2021
|
2018-09-20 22:50:40 +02:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser Public License
|
|
|
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
|
|
|
"""This module contains the BasePersistence class."""
|
2020-11-14 03:08:18 +01:00
|
|
|
import warnings
|
2021-05-29 16:18:16 +02:00
|
|
|
from sys import version_info as py_ver
|
2020-05-01 20:27:34 +02:00
|
|
|
from abc import ABC, abstractmethod
|
2020-07-13 21:52:26 +02:00
|
|
|
from copy import copy
|
2021-06-06 10:37:53 +02:00
|
|
|
from typing import Dict, Optional, Tuple, cast, ClassVar, Generic, DefaultDict
|
2020-07-13 21:52:26 +02:00
|
|
|
|
2021-05-29 16:18:16 +02:00
|
|
|
from telegram.utils.deprecate import set_new_attribute_deprecated
|
|
|
|
|
2020-07-13 21:52:26 +02:00
|
|
|
from telegram import Bot
|
2021-06-06 11:48:48 +02:00
|
|
|
import telegram.ext.extbot
|
2018-09-20 22:50:40 +02:00
|
|
|
|
2021-06-06 11:48:48 +02:00
|
|
|
from telegram.ext.utils.types import UD, CD, BD, ConversationDict, CDCData
|
2020-10-06 19:28:40 +02:00
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
class BasePersistence(Generic[UD, CD, BD], ABC):
|
2018-09-20 22:50:40 +02:00
|
|
|
"""Interface class for adding persistence to your bot.
|
|
|
|
Subclass this object for different implementations of a persistent bot.
|
|
|
|
|
2020-12-17 09:29:17 +01:00
|
|
|
All relevant methods must be overwritten. This includes:
|
|
|
|
|
2020-12-30 15:59:50 +01:00
|
|
|
* :meth:`get_bot_data`
|
2020-12-17 09:29:17 +01:00
|
|
|
* :meth:`update_bot_data`
|
2021-06-06 10:37:53 +02:00
|
|
|
* :meth:`refresh_bot_data`
|
2020-12-17 09:29:17 +01:00
|
|
|
* :meth:`get_chat_data`
|
|
|
|
* :meth:`update_chat_data`
|
2021-06-06 10:37:53 +02:00
|
|
|
* :meth:`refresh_chat_data`
|
2020-12-17 09:29:17 +01:00
|
|
|
* :meth:`get_user_data`
|
|
|
|
* :meth:`update_user_data`
|
2021-06-06 10:37:53 +02:00
|
|
|
* :meth:`refresh_user_data`
|
2021-06-06 11:48:48 +02:00
|
|
|
* :meth:`get_callback_data`
|
|
|
|
* :meth:`update_callback_data`
|
2020-12-17 09:29:17 +01:00
|
|
|
* :meth:`get_conversations`
|
|
|
|
* :meth:`update_conversation`
|
|
|
|
* :meth:`flush`
|
|
|
|
|
|
|
|
If you don't actually need one of those methods, a simple ``pass`` is enough. For example, if
|
2021-06-06 10:37:53 +02:00
|
|
|
``store_bot_data=False``, you don't need :meth:`get_bot_data`, :meth:`update_bot_data` or
|
|
|
|
:meth:`refresh_bot_data`.
|
2018-09-20 22:50:40 +02:00
|
|
|
|
2020-07-13 21:52:26 +02:00
|
|
|
Warning:
|
|
|
|
Persistence will try to replace :class:`telegram.Bot` instances by :attr:`REPLACED_BOT` and
|
|
|
|
insert the bot set with :meth:`set_bot` upon loading of the data. This is to ensure that
|
|
|
|
changes to the bot apply to the saved objects, too. If you change the bots token, this may
|
|
|
|
lead to e.g. ``Chat not found`` errors. For the limitations on replacing bots see
|
|
|
|
:meth:`replace_bot` and :meth:`insert_bot`.
|
|
|
|
|
|
|
|
Note:
|
|
|
|
:meth:`replace_bot` and :meth:`insert_bot` are used *independently* of the implementation
|
|
|
|
of the :meth:`update/get_*` methods, i.e. you don't need to worry about it while
|
|
|
|
implementing a custom persistence subclass.
|
|
|
|
|
2018-09-20 22:50:40 +02:00
|
|
|
Args:
|
|
|
|
store_user_data (:obj:`bool`, optional): Whether user_data should be saved by this
|
Documentation Improvements (#2008)
* Minor doc updates, following official API docs
* Fix spelling in Defaults docstrings
* Clarify Changelog of v12.7 about aware dates
* Fix typo in CHANGES.rst (#2024)
* Fix PicklePersistence.flush() with only bot_data (#2017)
* Update pylint in pre-commit to fix CI (#2018)
* Add Filters.via_bot (#2009)
* feat: via_bot filter
also fixing a small mistake in the empty parameter of the user filter and improve docs slightly
* fix: forgot to set via_bot to None
* fix: redoing subclassing to copy paste solution
* Cosmetic changes
Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
* Update CHANGES.rst
Fixed Typo
Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
* Update downloads badge, add info on IRC Channel to Getting Help section
* Remove RegexHandler from ConversationHandlers Docs (#1973)
Replaced RegexHandler with MessageHandler, since the former is deprecated
* Fix Filters.via_bot docstrings
* Add notes on Markdown v1 being legacy mode
* Fixed typo in the Regex doc.. (#2036)
* Typo: Spelling
* Minor cleanup from #2043
* Document CommandHandler ignoring channel posts
* Doc fixes for a few telegram.ext classes
* Doc fixes for most `telegram` classes.
* pep-8
forgot the hard wrap is at 99 chars, not 100!
fixed a few spelling mistakes too.
* Address review and made rendering of booleans consistent
True, False, None are now rendered with ``bool`` wherever they weren't in telegram and telegram.ext classes.
* Few doc fixes for inline* classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram/files classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram.Game
Mostly just added hyperlinks. And fixed message length doc.
As usual, docs were cross-checked with official tg api docs.
* Very minor doc fix for passportfile.py and passportelementerrors.py
Didn't bother changing too much since this seems to be a custom implementation.
* Doc fixes for telegram.payments
As usual, cross-checked with official bot api docs.
* Address review 2
Few tiny other fixes too.
* Changed from ``True/False/None`` to :obj:`True/False/None` project-wide.
Few tiny other doc fixes too.
Co-authored-by: Robert Geislinger <mitachundkrach@gmail.com>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
Co-authored-by: GauthamramRavichandran <30320759+GauthamramRavichandran@users.noreply.github.com>
Co-authored-by: Mahesh19 <maheshvagicherla99438@gmail.com>
Co-authored-by: hoppingturtles <ilovebhagwan@gmail.com>
2020-08-24 19:35:57 +02:00
|
|
|
persistence class. Default is :obj:`True`.
|
2018-09-20 22:50:40 +02:00
|
|
|
store_chat_data (:obj:`bool`, optional): Whether chat_data should be saved by this
|
Documentation Improvements (#2008)
* Minor doc updates, following official API docs
* Fix spelling in Defaults docstrings
* Clarify Changelog of v12.7 about aware dates
* Fix typo in CHANGES.rst (#2024)
* Fix PicklePersistence.flush() with only bot_data (#2017)
* Update pylint in pre-commit to fix CI (#2018)
* Add Filters.via_bot (#2009)
* feat: via_bot filter
also fixing a small mistake in the empty parameter of the user filter and improve docs slightly
* fix: forgot to set via_bot to None
* fix: redoing subclassing to copy paste solution
* Cosmetic changes
Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
* Update CHANGES.rst
Fixed Typo
Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
* Update downloads badge, add info on IRC Channel to Getting Help section
* Remove RegexHandler from ConversationHandlers Docs (#1973)
Replaced RegexHandler with MessageHandler, since the former is deprecated
* Fix Filters.via_bot docstrings
* Add notes on Markdown v1 being legacy mode
* Fixed typo in the Regex doc.. (#2036)
* Typo: Spelling
* Minor cleanup from #2043
* Document CommandHandler ignoring channel posts
* Doc fixes for a few telegram.ext classes
* Doc fixes for most `telegram` classes.
* pep-8
forgot the hard wrap is at 99 chars, not 100!
fixed a few spelling mistakes too.
* Address review and made rendering of booleans consistent
True, False, None are now rendered with ``bool`` wherever they weren't in telegram and telegram.ext classes.
* Few doc fixes for inline* classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram/files classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram.Game
Mostly just added hyperlinks. And fixed message length doc.
As usual, docs were cross-checked with official tg api docs.
* Very minor doc fix for passportfile.py and passportelementerrors.py
Didn't bother changing too much since this seems to be a custom implementation.
* Doc fixes for telegram.payments
As usual, cross-checked with official bot api docs.
* Address review 2
Few tiny other fixes too.
* Changed from ``True/False/None`` to :obj:`True/False/None` project-wide.
Few tiny other doc fixes too.
Co-authored-by: Robert Geislinger <mitachundkrach@gmail.com>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
Co-authored-by: GauthamramRavichandran <30320759+GauthamramRavichandran@users.noreply.github.com>
Co-authored-by: Mahesh19 <maheshvagicherla99438@gmail.com>
Co-authored-by: hoppingturtles <ilovebhagwan@gmail.com>
2020-08-24 19:35:57 +02:00
|
|
|
persistence class. Default is :obj:`True` .
|
2020-02-02 22:20:31 +01:00
|
|
|
store_bot_data (:obj:`bool`, optional): Whether bot_data should be saved by this
|
2021-06-06 11:48:48 +02:00
|
|
|
persistence class. Default is :obj:`True`.
|
|
|
|
store_callback_data (:obj:`bool`, optional): Whether callback_data should be saved by this
|
|
|
|
persistence class. Default is :obj:`False`.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
2020-12-30 15:59:50 +01:00
|
|
|
|
|
|
|
Attributes:
|
|
|
|
store_user_data (:obj:`bool`): Optional, Whether user_data should be saved by this
|
|
|
|
persistence class.
|
|
|
|
store_chat_data (:obj:`bool`): Optional. Whether chat_data should be saved by this
|
|
|
|
persistence class.
|
|
|
|
store_bot_data (:obj:`bool`): Optional. Whether bot_data should be saved by this
|
|
|
|
persistence class.
|
2021-06-06 11:48:48 +02:00
|
|
|
store_callback_data (:obj:`bool`): Optional. Whether callback_data should be saved by this
|
|
|
|
persistence class.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
2018-09-20 22:50:40 +02:00
|
|
|
"""
|
|
|
|
|
2021-05-29 16:18:16 +02:00
|
|
|
# Apparently Py 3.7 and below have '__dict__' in ABC
|
|
|
|
if py_ver < (3, 7):
|
2021-06-06 11:48:48 +02:00
|
|
|
__slots__ = (
|
|
|
|
'store_user_data',
|
|
|
|
'store_chat_data',
|
|
|
|
'store_bot_data',
|
|
|
|
'store_callback_data',
|
|
|
|
'bot',
|
|
|
|
)
|
2021-05-29 16:18:16 +02:00
|
|
|
else:
|
|
|
|
__slots__ = (
|
|
|
|
'store_user_data', # type: ignore[assignment]
|
|
|
|
'store_chat_data',
|
|
|
|
'store_bot_data',
|
2021-06-06 11:48:48 +02:00
|
|
|
'store_callback_data',
|
2021-05-29 16:18:16 +02:00
|
|
|
'bot',
|
|
|
|
'__dict__',
|
|
|
|
)
|
|
|
|
|
2021-01-30 11:38:54 +01:00
|
|
|
def __new__(
|
|
|
|
cls, *args: object, **kwargs: object # pylint: disable=W0613
|
|
|
|
) -> 'BasePersistence':
|
2021-06-06 10:37:53 +02:00
|
|
|
"""This overrides the get_* and update_* methods to use insert/replace_bot.
|
|
|
|
That has the side effect that we always pass deepcopied data to those methods, so in
|
|
|
|
Pickle/DictPersistence we don't have to worry about copying the data again.
|
2021-06-06 11:48:48 +02:00
|
|
|
|
|
|
|
Note: This doesn't hold for second tuple-entry of callback_data. That's a Dict[str, str],
|
|
|
|
so no bots to replace anyway.
|
2021-06-06 10:37:53 +02:00
|
|
|
"""
|
2020-07-13 21:52:26 +02:00
|
|
|
instance = super().__new__(cls)
|
|
|
|
get_user_data = instance.get_user_data
|
|
|
|
get_chat_data = instance.get_chat_data
|
|
|
|
get_bot_data = instance.get_bot_data
|
2021-06-06 11:48:48 +02:00
|
|
|
get_callback_data = instance.get_callback_data
|
2020-07-13 21:52:26 +02:00
|
|
|
update_user_data = instance.update_user_data
|
|
|
|
update_chat_data = instance.update_chat_data
|
|
|
|
update_bot_data = instance.update_bot_data
|
2021-06-06 11:48:48 +02:00
|
|
|
update_callback_data = instance.update_callback_data
|
2020-07-13 21:52:26 +02:00
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
def get_user_data_insert_bot() -> DefaultDict[int, UD]:
|
2020-07-13 21:52:26 +02:00
|
|
|
return instance.insert_bot(get_user_data())
|
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
def get_chat_data_insert_bot() -> DefaultDict[int, CD]:
|
2020-07-13 21:52:26 +02:00
|
|
|
return instance.insert_bot(get_chat_data())
|
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
def get_bot_data_insert_bot() -> BD:
|
2020-07-13 21:52:26 +02:00
|
|
|
return instance.insert_bot(get_bot_data())
|
|
|
|
|
2021-06-06 11:48:48 +02:00
|
|
|
def get_callback_data_insert_bot() -> Optional[CDCData]:
|
|
|
|
cdc_data = get_callback_data()
|
|
|
|
if cdc_data is None:
|
|
|
|
return None
|
|
|
|
return instance.insert_bot(cdc_data[0]), cdc_data[1]
|
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
def update_user_data_replace_bot(user_id: int, data: UD) -> None:
|
2020-07-13 21:52:26 +02:00
|
|
|
return update_user_data(user_id, instance.replace_bot(data))
|
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
def update_chat_data_replace_bot(chat_id: int, data: CD) -> None:
|
2020-07-13 21:52:26 +02:00
|
|
|
return update_chat_data(chat_id, instance.replace_bot(data))
|
|
|
|
|
2021-06-06 10:37:53 +02:00
|
|
|
def update_bot_data_replace_bot(data: BD) -> None:
|
2020-07-13 21:52:26 +02:00
|
|
|
return update_bot_data(instance.replace_bot(data))
|
|
|
|
|
2021-06-06 11:48:48 +02:00
|
|
|
def update_callback_data_replace_bot(data: CDCData) -> None:
|
|
|
|
obj_data, queue = data
|
|
|
|
return update_callback_data((instance.replace_bot(obj_data), queue))
|
|
|
|
|
2021-05-29 16:18:16 +02:00
|
|
|
# We want to ignore TGDeprecation warnings so we use obj.__setattr__. Adds to __dict__
|
|
|
|
object.__setattr__(instance, 'get_user_data', get_user_data_insert_bot)
|
|
|
|
object.__setattr__(instance, 'get_chat_data', get_chat_data_insert_bot)
|
|
|
|
object.__setattr__(instance, 'get_bot_data', get_bot_data_insert_bot)
|
2021-06-06 11:48:48 +02:00
|
|
|
object.__setattr__(instance, 'get_callback_data', get_callback_data_insert_bot)
|
2021-05-29 16:18:16 +02:00
|
|
|
object.__setattr__(instance, 'update_user_data', update_user_data_replace_bot)
|
|
|
|
object.__setattr__(instance, 'update_chat_data', update_chat_data_replace_bot)
|
|
|
|
object.__setattr__(instance, 'update_bot_data', update_bot_data_replace_bot)
|
2021-06-06 11:48:48 +02:00
|
|
|
object.__setattr__(instance, 'update_callback_data', update_callback_data_replace_bot)
|
2020-07-13 21:52:26 +02:00
|
|
|
return instance
|
|
|
|
|
2020-10-09 17:22:07 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
store_user_data: bool = True,
|
|
|
|
store_chat_data: bool = True,
|
|
|
|
store_bot_data: bool = True,
|
2021-06-06 11:48:48 +02:00
|
|
|
store_callback_data: bool = False,
|
2020-10-09 17:22:07 +02:00
|
|
|
):
|
2018-09-20 22:50:40 +02:00
|
|
|
self.store_user_data = store_user_data
|
|
|
|
self.store_chat_data = store_chat_data
|
2020-02-02 22:20:31 +01:00
|
|
|
self.store_bot_data = store_bot_data
|
2021-06-06 11:48:48 +02:00
|
|
|
self.store_callback_data = store_callback_data
|
2020-10-06 19:28:40 +02:00
|
|
|
self.bot: Bot = None # type: ignore[assignment]
|
2021-05-29 16:18:16 +02:00
|
|
|
|
|
|
|
def __setattr__(self, key: str, value: object) -> None:
|
|
|
|
# Allow user defined subclasses to have custom attributes.
|
|
|
|
if issubclass(self.__class__, BasePersistence) and self.__class__.__name__ not in {
|
|
|
|
'DictPersistence',
|
|
|
|
'PicklePersistence',
|
|
|
|
}:
|
|
|
|
object.__setattr__(self, key, value)
|
|
|
|
return
|
|
|
|
set_new_attribute_deprecated(self, key, value)
|
2020-07-13 21:52:26 +02:00
|
|
|
|
2020-10-06 19:28:40 +02:00
|
|
|
def set_bot(self, bot: Bot) -> None:
|
2020-07-13 21:52:26 +02:00
|
|
|
"""Set the Bot to be used by this persistence instance.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
bot (:class:`telegram.Bot`): The bot.
|
|
|
|
"""
|
2021-06-06 11:48:48 +02:00
|
|
|
if self.store_callback_data and not isinstance(bot, telegram.ext.extbot.ExtBot):
|
|
|
|
raise TypeError('store_callback_data can only be used with telegram.ext.ExtBot.')
|
|
|
|
|
2020-07-13 21:52:26 +02:00
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
@classmethod
|
2020-11-22 11:08:46 +01:00
|
|
|
def replace_bot(cls, obj: object) -> object:
|
2020-07-13 21:52:26 +02:00
|
|
|
"""
|
|
|
|
Replaces all instances of :class:`telegram.Bot` that occur within the passed object with
|
|
|
|
:attr:`REPLACED_BOT`. Currently, this handles objects of type ``list``, ``tuple``, ``set``,
|
|
|
|
``frozenset``, ``dict``, ``defaultdict`` and objects that have a ``__dict__`` or
|
2021-06-06 12:16:23 +02:00
|
|
|
``__slots__`` attribute, excluding classes and objects that can't be copied with
|
2021-06-20 22:14:05 +02:00
|
|
|
``copy.copy``. If the parsing of an object fails, the object will be returned unchanged and
|
|
|
|
the error will be logged.
|
2020-07-13 21:52:26 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
obj (:obj:`object`): The object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`obj`: Copy of the object with Bot instances replaced.
|
|
|
|
"""
|
2020-11-22 11:08:46 +01:00
|
|
|
return cls._replace_bot(obj, {})
|
|
|
|
|
|
|
|
@classmethod
|
2021-01-30 11:38:54 +01:00
|
|
|
def _replace_bot(cls, obj: object, memo: Dict[int, object]) -> object: # pylint: disable=R0911
|
2020-11-22 11:08:46 +01:00
|
|
|
obj_id = id(obj)
|
|
|
|
if obj_id in memo:
|
|
|
|
return memo[obj_id]
|
|
|
|
|
2020-07-13 21:52:26 +02:00
|
|
|
if isinstance(obj, Bot):
|
2020-11-22 11:08:46 +01:00
|
|
|
memo[obj_id] = cls.REPLACED_BOT
|
2020-07-13 21:52:26 +02:00
|
|
|
return cls.REPLACED_BOT
|
2020-11-22 11:08:46 +01:00
|
|
|
if isinstance(obj, (list, set)):
|
|
|
|
# We copy the iterable here for thread safety, i.e. make sure the object we iterate
|
|
|
|
# over doesn't change its length during the iteration
|
|
|
|
temp_iterable = obj.copy()
|
|
|
|
new_iterable = obj.__class__(cls._replace_bot(item, memo) for item in temp_iterable)
|
|
|
|
memo[obj_id] = new_iterable
|
|
|
|
return new_iterable
|
|
|
|
if isinstance(obj, (tuple, frozenset)):
|
|
|
|
# tuples and frozensets are immutable so we don't need to worry about thread safety
|
|
|
|
new_immutable = obj.__class__(cls._replace_bot(item, memo) for item in obj)
|
|
|
|
memo[obj_id] = new_immutable
|
|
|
|
return new_immutable
|
2021-05-16 20:02:35 +02:00
|
|
|
if isinstance(obj, type):
|
|
|
|
# classes usually do have a __dict__, but it's not writable
|
|
|
|
warnings.warn(
|
|
|
|
'BasePersistence.replace_bot does not handle classes. See '
|
|
|
|
'the docs of BasePersistence.replace_bot for more information.',
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
|
|
|
return obj
|
2020-07-13 21:52:26 +02:00
|
|
|
|
2020-11-14 03:08:18 +01:00
|
|
|
try:
|
|
|
|
new_obj = copy(obj)
|
2020-11-22 11:08:46 +01:00
|
|
|
memo[obj_id] = new_obj
|
2020-11-14 03:08:18 +01:00
|
|
|
except Exception:
|
|
|
|
warnings.warn(
|
|
|
|
'BasePersistence.replace_bot does not handle objects that can not be copied. See '
|
|
|
|
'the docs of BasePersistence.replace_bot for more information.',
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
2020-11-22 11:08:46 +01:00
|
|
|
memo[obj_id] = obj
|
2020-11-14 03:08:18 +01:00
|
|
|
return obj
|
|
|
|
|
2020-11-22 11:08:46 +01:00
|
|
|
if isinstance(obj, dict):
|
|
|
|
# We handle dicts via copy(obj) so we don't have to make a
|
|
|
|
# difference between dict and defaultdict
|
2020-10-06 19:28:40 +02:00
|
|
|
new_obj = cast(dict, new_obj)
|
2020-11-22 11:08:46 +01:00
|
|
|
# We can't iterate over obj.items() due to thread safety, i.e. the dicts length may
|
|
|
|
# change during the iteration
|
|
|
|
temp_dict = new_obj.copy()
|
2020-07-13 21:52:26 +02:00
|
|
|
new_obj.clear()
|
2020-11-22 11:08:46 +01:00
|
|
|
for k, val in temp_dict.items():
|
|
|
|
new_obj[cls._replace_bot(k, memo)] = cls._replace_bot(val, memo)
|
|
|
|
memo[obj_id] = new_obj
|
2020-07-13 21:52:26 +02:00
|
|
|
return new_obj
|
2021-06-13 15:07:40 +02:00
|
|
|
# if '__dict__' in obj.__slots__, we already cover this here, that's why the
|
|
|
|
# __dict__ case comes below
|
2021-06-20 22:14:05 +02:00
|
|
|
try:
|
|
|
|
if hasattr(obj, '__slots__'):
|
|
|
|
for attr_name in new_obj.__slots__:
|
|
|
|
setattr(
|
|
|
|
new_obj,
|
|
|
|
attr_name,
|
|
|
|
cls._replace_bot(
|
|
|
|
cls._replace_bot(getattr(new_obj, attr_name), memo), memo
|
|
|
|
),
|
|
|
|
)
|
|
|
|
memo[obj_id] = new_obj
|
|
|
|
return new_obj
|
|
|
|
if hasattr(obj, '__dict__'):
|
|
|
|
for attr_name, attr in new_obj.__dict__.items():
|
|
|
|
setattr(new_obj, attr_name, cls._replace_bot(attr, memo))
|
|
|
|
memo[obj_id] = new_obj
|
|
|
|
return new_obj
|
|
|
|
except Exception as exception:
|
|
|
|
warnings.warn(
|
|
|
|
f'Parsing of an object failed with the following exception: {exception}. '
|
|
|
|
f'See the docs of BasePersistence.replace_bot for more information.',
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
|
|
|
memo[obj_id] = obj
|
|
|
|
return obj
|
2020-07-13 21:52:26 +02:00
|
|
|
|
|
|
|
return obj
|
|
|
|
|
2020-11-22 11:08:46 +01:00
|
|
|
def insert_bot(self, obj: object) -> object:
|
2020-07-13 21:52:26 +02:00
|
|
|
"""
|
|
|
|
Replaces all instances of :attr:`REPLACED_BOT` that occur within the passed object with
|
|
|
|
:attr:`bot`. Currently, this handles objects of type ``list``, ``tuple``, ``set``,
|
|
|
|
``frozenset``, ``dict``, ``defaultdict`` and objects that have a ``__dict__`` or
|
2021-06-06 12:16:23 +02:00
|
|
|
``__slots__`` attribute, excluding classes and objects that can't be copied with
|
2021-06-20 22:14:05 +02:00
|
|
|
``copy.copy``. If the parsing of an object fails, the object will be returned unchanged and
|
|
|
|
the error will be logged.
|
2020-07-13 21:52:26 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
obj (:obj:`object`): The object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`obj`: Copy of the object with Bot instances inserted.
|
|
|
|
"""
|
2020-11-22 11:08:46 +01:00
|
|
|
return self._insert_bot(obj, {})
|
|
|
|
|
2021-01-30 11:38:54 +01:00
|
|
|
def _insert_bot(self, obj: object, memo: Dict[int, object]) -> object: # pylint: disable=R0911
|
2020-11-22 11:08:46 +01:00
|
|
|
obj_id = id(obj)
|
|
|
|
if obj_id in memo:
|
|
|
|
return memo[obj_id]
|
|
|
|
|
2020-07-13 21:52:26 +02:00
|
|
|
if isinstance(obj, Bot):
|
2020-11-22 11:08:46 +01:00
|
|
|
memo[obj_id] = self.bot
|
2020-07-13 21:52:26 +02:00
|
|
|
return self.bot
|
2020-11-14 03:08:18 +01:00
|
|
|
if isinstance(obj, str) and obj == self.REPLACED_BOT:
|
2020-11-22 11:08:46 +01:00
|
|
|
memo[obj_id] = self.bot
|
2020-07-13 21:52:26 +02:00
|
|
|
return self.bot
|
2020-11-22 11:08:46 +01:00
|
|
|
if isinstance(obj, (list, set)):
|
|
|
|
# We copy the iterable here for thread safety, i.e. make sure the object we iterate
|
|
|
|
# over doesn't change its length during the iteration
|
|
|
|
temp_iterable = obj.copy()
|
|
|
|
new_iterable = obj.__class__(self._insert_bot(item, memo) for item in temp_iterable)
|
|
|
|
memo[obj_id] = new_iterable
|
|
|
|
return new_iterable
|
|
|
|
if isinstance(obj, (tuple, frozenset)):
|
|
|
|
# tuples and frozensets are immutable so we don't need to worry about thread safety
|
|
|
|
new_immutable = obj.__class__(self._insert_bot(item, memo) for item in obj)
|
|
|
|
memo[obj_id] = new_immutable
|
|
|
|
return new_immutable
|
2021-05-16 20:02:35 +02:00
|
|
|
if isinstance(obj, type):
|
|
|
|
# classes usually do have a __dict__, but it's not writable
|
|
|
|
warnings.warn(
|
|
|
|
'BasePersistence.insert_bot does not handle classes. See '
|
|
|
|
'the docs of BasePersistence.insert_bot for more information.',
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
|
|
|
return obj
|
2020-07-13 21:52:26 +02:00
|
|
|
|
2020-11-14 03:08:18 +01:00
|
|
|
try:
|
|
|
|
new_obj = copy(obj)
|
|
|
|
except Exception:
|
|
|
|
warnings.warn(
|
|
|
|
'BasePersistence.insert_bot does not handle objects that can not be copied. See '
|
|
|
|
'the docs of BasePersistence.insert_bot for more information.',
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
2020-11-22 11:08:46 +01:00
|
|
|
memo[obj_id] = obj
|
2020-11-14 03:08:18 +01:00
|
|
|
return obj
|
|
|
|
|
2020-11-22 11:08:46 +01:00
|
|
|
if isinstance(obj, dict):
|
|
|
|
# We handle dicts via copy(obj) so we don't have to make a
|
|
|
|
# difference between dict and defaultdict
|
2020-10-06 19:28:40 +02:00
|
|
|
new_obj = cast(dict, new_obj)
|
2020-11-22 11:08:46 +01:00
|
|
|
# We can't iterate over obj.items() due to thread safety, i.e. the dicts length may
|
|
|
|
# change during the iteration
|
|
|
|
temp_dict = new_obj.copy()
|
2020-07-13 21:52:26 +02:00
|
|
|
new_obj.clear()
|
2020-11-22 11:08:46 +01:00
|
|
|
for k, val in temp_dict.items():
|
|
|
|
new_obj[self._insert_bot(k, memo)] = self._insert_bot(val, memo)
|
|
|
|
memo[obj_id] = new_obj
|
2020-07-13 21:52:26 +02:00
|
|
|
return new_obj
|
2021-06-13 15:07:40 +02:00
|
|
|
# if '__dict__' in obj.__slots__, we already cover this here, that's why the
|
|
|
|
# __dict__ case comes below
|
2021-06-20 22:14:05 +02:00
|
|
|
try:
|
|
|
|
if hasattr(obj, '__slots__'):
|
|
|
|
for attr_name in obj.__slots__:
|
|
|
|
setattr(
|
|
|
|
new_obj,
|
|
|
|
attr_name,
|
|
|
|
self._insert_bot(
|
|
|
|
self._insert_bot(getattr(new_obj, attr_name), memo), memo
|
|
|
|
),
|
|
|
|
)
|
|
|
|
memo[obj_id] = new_obj
|
|
|
|
return new_obj
|
|
|
|
if hasattr(obj, '__dict__'):
|
|
|
|
for attr_name, attr in new_obj.__dict__.items():
|
|
|
|
setattr(new_obj, attr_name, self._insert_bot(attr, memo))
|
|
|
|
memo[obj_id] = new_obj
|
|
|
|
return new_obj
|
|
|
|
except Exception as exception:
|
|
|
|
warnings.warn(
|
|
|
|
f'Parsing of an object failed with the following exception: {exception}. '
|
|
|
|
f'See the docs of BasePersistence.insert_bot for more information.',
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
|
|
|
memo[obj_id] = obj
|
|
|
|
return obj
|
2020-11-14 03:08:18 +01:00
|
|
|
|
2020-07-13 21:52:26 +02:00
|
|
|
return obj
|
2018-09-20 22:50:40 +02:00
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2021-06-06 10:37:53 +02:00
|
|
|
def get_user_data(self) -> DefaultDict[int, UD]:
|
2021-02-19 19:07:48 +01:00
|
|
|
"""Will be called by :class:`telegram.ext.Dispatcher` upon creation with a
|
2020-12-17 09:29:17 +01:00
|
|
|
persistence object. It should return the ``user_data`` if stored, or an empty
|
2021-06-06 10:37:53 +02:00
|
|
|
:obj:`defaultdict(telegram.ext.utils.types.UD)` with integer keys.
|
2018-09-20 22:50:40 +02:00
|
|
|
|
|
|
|
Returns:
|
2021-06-06 10:37:53 +02:00
|
|
|
DefaultDict[:obj:`int`, :class:`telegram.ext.utils.types.UD`]: The restored user data.
|
2018-09-20 22:50:40 +02:00
|
|
|
"""
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2021-06-06 10:37:53 +02:00
|
|
|
def get_chat_data(self) -> DefaultDict[int, CD]:
|
2021-02-19 19:07:48 +01:00
|
|
|
"""Will be called by :class:`telegram.ext.Dispatcher` upon creation with a
|
2020-12-17 09:29:17 +01:00
|
|
|
persistence object. It should return the ``chat_data`` if stored, or an empty
|
2021-06-06 10:37:53 +02:00
|
|
|
:obj:`defaultdict(telegram.ext.utils.types.CD)` with integer keys.
|
2018-09-20 22:50:40 +02:00
|
|
|
|
|
|
|
Returns:
|
2021-06-06 10:37:53 +02:00
|
|
|
DefaultDict[:obj:`int`, :class:`telegram.ext.utils.types.CD`]: The restored chat data.
|
2018-09-20 22:50:40 +02:00
|
|
|
"""
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2021-06-06 10:37:53 +02:00
|
|
|
def get_bot_data(self) -> BD:
|
2021-02-19 19:07:48 +01:00
|
|
|
"""Will be called by :class:`telegram.ext.Dispatcher` upon creation with a
|
2020-12-17 09:29:17 +01:00
|
|
|
persistence object. It should return the ``bot_data`` if stored, or an empty
|
2021-06-06 10:37:53 +02:00
|
|
|
:class:`telegram.ext.utils.types.BD`.
|
2020-02-02 22:20:31 +01:00
|
|
|
|
|
|
|
Returns:
|
2021-06-06 10:37:53 +02:00
|
|
|
:class:`telegram.ext.utils.types.BD`: The restored bot data.
|
2020-02-02 22:20:31 +01:00
|
|
|
"""
|
|
|
|
|
2021-06-06 11:48:48 +02:00
|
|
|
def get_callback_data(self) -> Optional[CDCData]:
|
|
|
|
"""Will be called by :class:`telegram.ext.Dispatcher` upon creation with a
|
|
|
|
persistence object. If callback data was stored, it should be returned.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
|
|
|
|
|
|
|
Returns:
|
2021-07-01 17:34:23 +02:00
|
|
|
Optional[:class:`telegram.ext.utils.types.CDCData`]: The restored meta data or
|
|
|
|
:obj:`None`, if no data was stored.
|
2021-06-06 11:48:48 +02:00
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2020-10-06 19:28:40 +02:00
|
|
|
def get_conversations(self, name: str) -> ConversationDict:
|
2021-02-19 19:07:48 +01:00
|
|
|
"""Will be called by :class:`telegram.ext.Dispatcher` when a
|
2018-09-20 22:50:40 +02:00
|
|
|
:class:`telegram.ext.ConversationHandler` is added if
|
Documentation Improvements (#2008)
* Minor doc updates, following official API docs
* Fix spelling in Defaults docstrings
* Clarify Changelog of v12.7 about aware dates
* Fix typo in CHANGES.rst (#2024)
* Fix PicklePersistence.flush() with only bot_data (#2017)
* Update pylint in pre-commit to fix CI (#2018)
* Add Filters.via_bot (#2009)
* feat: via_bot filter
also fixing a small mistake in the empty parameter of the user filter and improve docs slightly
* fix: forgot to set via_bot to None
* fix: redoing subclassing to copy paste solution
* Cosmetic changes
Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
* Update CHANGES.rst
Fixed Typo
Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
* Update downloads badge, add info on IRC Channel to Getting Help section
* Remove RegexHandler from ConversationHandlers Docs (#1973)
Replaced RegexHandler with MessageHandler, since the former is deprecated
* Fix Filters.via_bot docstrings
* Add notes on Markdown v1 being legacy mode
* Fixed typo in the Regex doc.. (#2036)
* Typo: Spelling
* Minor cleanup from #2043
* Document CommandHandler ignoring channel posts
* Doc fixes for a few telegram.ext classes
* Doc fixes for most `telegram` classes.
* pep-8
forgot the hard wrap is at 99 chars, not 100!
fixed a few spelling mistakes too.
* Address review and made rendering of booleans consistent
True, False, None are now rendered with ``bool`` wherever they weren't in telegram and telegram.ext classes.
* Few doc fixes for inline* classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram/files classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram.Game
Mostly just added hyperlinks. And fixed message length doc.
As usual, docs were cross-checked with official tg api docs.
* Very minor doc fix for passportfile.py and passportelementerrors.py
Didn't bother changing too much since this seems to be a custom implementation.
* Doc fixes for telegram.payments
As usual, cross-checked with official bot api docs.
* Address review 2
Few tiny other fixes too.
* Changed from ``True/False/None`` to :obj:`True/False/None` project-wide.
Few tiny other doc fixes too.
Co-authored-by: Robert Geislinger <mitachundkrach@gmail.com>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
Co-authored-by: GauthamramRavichandran <30320759+GauthamramRavichandran@users.noreply.github.com>
Co-authored-by: Mahesh19 <maheshvagicherla99438@gmail.com>
Co-authored-by: hoppingturtles <ilovebhagwan@gmail.com>
2020-08-24 19:35:57 +02:00
|
|
|
:attr:`telegram.ext.ConversationHandler.persistent` is :obj:`True`.
|
|
|
|
It should return the conversations for the handler with `name` or an empty :obj:`dict`
|
2018-09-20 22:50:40 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
name (:obj:`str`): The handlers name.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`dict`: The restored conversations for the handler.
|
|
|
|
"""
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2020-10-09 17:22:07 +02:00
|
|
|
def update_conversation(
|
|
|
|
self, name: str, key: Tuple[int, ...], new_state: Optional[object]
|
|
|
|
) -> None:
|
2021-07-01 17:34:23 +02:00
|
|
|
"""Will be called when a :class:`telegram.ext.ConversationHandler` changes states.
|
|
|
|
This allows the storage of the new state in the persistence.
|
2018-09-20 22:50:40 +02:00
|
|
|
|
|
|
|
Args:
|
Documentation Improvements (#2008)
* Minor doc updates, following official API docs
* Fix spelling in Defaults docstrings
* Clarify Changelog of v12.7 about aware dates
* Fix typo in CHANGES.rst (#2024)
* Fix PicklePersistence.flush() with only bot_data (#2017)
* Update pylint in pre-commit to fix CI (#2018)
* Add Filters.via_bot (#2009)
* feat: via_bot filter
also fixing a small mistake in the empty parameter of the user filter and improve docs slightly
* fix: forgot to set via_bot to None
* fix: redoing subclassing to copy paste solution
* Cosmetic changes
Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
* Update CHANGES.rst
Fixed Typo
Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
* Update downloads badge, add info on IRC Channel to Getting Help section
* Remove RegexHandler from ConversationHandlers Docs (#1973)
Replaced RegexHandler with MessageHandler, since the former is deprecated
* Fix Filters.via_bot docstrings
* Add notes on Markdown v1 being legacy mode
* Fixed typo in the Regex doc.. (#2036)
* Typo: Spelling
* Minor cleanup from #2043
* Document CommandHandler ignoring channel posts
* Doc fixes for a few telegram.ext classes
* Doc fixes for most `telegram` classes.
* pep-8
forgot the hard wrap is at 99 chars, not 100!
fixed a few spelling mistakes too.
* Address review and made rendering of booleans consistent
True, False, None are now rendered with ``bool`` wherever they weren't in telegram and telegram.ext classes.
* Few doc fixes for inline* classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram/files classes
As usual, docs were cross-checked with official tg api docs.
* Doc fixes for telegram.Game
Mostly just added hyperlinks. And fixed message length doc.
As usual, docs were cross-checked with official tg api docs.
* Very minor doc fix for passportfile.py and passportelementerrors.py
Didn't bother changing too much since this seems to be a custom implementation.
* Doc fixes for telegram.payments
As usual, cross-checked with official bot api docs.
* Address review 2
Few tiny other fixes too.
* Changed from ``True/False/None`` to :obj:`True/False/None` project-wide.
Few tiny other doc fixes too.
Co-authored-by: Robert Geislinger <mitachundkrach@gmail.com>
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
Co-authored-by: GauthamramRavichandran <30320759+GauthamramRavichandran@users.noreply.github.com>
Co-authored-by: Mahesh19 <maheshvagicherla99438@gmail.com>
Co-authored-by: hoppingturtles <ilovebhagwan@gmail.com>
2020-08-24 19:35:57 +02:00
|
|
|
name (:obj:`str`): The handler's name.
|
2018-09-20 22:50:40 +02:00
|
|
|
key (:obj:`tuple`): The key the state is changed for.
|
|
|
|
new_state (:obj:`tuple` | :obj:`any`): The new state for the given key.
|
|
|
|
"""
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2021-06-06 10:37:53 +02:00
|
|
|
def update_user_data(self, user_id: int, data: UD) -> None:
|
2018-09-20 22:50:40 +02:00
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
|
|
|
|
handled an update.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
user_id (:obj:`int`): The user the data might have been changed for.
|
2021-06-06 10:37:53 +02:00
|
|
|
data (:class:`telegram.ext.utils.types.UD`): The
|
2021-07-01 17:34:23 +02:00
|
|
|
:attr:`telegram.ext.Dispatcher.user_data` ``[user_id]``.
|
2018-09-20 22:50:40 +02:00
|
|
|
"""
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2021-06-06 10:37:53 +02:00
|
|
|
def update_chat_data(self, chat_id: int, data: CD) -> None:
|
2018-09-20 22:50:40 +02:00
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
|
|
|
|
handled an update.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
chat_id (:obj:`int`): The chat the data might have been changed for.
|
2021-06-06 10:37:53 +02:00
|
|
|
data (:class:`telegram.ext.utils.types.CD`): The
|
2021-07-01 17:34:23 +02:00
|
|
|
:attr:`telegram.ext.Dispatcher.chat_data` ``[chat_id]``.
|
2020-02-02 22:20:31 +01:00
|
|
|
"""
|
|
|
|
|
2020-05-01 20:27:34 +02:00
|
|
|
@abstractmethod
|
2021-06-06 10:37:53 +02:00
|
|
|
def update_bot_data(self, data: BD) -> None:
|
2020-02-02 22:20:31 +01:00
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
|
|
|
|
handled an update.
|
|
|
|
|
|
|
|
Args:
|
2021-06-06 10:37:53 +02:00
|
|
|
data (:class:`telegram.ext.utils.types.BD`): The
|
2021-07-01 17:34:23 +02:00
|
|
|
:attr:`telegram.ext.Dispatcher.bot_data`.
|
2021-06-06 10:37:53 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def refresh_user_data(self, user_id: int, user_data: UD) -> None:
|
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` before passing the
|
|
|
|
:attr:`user_data` to a callback. Can be used to update data stored in :attr:`user_data`
|
|
|
|
from an external source.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
|
|
|
|
|
|
|
Args:
|
|
|
|
user_id (:obj:`int`): The user ID this :attr:`user_data` is associated with.
|
|
|
|
user_data (:class:`telegram.ext.utils.types.UD`): The ``user_data`` of a single user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def refresh_chat_data(self, chat_id: int, chat_data: CD) -> None:
|
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` before passing the
|
|
|
|
:attr:`chat_data` to a callback. Can be used to update data stored in :attr:`chat_data`
|
|
|
|
from an external source.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
|
|
|
|
|
|
|
Args:
|
|
|
|
chat_id (:obj:`int`): The chat ID this :attr:`chat_data` is associated with.
|
|
|
|
chat_data (:class:`telegram.ext.utils.types.CD`): The ``chat_data`` of a single chat.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def refresh_bot_data(self, bot_data: BD) -> None:
|
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` before passing the
|
|
|
|
:attr:`bot_data` to a callback. Can be used to update data stored in :attr:`bot_data`
|
|
|
|
from an external source.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
|
|
|
|
|
|
|
Args:
|
|
|
|
bot_data (:class:`telegram.ext.utils.types.BD`): The ``bot_data``.
|
2018-09-20 22:50:40 +02:00
|
|
|
"""
|
|
|
|
|
2021-06-06 11:48:48 +02:00
|
|
|
def update_callback_data(self, data: CDCData) -> None:
|
|
|
|
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
|
|
|
|
handled an update.
|
|
|
|
|
|
|
|
.. versionadded:: 13.6
|
|
|
|
|
|
|
|
Args:
|
2021-07-01 17:34:23 +02:00
|
|
|
data (:class:`telegram.ext.utils.types.CDCData`): The relevant data to restore
|
|
|
|
:class:`telegram.ext.CallbackDataCache`.
|
2021-06-06 11:48:48 +02:00
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-10-06 19:28:40 +02:00
|
|
|
def flush(self) -> None:
|
2018-09-20 22:50:40 +02:00
|
|
|
"""Will be called by :class:`telegram.ext.Updater` upon receiving a stop signal. Gives the
|
2020-12-17 09:29:17 +01:00
|
|
|
persistence a chance to finish up saving or close a database connection gracefully.
|
2018-09-20 22:50:40 +02:00
|
|
|
"""
|
2020-07-13 21:52:26 +02:00
|
|
|
|
2020-10-15 18:50:47 +02:00
|
|
|
REPLACED_BOT: ClassVar[str] = 'bot_instance_replaced_by_ptb_persistence'
|
2020-07-13 21:52:26 +02:00
|
|
|
""":obj:`str`: Placeholder for :class:`telegram.Bot` instances replaced in saved data."""
|