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,
"bind": null,
"timeout": 30,
"maxdelay": 5,
"initialdelay": 1,
"factor": 2,
"jitter": 5,
"maxdelay": 360,
"initialdelay": 1.0,
"factor": 2.7182818284590451,
"jitter": 0.11962656472,
"nickname": null,
"username": null,
"realname": null,

View File

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