Commits

Lucian Brănescu-Mihăilă  committed 8133b3e

Add IRC bits.

  • Participants
  • Parent commits 4572ef4

Comments (0)

Files changed (1)

 
 from gi.repository import Gtk, Gio
 
+from twisted.internet import reactor
+from twisted.internet.protocol import ClientFactory
+from twisted.words.protocols.irc import IRCClient
+
+class IRC(IRCClient):
+    nickname = 'testirk'
+
+    def __init__(self, store):
+        self.store = store
+
+    def lineReceived(self, line):
+        self.store.append([line])
+        print 'line'
+
+    def connectionMade(self):
+        IRCClient.connectionMade(self)
+
+        self.store.append(['* CONNECTED'])
+        print 'conn'
+
+    def clientConnectionLost(self, connection, reason):
+        IRCClient.clientConnectionLost(self)
+
+        self.store.append(['* DISCONNECTED'])
+        print 'disconn'
+
+
+class IRCFactory(ClientFactory):
+    protocol = IRC
+
+    def __init__(self, store):
+        self.store = store
+
+    def buildProtocol(self, addr):
+        p = self.protocol(self.store)
+        p.factory = self
+        return p
+
+    def clientConnectionLost(self, connector, reason):
+        """If we get disconnected, reconnect to server."""
+        connector.connect()
+
+    def clientConnectionFailed(self, connector, reason):
+        print "connection failed:", reason
+
+
 class Irk(Gtk.Application):
     def __init__(self):
         super(Irk, self).__init__(
         summary.append_column(
             Gtk.TreeViewColumn("Message", Gtk.CellRendererText(), text=0))
 
-        store.append(['Hello'])
+        #store.append(['Hello'])
+        self._summary = store
 
     def _activate_cb(self, widget):
-        pass
+        irc_factory = IRCFactory(self._summary)
+        reactor.connectTCP('irc.freenode.net', 6667, irc_factory)
 
 if __name__ == "__main__":
     app = Irk()
-    app.run(None)
+    #app.run(None)
+    reactor.run()
+
+    #irc_factory = IRCFactory(Gtk.ListStore(str))
+    #reactor.connectTCP('irc.freenode.net', 6667, irc_factory)
+    #reactor.run()