telegram.ext.PicklePersistence¶
-
class
telegram.ext.PicklePersistence(filename, store_user_data=True, store_chat_data=True, singe_file=True, on_flush=False)¶ Bases:
telegram.ext.basepersistence.BasePersistenceUsing python’s builtin pickle for making you bot persistent.
-
filename¶ str– The filename for storing the pickle files. Whensingle_fileis false this will be used as a prefix.
-
store_user_data¶ bool– Optional. Whether user_data should be saved by this persistence class.
-
store_chat_data¶ bool– Optional. Whether user_data should be saved by this persistence class.
-
single_file¶ bool– Optional. WhenFalsewill store 3 sperate files of filename_user_data, filename_chat_data and filename_conversations. Default isTrue.
-
on_flush¶ bool– Optional. WhenTruewill only save to file whenflush()is called and keep data in memory until that happens. When False will store data on any transaction. Default isFalse.
Parameters: - filename (
str) – The filename for storing the pickle files. Whensingle_fileis false this will be used as a prefix. - store_user_data (
bool, optional) – Whether user_data should be saved by this persistence class. Default isTrue. - store_chat_data (
bool, optional) – Whether user_data should be saved by this persistence class. Default isTrue. - single_file (
bool, optional) – WhenFalsewill store 3 sperate files of filename_user_data, filename_chat_data and filename_conversations. Default isTrue. - on_flush (
bool, optional) – WhenTruewill only save to file whenflush()is called and keep data in memory until that happens. When False will store data on any transaction. Default isFalse.
-
flush()¶ If
on_flushis set toTrue. Will save all data in memory to pickle file(s). If it’sFalsewill just pass.
-
get_chat_data()¶ Returns the chat_data from the pickle file if it exsists or an empty defaultdict.
Returns: The restored chat data. Return type: defaultdict
-
get_conversations(name)¶ Returns the conversations from the pickle file if it exsists or an empty defaultdict.
Parameters: name ( str) – The handlers name.Returns: The restored conversations for the handler. Return type: dict
-
get_user_data()¶ Returns the user_data from the pickle file if it exsists or an empty defaultdict.
Returns: The restored user data. Return type: defaultdict
-
update_chat_data(chat_id, data)¶ Will update the chat_data (if changed) and depending on
on_flushsave the pickle file.Parameters: - chat_id (
int) – The chat the data might have been changed for. - data (
dict) – The :attr:`telegram.ext.dispatcher.chat_data`[chat_id].
- chat_id (
-