/** * Attaches the reading listener */ private function attachReadListener() { $this->client->on('irc.received', function ($message, $writeStream) { /** * Store the write stream so we can use it later... */ if ($this->write === false) { $this->write = $writeStream; } /** * Join the configured channel once connected */ if (isset($message['code']) && $message['code'] == 'RPL_ENDOFMOTD') { $this->write->ircJoin($this->getContainer()->get('config')['irc']['channel']); $this->connected = true; $this->getContainer()->get('logger')->info('Connected to IRC'); return; } /** * Respond to PING */ if (isset($message['command']) && $message['command'] === 'PING') { $this->getContainer()->get('logger')->debug('Responding to PING with a PONG'); $this->write->ircPong($message['params']['server1']); return; } /** * Read the chat, and send messages to the socket */ if (isset($message['command']) && $message['command'] === 'PRIVMSG' && !isset($message['ctcp'])) { $nick = $message['nick']; $text = $message['params']['text']; $channel = $message['params']['receivers']; if ($channel == $this->getContainer()->get('config')['irc']['channel'] && $nick != $this->getContainer()->get('config')['irc']['nickname']) { $this->getContainer()->get('logger')->debug('Found a message in the IRC channel. Writing it to the XMPP Socket'); $this->ircStream->write(sprintf("<%s> %s", $nick, $text)); } return; } }); }
/** * Joins all the channels added to auto join list * @param WriteStream $writeStream WriteStream object * @return void */ public function trigger(WriteStream $writeStream) { foreach ($this->list as $channel => $key) { $writeStream->ircJoin($channel, $key); } }