class IRCBotFactory(ReconnectingClientFactory): def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None): if net is None: self.num = num self.net = None self.name = "relay - %i" % num self.relay = True else: self.name = net + str(num) self.num = num self.net = net self.relay = False self.client = None self.maxDelay = main.config["Tweaks"]["Delays"]["MaxDelay"] self.initialDelay = main.config["Tweaks"]["Delays"]["InitialDelay"] self.factor = main.config["Tweaks"]["Delays"]["Factor"] self.jitter = main.config["Tweaks"]["Delays"]["Jitter"] self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2 def buildProtocol(self, addr): if self.relay is False: entry = IRCBot(self.net, self.num) main.IRCPool[self.name] = entry else: entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2) self.client = entry return entry def clientConnectionLost(self, connector, reason): if not self.relay: userinfo.delChannels(self.net, self.client.channels) if self.client is not None: self.client.isconnected = False self.client.authenticated = False self.client.channels = [] error = reason.getErrorMessage() if not self.relay: log("%s - %i: connection lost: %s" % (self.net, self.num, error)) sendAll("%s - %i: connection lost: %s" % (self.net, self.num, error)) ctime = str(datetime.now().isoformat()) sendRelayNotification( { "type": "conn", "net": self.net, "num": self.num, "status": "lost", "message": error, "ts": ctime, } ) self.retry(connector) # ReconnectingClientFactory.clientConnectionLost(self, connector, reason) def clientConnectionFailed(self, connector, reason): if self.client is not None: self.client.isconnected = False self.client.authenticated = False self.client.channels = [] error = reason.getErrorMessage() log("%s - %i: connection failed: %s" % (self.net, self.num, error)) if not self.relay: sendAll("%s - %s: connection failed: %s" % (self.net, self.num, error)) ctime = str(datetime.now().isoformat()) sendRelayNotification( { "type": "conn", "net": self.net, "num": self.num, "status": "failed", "message": error, "ts": ctime, } ) self.retry(connector) # ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)