--- a/modulecore.py Sat Nov 29 10:11:42 2014 -0500 +++ b/modulecore.py Sat Nov 29 10:45:51 2014 -0500 @@ -67,6 +67,18 @@ raise CommandError (message) # +# is_available (cmd, ident, host) +# +# Is the given command available to the given user? +# +def is_available (cmd, ident, host): + if cmd['level'] == 'admin' \ + and not "%s@%s" % (ident, host) in Config.get_value ('admins', default=[]): + return False + + return True + +# # call_command (bot, message, cmdname, **kvargs) # # Calls a cobalt command @@ -77,8 +89,7 @@ except KeyError: return False - if cmd['level'] == 'admin' \ - and not "%s@%s" % (kvargs['ident'], kvargs['host']) in Config.get_value ('admins', default=[]): + if not is_available (cmd, kvargs['ident'], kvargs['host']): command_error ("you may not use %s" % cmdname) match = re.compile (cmd['regex']).match (message) @@ -99,6 +110,33 @@ return True # +# get_available_commands +# +# Gets a list of commands available to the given user +# +def get_available_commands (ident, host): + result=[] + + for cmdname,cmd in Commands.iteritems(): + if not is_available (cmd, ident, host): + continue + + result.append (cmdname) + + return result + +# +# get_command_by_name +# +# Gets a command by name +# +def get_command_by_name (name): + try: + return Commands[name] + except: + return None + +# # make_regex # # Takes the argument list and returns a corresponding regular expression @@ -156,4 +194,4 @@ #done return '^[^ ]+%s$' % regex -#enddef \ No newline at end of file +#enddef