class QWebIRCClient(basic.LineReceiver):
delimiter = "\n"
-
+
def dataReceived(self, data):
basic.LineReceiver.dataReceived(self, data.replace("\r", ""))
def connectionMade(self):
basic.LineReceiver.connectionMade(self)
+ self.lastError = None
f = self.factory.ircinit
nick, ident, ip, realname = f["nick"], f["ident"], f["ip"], f["realname"]
self("connect")
def connectionLost(self, reason):
+ if self.lastError:
+ self.disconnect("Connection to IRC server lost: %s" % self.lastError)
+ else:
+ self.disconnect("Connection to IRC server lost.")
self.factory.client = None
basic.LineReceiver.connectionLost(self, reason)
- self("disconnect")
+
+ def error(self, message):
+ self.lastError = message
+ self.write("QUIT :qwebirc exception: %s" % message)
+ self.transport.loseConnection()
+
+ def disconnect(self, reason):
+ self("disconnect", reason)
+ self.factory.publisher.disconnect()
class QWebIRCFactory(protocol.ClientFactory):
protocol = QWebIRCClient
def write(self, data):
self.client.write(data)
-
+
+ def error(self, reason):
+ self.client.error(reason)
+
+ def clientConnectionFailed(self, reason):
+ protocol.ClientFactory.clientConnectionFailed(reason)
+ self.client.disconnect("Connection to IRC server failed.")
+
def createIRC(*args, **kwargs):
f = QWebIRCFactory(*args, **kwargs)
reactor.connectTCP(config.IRCSERVER, config.IRCPORT, f)
if __name__ == "__main__":
e = createIRC(lambda x: 2, nick="slug__moo", ident="mooslug", ip="1.2.3.6", realname="mooooo")
- reactor.run()
\ No newline at end of file
+ reactor.run()