Update examples and change how variables used when reconnecting are set

This commit is contained in:
Mark Veidemanis 2018-02-03 19:31:59 +00:00
parent 88426be62a
commit aacb50d5d2
2 changed files with 31 additions and 10 deletions

View File

@ -21,10 +21,10 @@
"protocol": null, "protocol": null,
"bind": null, "bind": null,
"timeout": 30, "timeout": 30,
"maxdelay": 5, "maxdelay": 360,
"initialdelay": 1, "initialdelay": 1.0,
"factor": 2, "factor": 2.7182818284590451,
"jitter": 5, "jitter": 0.11962656472,
"nickname": null, "nickname": null,
"username": null, "username": null,
"realname": null, "realname": null,

View File

@ -251,6 +251,7 @@ class IRCBotFactory(ReconnectingClientFactory):
def __init__(self, name): def __init__(self, name):
self.instance = pool[name] self.instance = pool[name]
self.name = name self.name = name
self.client = None
self.maxDelay = self.instance["maxdelay"] self.maxDelay = self.instance["maxdelay"]
self.initialDelay = self.instance["initialdelay"] self.initialDelay = self.instance["initialdelay"]
self.factor = self.instance["factor"] self.factor = self.instance["factor"]
@ -264,6 +265,7 @@ class IRCBotFactory(ReconnectingClientFactory):
return entry return entry
def clientConnectionLost(self, connector, reason): def clientConnectionLost(self, connector, reason):
if not self.client == None:
self.client.connected = False self.client.connected = False
self.client.channels = [] self.client.channels = []
error = reason.getErrorMessage() error = reason.getErrorMessage()
@ -273,6 +275,7 @@ class IRCBotFactory(ReconnectingClientFactory):
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason) #ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
if not self.client == None:
self.client.connected = False self.client.connected = False
self.client.channels = [] self.client.channels = []
error = reason.getErrorMessage() error = reason.getErrorMessage()
@ -963,6 +966,10 @@ class Helper(object):
"protocol": protocol, "protocol": protocol,
"bind": config["Default"]["bind"], "bind": config["Default"]["bind"],
"timeout": config["Default"]["timeout"], "timeout": config["Default"]["timeout"],
"maxdelay": config["Default"]["maxdelay"],
"initialdelay": config["Default"]["initialdelay"],
"factor": config["Default"]["factor"],
"jitter": config["Default"]["jitter"],
"nickname": nickname, "nickname": nickname,
"username": config["Default"]["username"], "username": config["Default"]["username"],
"realname": config["Default"]["realname"], "realname": config["Default"]["realname"],
@ -1024,13 +1031,20 @@ class Helper(object):
spl[2] = None spl[2] = None
toUnset = True toUnset = True
if spl[1] in ["port", "timeout", "maxdelay", "initialdelay", "factor", "jitter"]: if spl[1] in ["port", "timeout", "maxdelay"]:
try: try:
spl[2] = int(spl[2]) spl[2] = int(spl[2])
except: except:
failure("Value must be an integer, not %s" % spl[2]) failure("Value must be an integer, not %s" % spl[2])
return 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 spl[1] == "protocol":
if not toUnset: if not toUnset:
if not spl[2] in ["ssl", "plain"]: if not spl[2] in ["ssl", "plain"]:
@ -1108,13 +1122,20 @@ class Helper(object):
spl[3] = None spl[3] = None
toUnset = True toUnset = True
if spl[2] in ["port", "timeout", "maxdelay", "initialdelay", "factor", "jitter"]: if spl[2] in ["port", "timeout", "maxdelay"]:
try: try:
spl[3] = int(spl[3]) spl[3] = int(spl[3])
except: except:
failure("Value must be an integer, not %s" % spl[3]) failure("Value must be an integer, not %s" % spl[3])
return 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[2] == "authtype": if spl[2] == "authtype":
if not toUnset: if not toUnset:
if not spl[3] in ["sp", "ns"]: if not spl[3] in ["sp", "ns"]: