@@ -198,16 +198,41 @@ def default_about_response():
198
198
if bot_details ['description' ] == "" :
199
199
return "**{name}**" .format (** bot_details )
200
200
return "**{name}**: {description}" .format (** bot_details )
201
+
202
+ def default_commands_response ():
203
+ return "**Commands**: {} {}" .format (
204
+ " " .join (name for name in command_defaults if name ),
205
+ " " .join (name for name in bot_details ['commands' ] if name ))
206
+
207
+ def commands_list ():
208
+ return ("\n " .join ("**{}** - {}" .format (name , options [1 ])
209
+ for name , options in command_defaults .items () if name ) +
210
+ "\n " +
211
+ "\n " .join ("**{}** - {}" .format (name , description )
212
+ for name , description in bot_details ['commands' ].items () if name ))
213
+
214
+ def default_help_response ():
215
+ return "{}\n {}\n {}" .format (default_about_response (),
216
+ message_handler .usage (), commands_list ())
201
217
# FIXME Add boilerplate text above, to include eg. how to mention bot?
202
218
# FIXME Should usage be included?
203
219
204
220
command_defaults = OrderedDict ([ # Variable definition required for callbacks above
205
221
('' , (default_empty_response , "[BLANK MESSAGE NOT SHOWN]" )),
206
222
('about' , (default_about_response , "The type and use of this bot" )),
207
223
('usage' , ((lambda : message_handler .usage (), "Bot-provided usage text" ))),
224
+ ('commands' , (default_commands_response , "A short list of supported commands" )),
225
+ ('help' , (default_help_response , "This help text" )),
208
226
])
209
227
return command_defaults
210
228
229
+ def updated_default_commands (default_commands , bot_details ):
230
+ if not bot_details ['default_commands_enabled' ]:
231
+ return OrderedDict ()
232
+ exclude_list = bot_details ['commands' ] or ('commands' , 'help' )
233
+ return OrderedDict ((name , option ) for name , option in default_commands .items ()
234
+ if name not in exclude_list )
235
+
211
236
def run_message_handler_for_bot (lib_module , quiet , config_file , bot_name ):
212
237
# type: (Any, bool, str) -> Any
213
238
#
@@ -231,16 +256,17 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
231
256
bot_details = {
232
257
'name' : bot_name .capitalize (),
233
258
'description' : "" ,
259
+ # 'commands': {},
234
260
'default_commands_enabled' : True ,
235
261
}
236
262
bot_details .update (getattr (lib_module .handler_class , 'META' , {}))
237
263
238
264
# Initialise default commands, then override & sync with bot_details
239
265
default_commands = setup_default_commands (bot_details , message_handler )
240
- if bot_details [ 'default_commands_enabled' ]:
241
- updated_defaults = default_commands
242
- else :
243
- updated_defaults = OrderedDict ()
266
+ updated_defaults = updated_default_commands ( default_commands , bot_details )
267
+ # Update bot_details if updated_defaults is empty
268
+ if len ( updated_defaults ) == 0 :
269
+ bot_details [ 'default_commands_enabled' ] = False
244
270
245
271
if not quiet :
246
272
print ("Running {} Bot:" .format (bot_details ['name' ]))
0 commit comments