Restructure provisioning into fewer functions
This commit is contained in:
parent
1ac1061348
commit
d99c3c394f
|
@ -3,19 +3,33 @@ from core.bot import deliverRelayCommands
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
|
||||||
def provisionUserData(num, nick, altnick, ident, realname, unused): # last field is password,
|
def provisionUserNetworkData(num, nick, altnick, ident, realname, network, host, port, security, auth, password):
|
||||||
# which we don't want to inherit here, but still want to use * expansion, so this is a bit of a hack
|
|
||||||
commands = {}
|
commands = {}
|
||||||
|
stage2commands = {}
|
||||||
|
stage2commands["status"] = []
|
||||||
commands["controlpanel"] = []
|
commands["controlpanel"] = []
|
||||||
commands["controlpanel"].append("AddUser %s %s" % (nick, main.config["Relay"]["Password"]))
|
commands["controlpanel"].append("AddUser %s %s" % (nick, main.config["Relay"]["Password"]))
|
||||||
|
commands["controlpanel"].append("AddNetwork %s %s" % (nick, network))
|
||||||
commands["controlpanel"].append("Set Nick %s %s" % (nick, nick))
|
commands["controlpanel"].append("Set Nick %s %s" % (nick, nick))
|
||||||
commands["controlpanel"].append("Set Altnick %s %s" % (nick, altnick))
|
commands["controlpanel"].append("Set Altnick %s %s" % (nick, altnick))
|
||||||
commands["controlpanel"].append("Set Ident %s %s" % (nick, ident))
|
commands["controlpanel"].append("Set Ident %s %s" % (nick, ident))
|
||||||
commands["controlpanel"].append("Set RealName %s %s" % (nick, realname))
|
commands["controlpanel"].append("Set RealName %s %s" % (nick, realname))
|
||||||
deliverRelayCommands(num, commands)
|
if security == "ssl":
|
||||||
|
commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (nick, network)) # Don't judge me
|
||||||
|
commands["controlpanel"].append("AddServer %s %s %s +%s" % (nick, network, host, port))
|
||||||
|
elif security == "plain":
|
||||||
|
commands["controlpanel"].append("AddServer %s %s %s %s" % (nick, network, host, port))
|
||||||
|
if not main.config["ConnectOnCreate"]:
|
||||||
|
stage2commands["status"].append("Disconnect")
|
||||||
|
if main.config["Toggles"]["CycleChans"]:
|
||||||
|
stage2commands["status"].append("LoadMod disconkick")
|
||||||
|
stage2commands["status"].append("LoadMod chansaver")
|
||||||
|
deliverRelayCommands(num, commands,
|
||||||
|
stage2=[[nick+"/"+network, stage2commands]])
|
||||||
|
|
||||||
def provisionAuthenticationData(num, nick, network, security, auth, password):
|
def provisionAuthenticationData(num, nick, network, security, auth, password):
|
||||||
commands = {}
|
commands = {}
|
||||||
|
commands["status"] = []
|
||||||
if auth == "sasl":
|
if auth == "sasl":
|
||||||
commands["sasl"] = []
|
commands["sasl"] = []
|
||||||
commands["status"].append("LoadMod sasl")
|
commands["status"].append("LoadMod sasl")
|
||||||
|
@ -27,49 +41,16 @@ def provisionAuthenticationData(num, nick, network, security, auth, password):
|
||||||
commands["nickserv"].append("Set %s" % password)
|
commands["nickserv"].append("Set %s" % password)
|
||||||
deliverRelayCommands(num, commands, user=nick+"/"+network)
|
deliverRelayCommands(num, commands, user=nick+"/"+network)
|
||||||
|
|
||||||
def provisionNetworkData(num, nick, network, host, port, security, auth, password):
|
|
||||||
commands = {}
|
|
||||||
stage2commands = {}
|
|
||||||
stage2commands["status"] = []
|
|
||||||
commands["controlpanel"] = []
|
|
||||||
commands["controlpanel"].append("AddNetwork %s %s" % (nick, network))
|
|
||||||
if security == "ssl":
|
|
||||||
commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (nick, network)) # Don't judge me
|
|
||||||
commands["controlpanel"].append("AddServer %s %s %s +%s" % (nick, network, host, port))
|
|
||||||
elif security == "plain":
|
|
||||||
commands["controlpanel"].append("AddServer %s %s %s %s" % (nick, network, host, port))
|
|
||||||
# Remove below and use provisionAuthenticationData() when registration implemented
|
|
||||||
if auth == "sasl":
|
|
||||||
stage2commands["sasl"] = []
|
|
||||||
stage2commands["status"].append("LoadMod sasl")
|
|
||||||
stage2commands["sasl"].append("Mechanism plain")
|
|
||||||
stage2commands["sasl"].append("Set %s %s" % (nick, password))
|
|
||||||
elif auth == "ns":
|
|
||||||
stage2commands["nickserv"] = []
|
|
||||||
stage2commands["status"].append("LoadMod nickserv")
|
|
||||||
stage2commands["nickserv"].append("Set %s" % password)
|
|
||||||
# End
|
|
||||||
if not main.config["ConnectOnCreate"]:
|
|
||||||
stage2commands["status"].append("Disconnect")
|
|
||||||
if main.config["Toggles"]["CycleChans"]:
|
|
||||||
stage2commands["status"].append("LoadMod disconkick")
|
|
||||||
stage2commands["status"].append("LoadMod chansaver")
|
|
||||||
deliverRelayCommands(num, commands,
|
|
||||||
stage2=[[nick+"/"+network, stage2commands]])
|
|
||||||
|
|
||||||
def provisionRelayForNetwork(num, alias, network):
|
def provisionRelay(num, network): # provision user and network data
|
||||||
provisionNetworkData(num, alias, network,
|
aliasObj = main.alias[num]
|
||||||
|
alias = aliasObj["nick"]
|
||||||
|
provisionUserNetworkData(num, *aliasObj.values(), network,
|
||||||
main.network[network].host,
|
main.network[network].host,
|
||||||
main.network[network].port,
|
main.network[network].port,
|
||||||
main.network[network].security,
|
main.network[network].security,
|
||||||
main.network[network].auth,
|
main.network[network].auth,
|
||||||
main.network[network].aliases[num]["password"])
|
main.network[network].aliases[num]["password"])
|
||||||
|
|
||||||
def provisionRelay(num, network):
|
|
||||||
aliasObj = main.alias[num]
|
|
||||||
alias = aliasObj["nick"]
|
|
||||||
provisionUserData(num, *aliasObj.values())
|
|
||||||
reactor.callLater(5, provisionRelayForNetwork, num, alias, network)
|
|
||||||
if main.config["ConnectOnCreate"]:
|
if main.config["ConnectOnCreate"]:
|
||||||
reactor.callLater(10, main.network[network].start_bot, num)
|
reactor.callLater(10, main.network[network].start_bot, num)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue