X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/de66fe6d5bb5be3278beef5daa4fcff562d256f6..HEAD:/modules/control.py diff --git a/modules/control.py b/modules/control.py index 2e3dafb..4939fa1 100644 --- a/modules/control.py +++ b/modules/control.py @@ -24,7 +24,7 @@ import ctlmod from collections import deque -@lib.hook(('die','restart'), needchan=False, glevel=lib.MANAGER) +@lib.hook(('die','restart','exit'), needchan=False, glevel=lib.MANAGER) @lib.help(None, "stops the bot") def die(bot, user, chan, realtarget, *args): quitmsg = ' '.join(args) @@ -34,20 +34,11 @@ def die(bot, user, chan, realtarget, *args): @lib.hook(needchan=False, glevel=lib.MANAGER) @lib.help("[-autoload] ", "loads a module, optionally marking it for autoloading") -@lib.argsGE(1) -def modload(bot, user, chan, realtarget, *args): - module = None - autoload = False - for arg in args: - if arg[0] != "-": - if module is not None: - bot.msg(user, "Wrong number of arguments.") - return - module = arg - elif arg == "-autoload": - autoload = True - else: - bot.msg(user, "Bad option %s" % (arg)) +@lib.flags('autoload') +@lib.argsEQ(1) +def modload(bot, user, chan, realtarget, flags, *args): + autoload = flags['autoload'] + module = args[0] if autoload: bot.parent.cfg.set('autoloads', module, 1) @@ -60,23 +51,12 @@ def modload(bot, user, chan, realtarget, *args): @lib.hook(needchan=False, glevel=lib.MANAGER) @lib.help("[-force] [-autoload] ", "unloads a module", "will refuse to unload a module which is depended on by others unless you specify FORCE.", "optionally removes from autoloads") -@lib.argsGE(1) -def modunload(bot, user, chan, realtarget, *args): - module = None - autoload = False - force = False - for arg in args: - if arg[0] != "-": - if module is not None: - bot.msg(user, "Wrong number of arguments.") - return - module = arg - elif arg == "-autoload": - autoload = True - elif arg == "-force": - force = True - else: - bot.msg(user, "Bad option %s" % (arg)) +@lib.flags('force','autoload') +@lib.argsEQ(1) +def modunload(bot, user, chan, realtarget, flags, *args): + autoload = flags['autoload'] + force = flags['force'] + module = args[0] if autoload: bot.parent.cfg.delete('autoloads', module) @@ -86,7 +66,7 @@ def modunload(bot, user, chan, realtarget, *args): return if len(ctlmod.dependents[module]) > 0: if not force: - bot.msg(user, "That module has dependents! Say MODUNLOAD %s FORCE to unload it and any dependents." % (module)) + bot.msg(user, "That module has dependents! Say MODUNLOAD -force %s to unload it and any dependents." % (module)) return okay = ctlmod.unload(bot.parent, module)