--- a/mod_util.py Sat Nov 29 10:11:42 2014 -0500 +++ b/mod_util.py Sat Nov 29 10:45:51 2014 -0500 @@ -2,6 +2,7 @@ import urllib2 import json from modulecore import command_error +import modulecore as ModuleCore ModuleData = { 'commands': @@ -19,6 +20,20 @@ 'args': '<term...>', 'level': 'normal', }, + + { + 'name': 'commands', + 'description': 'Lists commands available to the calling user', + 'args': None, + 'level': 'normal', + }, + + { + 'name': 'help', + 'description': 'Prints help about a given command', + 'args': '<command>', + 'level': 'normal', + }, ] } @@ -70,4 +85,26 @@ down = data['list'][0]['thumbs_down'] bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) except Exception as e: - command_error ('Urban dictionary lookup failed: %s' % e) \ No newline at end of file + command_error ('Urban dictionary lookup failed: %s' % e) + +def cmd_commands (bot, replyto, ident, host, **rest): + commandlist = ModuleCore.get_available_commands (ident, host) + partitioned=[] + + while len (commandlist) > 0: + partitioned.append (commandlist[0:15]) + commandlist = commandlist[15:] + + for part in partitioned: + bot.privmsg (replyto, 'Available commands: %s' % (", ".join (part))) + +def cmd_help (bot, replyto, ident, host, args, **rest): + cmd = ModuleCore.get_command_by_name (args['command']) + + if not cmd: + command_error ('unknown command \'%s\'' % args['command']) + + if not ModuleCore.is_available (cmd, ident, host): + command_error ('you may not use %s' % cmd['name']) + + bot.privmsg (replyto, '%s %s: %s' % (cmd['name'], cmd['args'], cmd['description']))