2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2018-02-23 22:05:40 +00:00
|
|
|
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:
|
2018-03-14 20:13:40 +00:00
|
|
|
if main.config["Default"]["nickname"] == None:
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Choose a nickname, or configure one in defaults")
|
|
|
|
toFail = True
|
|
|
|
else:
|
2018-03-14 20:13:40 +00:00
|
|
|
nickname = main.config["Default"]["nickname"]
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
if length < 5:
|
2018-03-14 20:13:40 +00:00
|
|
|
if main.config["Default"]["protocol"] == None:
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Choose a protocol, or configure one in defaults")
|
|
|
|
toFail = True
|
|
|
|
else:
|
2018-03-14 20:13:40 +00:00
|
|
|
protocol = main.config["Default"]["protocol"]
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
if length < 4:
|
2018-03-14 20:13:40 +00:00
|
|
|
if main.config["Default"]["port"] == None:
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Choose a port, or configure one in defaults")
|
|
|
|
toFail = True
|
|
|
|
else:
|
2018-03-14 20:13:40 +00:00
|
|
|
port = main.config["Default"]["port"]
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
if length < 3:
|
2018-03-14 20:13:40 +00:00
|
|
|
if main.config["Default"]["host"] == None:
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Choose a host, or configure one in defaults")
|
|
|
|
toFail = True
|
|
|
|
else:
|
2018-03-14 20:13:40 +00:00
|
|
|
host = main.config["Default"]["host"]
|
2018-02-23 22:05:40 +00:00
|
|
|
if toFail:
|
|
|
|
failure("Stopping due to previous error(s)")
|
|
|
|
return
|
|
|
|
|
|
|
|
if length < 2:
|
|
|
|
incUsage("add")
|
|
|
|
return
|
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
if name in main.pool.keys():
|
2018-02-23 22:05:40 +00:00
|
|
|
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
|
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
main.pool[name] = { "host": host,
|
2018-02-23 22:05:40 +00:00
|
|
|
"port": port,
|
|
|
|
"protocol": protocol,
|
2018-03-14 20:13:40 +00:00
|
|
|
"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"],
|
2018-02-23 22:05:40 +00:00
|
|
|
"nickname": nickname,
|
2018-03-14 20:13:40 +00:00
|
|
|
"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-02-23 22:05:40 +00:00
|
|
|
}
|
2018-04-21 13:38:07 +00:00
|
|
|
if main.config["ConnectOnCreate"] == True:
|
2018-02-23 22:05:40 +00:00
|
|
|
helper.addBot(name)
|
|
|
|
success("Successfully created bot")
|
2018-03-14 20:13:40 +00:00
|
|
|
main.saveConf("pool")
|
2018-02-23 22:05:40 +00:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|