@@ -524,41 +524,65 @@ def default_command(message):
524524 :param content_types: This commands' supported content types. Must be a list. Defaults to ['text'].
525525 """
526526
527- def decorator (fn ):
528- handler_dict = {'function' : fn }
529- filters = {'content_types' : content_types }
530- if regexp :
531- filters ['regexp' ] = regexp
532- if func :
533- filters ['lambda' ] = func
534- if commands :
535- filters ['commands' ] = commands
536- handler_dict ['filters' ] = filters
537- self .message_handlers .append (handler_dict )
538- return fn
527+ def decorator (handler ):
528+ self .add_message_handler (handler , commands , regexp , func , content_types )
529+ return handler
539530
540531 return decorator
541532
533+ def add_message_handler (self , handler , commands = None , regexp = None , func = None , content_types = None ):
534+ if content_types is None :
535+ content_types = ['text' ]
536+
537+ filters = {'content_types' : content_types }
538+ if regexp :
539+ filters ['regexp' ] = regexp
540+ if func :
541+ filters ['lambda' ] = func
542+ if commands :
543+ filters ['commands' ] = commands
544+
545+ handler_dict = {
546+ 'function' : handler ,
547+ 'filters' : filters
548+ }
549+
550+ self .message_handlers .append (handler_dict )
551+
542552 def inline_handler (self , func ):
543- def decorator (fn ):
544- handler_dict = {'function' : fn }
545- filters = {'lambda' : func }
546- handler_dict ['filters' ] = filters
547- self .inline_handlers .append (handler_dict )
548- return fn
553+ def decorator (handler ):
554+ self .add_inline_handler (handler , func )
555+ return handler
549556
550557 return decorator
551558
559+ def add_inline_handler (self , handler , func ):
560+ filters = {'lambda' : func }
561+
562+ handler_dict = {
563+ 'function' : handler ,
564+ 'filters' : filters
565+ }
566+
567+ self .inline_handlers .append (handler_dict )
568+
552569 def chosen_inline_handler (self , func ):
553- def decorator (fn ):
554- handler_dict = {'function' : fn }
555- filters = {'lambda' : func }
556- handler_dict ['filters' ] = filters
557- self .chosen_inline_handlers .append (handler_dict )
558- return fn
570+ def decorator (handler ):
571+ self .add_chosen_inline_handler (handler , func )
572+ return handler
559573
560574 return decorator
561575
576+ def add_chosen_inline_handler (self , handler , func ):
577+ filters = {'lambda' : func }
578+
579+ handler_dict = {
580+ 'function' : handler ,
581+ 'filters' : filters
582+ }
583+
584+ self .chosen_inline_handlers .append (handler_dict )
585+
562586 @staticmethod
563587 def _test_message_handler (message_handler , message ):
564588 for filter , filter_value in six .iteritems (message_handler ['filters' ]):
0 commit comments