From 85ec2dcd018650f7a6a92b26f1cd7c3d5137244f Mon Sep 17 00:00:00 2001 From: nemunaire Date: Thu, 4 Sep 2014 10:43:50 +0200 Subject: [PATCH] New callback _on_connect, called after 001 numeric reply reception: currently it joins channels --- consumer.py | 6 +++++- server/IRC.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/consumer.py b/consumer.py index da9e711..4a94c2c 100644 --- a/consumer.py +++ b/consumer.py @@ -119,7 +119,11 @@ class MessageConsumer: self.responses = list() for msg in self.msgs: # TODO: should be placed in server hooks - if msg.cmd == "PING": + if msg.cmd == "001": + if hasattr(self.srv, "_on_connect"): + self.srv._on_connect() + + elif msg.cmd == "PING": self.srv.write("%s :%s" % ("PONG", msg.params[0])) else: diff --git a/server/IRC.py b/server/IRC.py index 61c8172..fe8bbb2 100644 --- a/server/IRC.py +++ b/server/IRC.py @@ -33,6 +33,16 @@ class IRCServer(SocketServer): self.realname = realname self.id = "TODO" + def _on_connect(): + # First, JOIN some channels + for chn in node.getNodes("channel"): + if chn["password"] is not None: + self.write("JOIN %s %s" % (chn["name"], chn["password"])) + else: + self.write("JOIN %s" % chn["name"]) + self._on_connect = _on_connect + + def _open(self): if SocketServer._open(self): if self.password is not None: