Separate out everything into files and implement a modules system to segment commands
This commit is contained in:
80
commands/default.py
Normal file
80
commands/default.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from core.main import *
|
||||
|
||||
class Default:
|
||||
def __init__(self, register):
|
||||
register("default", self.default)
|
||||
|
||||
def default(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
toUnset = False
|
||||
if length == 1:
|
||||
optionMap = ["Viewing defaults"]
|
||||
for i in config["Default"].keys():
|
||||
optionMap.append("%s: %s" % (i, config["Default"][i]))
|
||||
info("\n".join(optionMap))
|
||||
return
|
||||
elif length == 2:
|
||||
if not spl[1] in config["Default"].keys():
|
||||
failure("No such key: %s" % spl[1])
|
||||
return
|
||||
info("%s: %s" % (spl[1], config["Default"][spl[1]]))
|
||||
return
|
||||
elif length == 3:
|
||||
if not spl[1] in config["Default"].keys():
|
||||
failure("No such key: %s" % spl[1])
|
||||
return
|
||||
|
||||
if spl[2].lower() in ["none", "nil"]:
|
||||
spl[2] = None
|
||||
toUnset = True
|
||||
|
||||
if spl[1] in ["port", "timeout", "maxdelay"]:
|
||||
try:
|
||||
spl[2] = int(spl[2])
|
||||
except:
|
||||
failure("Value must be an integer, not %s" % spl[2])
|
||||
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[1] == "protocol":
|
||||
if not toUnset:
|
||||
if not spl[2] in ["ssl", "plain"]:
|
||||
failure("Protocol must be ssl or plain, not %s" % spl[2])
|
||||
return
|
||||
|
||||
if spl[2] == config["Default"][spl[1]]:
|
||||
failure("Value already exists: %s" % spl[2])
|
||||
return
|
||||
|
||||
if spl[1] == "authtype":
|
||||
if not toUnset:
|
||||
if not spl[2] in ["sp", "ns"]:
|
||||
failure("Authtype must be sp or ns, not %s" % spl[2])
|
||||
return
|
||||
if spl[1] == "enabled":
|
||||
failure("Use the ConnectOnCreate config parameter to set this")
|
||||
return
|
||||
if spl[1] == "autojoin":
|
||||
if not toUnset:
|
||||
spl[2] = spl[2].split(",")
|
||||
else:
|
||||
spl[2] = []
|
||||
|
||||
config["Default"][spl[1]] = spl[2]
|
||||
saveConf("config")
|
||||
if toUnset:
|
||||
success("Successfully unset key %s" % spl[1])
|
||||
else:
|
||||
success("Successfully set key %s to %s" % (spl[1], spl[2]))
|
||||
return
|
||||
else:
|
||||
incUsage("default")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
Reference in New Issue
Block a user