3535from telegram .utils .promise import Promise
3636from telegram .ext import BasePersistence
3737
38-
3938logging .getLogger (__name__ ).addHandler (logging .NullHandler ())
4039DEFAULT_GROUP = 0
4140
@@ -50,6 +49,7 @@ def run_async(func):
5049 Note: Use this decorator to run handlers asynchronously.
5150
5251 """
52+
5353 @wraps (func )
5454 def async_func (* args , ** kwargs ):
5555 return Dispatcher .get_instance ().run_async (func , * args , ** kwargs )
@@ -90,7 +90,8 @@ class Dispatcher(object):
9090 __singleton = None
9191 logger = logging .getLogger (__name__ )
9292
93- def __init__ (self , bot , update_queue , workers = 4 , exception_event = None , job_queue = None , persistence = None ):
93+ def __init__ (self , bot , update_queue , workers = 4 , exception_event = None , job_queue = None ,
94+ persistence = None ):
9495 self .bot = bot
9596 self .update_queue = update_queue
9697 self .workers = workers
@@ -298,6 +299,11 @@ def process_update(self, update):
298299 try :
299300 for handler in (x for x in self .handlers [group ] if x .check_update (update )):
300301 handler .handle_update (update , self )
302+ if self .persistence :
303+ if self .persistence .store_chat_data :
304+ self .persistence .update_chat_data (self .chat_data )
305+ if self .persistence .store_user_data :
306+ self .persistence .update_user_data (self .user_data )
301307 break
302308
303309 # Stop processing with any other handler.
@@ -354,8 +360,11 @@ def add_handler(self, handler, group=DEFAULT_GROUP):
354360 raise TypeError ('group is not int' )
355361 if isinstance (handler , ConversationHandler ) and handler .persistent :
356362 if not self .persistence :
357- raise ValueError ("Conversationhandler {} can not be persistent if logger has no persistence" , handler .name )
363+ raise ValueError (
364+ "Conversationhandler {} can not be persistent if logger has no persistence" ,
365+ handler .name )
358366 handler .conversations = self .persistence .get_conversations (handler .name )
367+ handler .persistence = self .persistence
359368
360369 if group not in self .handlers :
361370 self .handlers [group ] = list ()
0 commit comments