diff -r 497b7290977d -r df862cca1773 modulecore.py --- a/modulecore.py Sun Aug 16 19:27:14 2015 +0300 +++ b/modulecore.py Sun Aug 16 23:30:11 2015 +0300 @@ -30,6 +30,7 @@ import os import re import time +import sys from configfile import Config Modules = {} @@ -63,24 +64,7 @@ Modules[fn] = module for cmd in module.ModuleData['commands']: - if cmd['args'] == None: - cmd['args'] = '' - - cmd['module'] = module - cmd['regex'] = make_regex (cmd['args']) - cmd['argnames'] = [] - Commands[cmd['name']] = cmd - - for argname in cmd['args'].split (' '): - argname = argname[1:-1] - - if argname[-3:] == '...': - argname = argname[0:-3] - - if argname == '': - continue - - cmd['argnames'].append (argname) + install_command (cmd, module) if 'hooks' in module.ModuleData: for key, hooks in module.ModuleData['hooks'].items(): @@ -96,6 +80,28 @@ print ('''Loaded %d commands and %d hooks in %d modules''' % (len (Commands), numHooks, len (Modules))) +def install_command (cmd, module): + if cmd['args'] == None: + cmd['args'] = '' + + Modules[module.__name__] = module + cmd['module'] = module + cmd['regex'] = make_regex (cmd['args']) + cmd['argnames'] = [] + + for argname in cmd['args'].split (' '): + argname = argname[1:-1] + + if argname[-3:] == '...': + argname = argname[0:-3] + + if argname == '': + continue + + cmd['argnames'].append (argname) + + Commands[cmd['name']] = cmd + # # command_error (message) # @@ -181,8 +187,8 @@ global g_lastConfirm global g_confirmCommand - if 'function' in commandObject: - func = commandObject['function'] + if 'function' in commandObject['info']: + func = commandObject['info']['function'] else: cmdname = commandObject['cmdname'] @@ -379,3 +385,22 @@ regex += r'\s*' return '^[^ ]+%s$' % regex + +def irc_command (**command): + def result (fn): + command['name'] = fn.__name__ + command['description'] = fn.__doc__ + command['function'] = fn + + if command['description'] == None: + command['description'] = '' + + if 'level' not in command: + command['level'] = 'normal' + + if 'args' not in command: + command['args'] = None + + install_command (command, sys.modules[fn.__module__]) + return fn + return result \ No newline at end of file