monolith/commands/add.py

111 lines
4.3 KiB
Python
Raw Normal View History

import main
import core.helper as helper
class Add:
def __init__(self, register):
register("add", self.add)
def add(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 6:
failure("Too many arguments")
return
if length > 1:
name = spl[1]
else:
incUsage("add")
return
if length > 2:
host = spl[2]
if length > 3:
port = spl[3]
if length > 4:
protocol = spl[4]
if length > 5:
nickname = spl[5]
toFail = False
if length < 6:
if main.config["Default"]["nickname"] == None:
failure("Choose a nickname, or configure one in defaults")
toFail = True
else:
nickname = main.config["Default"]["nickname"]
if length < 5:
if main.config["Default"]["protocol"] == None:
failure("Choose a protocol, or configure one in defaults")
toFail = True
else:
protocol = main.config["Default"]["protocol"]
if length < 4:
if main.config["Default"]["port"] == None:
failure("Choose a port, or configure one in defaults")
toFail = True
else:
port = main.config["Default"]["port"]
if length < 3:
if main.config["Default"]["host"] == None:
failure("Choose a host, or configure one in defaults")
toFail = True
else:
host = main.config["Default"]["host"]
if toFail:
failure("Stopping due to previous error(s)")
return
if length < 2:
incUsage("add")
return
if name in main.pool.keys():
failure("Name already exists: %s" % name)
return
protocol = protocol.lower()
if not protocol in ["ssl", "plain"]:
failure("Protocol must be ssl or plain, not %s" % protocol)
return
try:
int(port)
except:
failure("Port must be an integer, not %s" % port)
return
main.pool[name] = { "host": host,
"port": port,
"protocol": protocol,
"bind": main.config["Default"]["bind"],
"timeout": main.config["Default"]["timeout"],
"maxdelay": main.config["Default"]["maxdelay"],
"initialdelay": main.config["Default"]["initialdelay"],
"factor": main.config["Default"]["factor"],
"jitter": main.config["Default"]["jitter"],
"nickname": nickname,
"username": main.config["Default"]["username"],
"realname": main.config["Default"]["realname"],
"userinfo": main.config["Default"]["userinfo"],
"finger": main.config["Default"]["finger"],
"version": main.config["Default"]["version"],
"source": main.config["Default"]["source"],
"autojoin": main.config["Default"]["autojoin"],
"authtype": main.config["Default"]["authtype"],
"password": main.config["Default"]["password"],
"authentity": main.config["Default"]["authentity"],
"key": main.config["Default"]["key"],
"certificate": main.config["Default"]["certificate"],
"enabled": main.config["ConnectOnCreate"],
}
2018-04-21 13:38:07 +00:00
if main.config["ConnectOnCreate"] == True:
helper.addBot(name)
success("Successfully created bot")
main.saveConf("pool")
return
else:
incUsage(None)