2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2018-07-28 20:33:50 +00:00
|
|
|
from yaml import dump
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2019-08-09 22:06:34 +00:00
|
|
|
class ModCommand:
|
2019-01-26 18:58:21 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self.mod(*args)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
|
|
|
if authed:
|
|
|
|
if length == 2:
|
2018-03-14 20:13:40 +00:00
|
|
|
if not spl[1] in main.pool.keys():
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Name does not exist: %s" % spl[1])
|
|
|
|
return
|
2018-07-28 20:33:50 +00:00
|
|
|
info(dump({spl[1]: main.pool[spl[1]]}))
|
2018-02-23 22:05:40 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
elif length == 3:
|
2018-03-14 20:13:40 +00:00
|
|
|
if not spl[1] in main.pool.keys():
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Name does not exist: %s" % spl[1])
|
|
|
|
return
|
2018-03-14 20:13:40 +00:00
|
|
|
if not spl[2] in main.pool[spl[1]].keys():
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("No such key: %s" % spl[2])
|
|
|
|
return
|
2018-03-14 20:13:40 +00:00
|
|
|
info("%s: %s" % (spl[2], main.pool[spl[1]][spl[2]]))
|
2018-02-23 22:05:40 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
elif length == 4:
|
2018-03-14 20:13:40 +00:00
|
|
|
if not spl[1] in main.pool.keys():
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Name does not exist: %s" % spl[1])
|
|
|
|
return
|
2018-03-14 20:13:40 +00:00
|
|
|
if not spl[2] in main.pool[spl[1]].keys():
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("No such key: %s" % spl[2])
|
|
|
|
return
|
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
if spl[3] == main.pool[spl[1]][spl[2]]:
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Value already exists: %s" % spl[3])
|
|
|
|
return
|
|
|
|
|
|
|
|
if spl[2] == "enabled":
|
|
|
|
failure("Use the enable and disable commands to manage this")
|
|
|
|
return
|
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
main.pool[spl[1]][spl[2]] = spl[3]
|
|
|
|
main.saveConf("pool")
|
2019-01-26 18:58:21 +00:00
|
|
|
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
2018-02-23 22:05:40 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
|
|
|
incUsage("mod")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|