@@ -92,6 +92,15 @@ def __init__(self, command, supported):
92
92
def __str__ (self ):
93
93
return self .msg
94
94
95
+ to_dispatch = {}
96
+ def dispatch (command , help_text ):
97
+ def wrap (func ):
98
+ to_dispatch [command ] = (help_text , func )
99
+ def wrapped_f (* args , ** kwargs ):
100
+ return func (* args , ** kwargs )
101
+ return wrapped_f
102
+ return wrap
103
+
95
104
class ExternalBotHandler (object ):
96
105
def __init__ (self , client , root_dir , bot_details = {}):
97
106
# type: (Client, str, Dict[str, Any]) -> None
@@ -215,18 +224,22 @@ def dispatch_default_commands(self, message, command_list, meta, other_commands=
215
224
cmd_list = [cmd for cmd in command_list if cmd != "" ]
216
225
if other_commands is not None :
217
226
cmd_list .extend (other_commands )
227
+ cmd_list .extend (to_dispatch )
218
228
return "**Commands**: " + ", " .join (cmd_list )
219
229
elif command == "help" :
220
230
cmd_list = OrderedDict ([(cmd , supported_commands [cmd ]) for cmd in command_list if cmd != "" ])
221
231
if other_commands is not None :
222
232
cmd_list .update (OrderedDict ([(c , h [0 ]) for c , h in other_commands .items ()]))
233
+ cmd_list .update (OrderedDict ([(c , h [0 ]) for c , h in to_dispatch .items ()]))
223
234
help_text = ("**{name}**: {description}" .format (** meta )+
224
235
"\n This bot supports the following commands:\n " +
225
236
"\n " .join (["**{}** - {}" .format (c , h ) for c , h in cmd_list .items ()]))
226
237
return help_text
227
238
if other_commands is not None and command in other_commands :
228
239
if other_commands [command ][1 ] is not None :
229
240
return other_commands [command ][1 ]()
241
+ if command in to_dispatch :
242
+ return to_dispatch [command ][1 ]()
230
243
return None
231
244
232
245
def extract_query_without_mention (message , client ):
0 commit comments