New callback _on_connect, called after 001 numeric reply reception: currently it joins channels

This commit is contained in:
nemunaire 2014-09-04 10:43:50 +02:00
parent c32f1579ee
commit 85ec2dcd01
2 changed files with 15 additions and 1 deletions

View File

@ -119,7 +119,11 @@ class MessageConsumer:
self.responses = list() self.responses = list()
for msg in self.msgs: for msg in self.msgs:
# TODO: should be placed in server hooks # 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])) self.srv.write("%s :%s" % ("PONG", msg.params[0]))
else: else:

View File

@ -33,6 +33,16 @@ class IRCServer(SocketServer):
self.realname = realname self.realname = realname
self.id = "TODO" 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): def _open(self):
if SocketServer._open(self): if SocketServer._open(self):
if self.password is not None: if self.password is not None: