monolith/commands/mod.py

90 lines
3.4 KiB
Python
Raw Normal View History

import main
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:
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
optionMap = ["Viewing options for %s" % spl[1]]
for i in main.pool[spl[1]].keys():
optionMap.append(" %s: %s" % (i, main.pool[spl[1]][i]))
info("\n".join(optionMap))
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[2] == "protocol":
if not spl[3] in ["ssl", "plain"]:
failure("Protocol must be ssl or plain, not %s" % spl[3])
return
if spl[3] == main.pool[spl[1]][spl[2]]:
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(",")
main.pool[spl[1]][spl[2]] = spl[3]
if spl[1] in main.IRCPool.keys():
main.IRCPool[spl[1]].refresh()
main.saveConf("pool")
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)