53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
import main
|
|
from yaml import dump
|
|
|
|
class ModCommand:
|
|
def __init__(self, *args):
|
|
self.mod(*args)
|
|
|
|
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
|
if authed:
|
|
if length == 2:
|
|
if not spl[1] in main.pool.keys():
|
|
failure("Name does not exist: %s" % spl[1])
|
|
return
|
|
info(dump({spl[1]: main.pool[spl[1]]}))
|
|
return
|
|
|
|
elif length == 3:
|
|
if not spl[1] in main.pool.keys():
|
|
failure("Name does not exist: %s" % spl[1])
|
|
return
|
|
if not spl[2] in main.pool[spl[1]].keys():
|
|
failure("No such key: %s" % spl[2])
|
|
return
|
|
info("%s: %s" % (spl[2], main.pool[spl[1]][spl[2]]))
|
|
return
|
|
|
|
elif length == 4:
|
|
if not spl[1] in main.pool.keys():
|
|
failure("Name does not exist: %s" % spl[1])
|
|
return
|
|
if not spl[2] in main.pool[spl[1]].keys():
|
|
failure("No such key: %s" % spl[2])
|
|
return
|
|
|
|
if spl[3] == main.pool[spl[1]][spl[2]]:
|
|
failure("Value already exists: %s" % spl[3])
|
|
return
|
|
|
|
if spl[2] == "enabled":
|
|
failure("Use the enable and disable commands to manage this")
|
|
return
|
|
|
|
main.pool[spl[1]][spl[2]] = spl[3]
|
|
main.saveConf("pool")
|
|
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
|
return
|
|
|
|
else:
|
|
incUsage("mod")
|
|
return
|
|
else:
|
|
incUsage(None)
|