111 lines
4.2 KiB
Python
111 lines
4.2 KiB
Python
from core.main import *
|
|
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 config["Default"]["nickname"] == None:
|
|
failure("Choose a nickname, or configure one in defaults")
|
|
toFail = True
|
|
else:
|
|
nickname = config["Default"]["nickname"]
|
|
|
|
if length < 5:
|
|
if config["Default"]["protocol"] == None:
|
|
failure("Choose a protocol, or configure one in defaults")
|
|
toFail = True
|
|
else:
|
|
protocol = config["Default"]["protocol"]
|
|
|
|
if length < 4:
|
|
if config["Default"]["port"] == None:
|
|
failure("Choose a port, or configure one in defaults")
|
|
toFail = True
|
|
else:
|
|
port = config["Default"]["port"]
|
|
|
|
if length < 3:
|
|
if config["Default"]["host"] == None:
|
|
failure("Choose a host, or configure one in defaults")
|
|
toFail = True
|
|
else:
|
|
host = config["Default"]["host"]
|
|
if toFail:
|
|
failure("Stopping due to previous error(s)")
|
|
return
|
|
|
|
if length < 2:
|
|
incUsage("add")
|
|
return
|
|
|
|
if name in 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
|
|
|
|
pool[name] = { "host": host,
|
|
"port": port,
|
|
"protocol": protocol,
|
|
"bind": config["Default"]["bind"],
|
|
"timeout": config["Default"]["timeout"],
|
|
"maxdelay": config["Default"]["maxdelay"],
|
|
"initialdelay": config["Default"]["initialdelay"],
|
|
"factor": config["Default"]["factor"],
|
|
"jitter": config["Default"]["jitter"],
|
|
"nickname": nickname,
|
|
"username": config["Default"]["username"],
|
|
"realname": config["Default"]["realname"],
|
|
"userinfo": config["Default"]["userinfo"],
|
|
"finger": config["Default"]["finger"],
|
|
"version": config["Default"]["version"],
|
|
"source": config["Default"]["source"],
|
|
"autojoin": config["Default"]["autojoin"],
|
|
"authtype": config["Default"]["authtype"],
|
|
"password": config["Default"]["password"],
|
|
"authentity": config["Default"]["authentity"],
|
|
"key": config["Default"]["key"],
|
|
"certificate": config["Default"]["certificate"],
|
|
"enabled": config["ConnectOnCreate"],
|
|
}
|
|
if config["ConnectOnCreate"] == True:
|
|
helper.addBot(name)
|
|
success("Successfully created bot")
|
|
saveConf("pool")
|
|
return
|
|
else:
|
|
incUsage(None)
|