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
|
|
|
|
|
|
|
class Mod:
|
|
|
|
def __init__(self, register):
|
|
|
|
register("mod", self.mod)
|
|
|
|
|
|
|
|
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
|
|
|
if authed:
|
|
|
|
toUnset = False
|
|
|
|
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
|
|
|
|
|
|
|
|
if spl[2] == "protocol":
|
|
|
|
if not spl[3] in ["ssl", "plain"]:
|
|
|
|
failure("Protocol must be ssl or plain, not %s" % spl[3])
|
|
|
|
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[3].lower() in ["none", "nil"]:
|
|
|
|
spl[3] = None
|
|
|
|
toUnset = True
|
|
|
|
|
|
|
|
if spl[2] in ["port", "timeout", "maxdelay"]:
|
|
|
|
try:
|
|
|
|
spl[3] = int(spl[3])
|
|
|
|
except:
|
|
|
|
failure("Value must be an integer, not %s" % spl[3])
|
|
|
|
return
|
|
|
|
|
|
|
|
if spl[2] in ["initialdelay", "factor", "jitter"]:
|
|
|
|
try:
|
|
|
|
spl[3] = float(spl[3])
|
|
|
|
except:
|
|
|
|
failure("Value must be a floating point integer, not %s" % spl[3])
|
|
|
|
return
|
|
|
|
|
|
|
|
if spl[2] == "authtype":
|
|
|
|
if not toUnset:
|
|
|
|
if not spl[3] in ["sp", "ns"]:
|
|
|
|
failure("Authtype must be sp or ns, not %s" % spl[3])
|
|
|
|
return
|
|
|
|
if spl[2] == "enabled":
|
|
|
|
failure("Use the enable and disable commands to manage this")
|
|
|
|
return
|
|
|
|
if spl[2] == "autojoin":
|
|
|
|
spl[3] = spl[3].split(",")
|
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
main.pool[spl[1]][spl[2]] = spl[3]
|
|
|
|
if spl[1] in main.IRCPool.keys():
|
|
|
|
main.IRCPool[spl[1]].refresh()
|
|
|
|
main.saveConf("pool")
|
2018-02-23 22:05:40 +00:00
|
|
|
if toUnset:
|
|
|
|
success("Successfully unset key %s on %s" % (spl[2], spl[1]))
|
|
|
|
else:
|
|
|
|
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
|
|
|
incUsage("mod")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|