16
16
17
17
if False :
18
18
from mypy_extensions import NoReturn
19
- from typing import Any , Optional , List , Dict , IO , Text , Set , Sequence
19
+ from typing import Any , Optional , List , Dict , IO , Text , Set , Sequence , Tuple , Callable
20
20
from types import ModuleType
21
21
22
22
from zulip import Client , ZulipError
@@ -221,14 +221,14 @@ def open(self, filepath):
221
221
"files in their local directory." .format (abs_filepath ))
222
222
223
223
def dispatch_default_commands (self , message , command_list , meta , other_commands = None ):
224
- # type: (Dict[str, Any], Sequence[Text], Dict[Text, Text], Optional[Mapping[Text, Text]]) -> Optional[Text]
224
+ # type: (Dict[str, Any], Sequence[Text], Dict[Text, Text], Optional[Mapping[Text, Tuple[ Text, Optional[Callable[[], Text]]] ]]) -> Optional[Text]
225
225
supported_commands = OrderedDict ([
226
226
("" , "" ), # No help text, as this shouldn't appear in commands/help
227
227
("about" , "The brief type and use of this bot." ),
228
228
("commands" , "A short list of the supported commands." ),
229
229
("help" , "This help text." ),
230
230
])
231
- ["" , "about" , "commands" , "help" ] # TODO: 'custom'
231
+ ["" , "about" , "commands" , "help" ]
232
232
233
233
# Check command_list has supported commands
234
234
for requested_command in command_list :
@@ -253,11 +253,14 @@ def dispatch_default_commands(self, message, command_list, meta, other_commands=
253
253
elif command == "help" :
254
254
cmd_list = OrderedDict ([(cmd , supported_commands [cmd ]) for cmd in command_list if cmd != "" ])
255
255
if other_commands is not None :
256
- cmd_list .update (other_commands )
256
+ cmd_list .update (OrderedDict ([( c , h [ 0 ]) for c , h in other_commands . items ()]) )
257
257
help_text = ("**{name}**: {description}" .format (** meta )+
258
258
"\n This bot supports the following commands:\n " +
259
259
"\n " .join (["**{}** - {}" .format (c , h ) for c , h in cmd_list .items ()]))
260
260
return help_text
261
+ if other_commands is not None and command in other_commands :
262
+ if other_commands [command ][1 ] is not None :
263
+ return other_commands [command ][1 ]()
261
264
return None
262
265
263
266
def extract_query_without_mention (message , client ):
0 commit comments