-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[FEATURE] #2148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi. A few thoughts:
I think 1.+2. are a good way to achieve what you want for now. |
|
You can do whatever you want before calling |
While exiting we can just add that custom class to updater.dispatcher.bot_data in one step only. No need to update that updater.dispatcher.bot_data class copy every time my object mutate. That will be helpful. Anyways, I will try using your solution and provide feedback. |
Python passes objects by reference:
so no need to update the custom object before exit. its current state will be saved. |
Thanks for help! |
Is your feature request related to a problem? Please describe.
I made a global class which extends the functionality of sending message by saving the chat id and message id of message sent by bot. So object of this class will have the list of all the messages sent by bot and also have methods to delete duplicate bot messages. I want to add this object to pickle persistence of bot but there is no way to it. Pickle Persistence class of PTB library only give options to add
chat_data
,bot_data
anduser_data
to persistence; No option to add user defined objects and variables to the persistence.Describe the solution you'd like
I think it would be nice if you would add a feature to pass a dictionary as a parameter to the PicklePersistence() method which will add the global variables mentioned in the dictionary to the persistence, and after restarting bot, those variables will be reloaded.
Describe alternatives you've considered
I considered saving those objects to the
bot_data
of the Callback context while exiting bot and restoring thatbot_data
copy at every restart of bot; asbot_data
get persisted with inbuilt persistence. But that didn't work, as callback context is only accessible inside any handler not in main. So I need to call adump_handler
once before exiting and call aload_handler
after the restart. So there should be predefined functions through which user can call any function just after bot start and just before bot stop.Also
bot_data
should be available in whole main function or there should be any other*_data
free from callback context to which any object can be saved inside main function so it get persisted with default persistence.The text was updated successfully, but these errors were encountered: