]> jfr.im git - erebus.git/commitdiff
control - use new flags feature
authorJohn Runyon <redacted>
Wed, 13 Mar 2024 02:31:21 +0000 (20:31 -0600)
committerJohn Runyon <redacted>
Wed, 13 Mar 2024 02:31:21 +0000 (20:31 -0600)
modules/control.py

index 693770dd47821a2c9b34dce8d4fd51b370ef6c7e..4939fa155c1cc232304792834dd46f6753636897 100644 (file)
@@ -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, "Incorrect syntax - can only name one module")
-                               return
-                       module = arg
-               elif arg.lower() == "-autoload":
-                       autoload = True
-               elif arg.lower() == "-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)