]> jfr.im git - erebus.git/blobdiff - modules/control.py
control - use new flags feature
[erebus.git] / modules / control.py
index 2e3dafb5ad8af206fd71002a9250912c6ec1dd27..4939fa155c1cc232304792834dd46f6753636897 100644 (file)
@@ -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] <mod>", "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] <mod>", "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)