@@ -95,6 +95,15 @@ def __init__(self, command, supported):
95
95
def __str__ (self ):
96
96
return self .msg
97
97
98
+ to_dispatch = {}
99
+ def dispatch (command , help_text ):
100
+ def wrap (func ):
101
+ to_dispatch [command ] = (help_text , func )
102
+ def wrapped_f (* args , ** kwargs ):
103
+ return func (* args , ** kwargs )
104
+ return wrapped_f
105
+ return wrap
106
+
98
107
class ExternalBotHandler (object ):
99
108
def __init__ (self , client , root_dir , bot_details , bot_config_file ):
100
109
# type: (Client, str, Dict[str, Any], str) -> None
@@ -249,18 +258,22 @@ def dispatch_default_commands(self, message, command_list, meta, other_commands=
249
258
cmd_list = [cmd for cmd in command_list if cmd != "" ]
250
259
if other_commands is not None :
251
260
cmd_list .extend (other_commands )
261
+ cmd_list .extend (to_dispatch )
252
262
return "**Commands**: " + ", " .join (cmd_list )
253
263
elif command == "help" :
254
264
cmd_list = OrderedDict ([(cmd , supported_commands [cmd ]) for cmd in command_list if cmd != "" ])
255
265
if other_commands is not None :
256
266
cmd_list .update (OrderedDict ([(c , h [0 ]) for c , h in other_commands .items ()]))
267
+ cmd_list .update (OrderedDict ([(c , h [0 ]) for c , h in to_dispatch .items ()]))
257
268
help_text = ("**{name}**: {description}" .format (** meta )+
258
269
"\n This bot supports the following commands:\n " +
259
270
"\n " .join (["**{}** - {}" .format (c , h ) for c , h in cmd_list .items ()]))
260
271
return help_text
261
272
if other_commands is not None and command in other_commands :
262
273
if other_commands [command ][1 ] is not None :
263
274
return other_commands [command ][1 ]()
275
+ if command in to_dispatch :
276
+ return to_dispatch [command ][1 ]()
264
277
return None
265
278
266
279
def extract_query_without_mention (message , client ):
0 commit comments