Exemplo n.º 1
0
 /**
  * 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;
         }
     });
 }
Exemplo n.º 2
0
 /**
  * There are certain incoming events that the client processes internally.
  * These functions are essential to the client-server relationship: for example,
  * updating the connection's stored nickname, responding to PING events, etc.
  *
  * Any user-level IRC functionality handled internally by the client
  * should be implemented here.
  *
  * @param array $message Parser output
  * @param \Phergie\Irc\Client\React\WriteStream $write Write stream
  *        corresponding to the read stream on which the event occurred
  * @param \Phergie\Irc\ConnectionInterface $connection Connection on
  *        which the event occurred
  */
 protected function processInput(array $message, WriteStream $write, ConnectionInterface $connection)
 {
     switch ($message['command']) {
         // Update connection's internal nickname when changed
         case 'NICK':
             if ($connection->getNickname() === $message['nick']) {
                 $connection->setNickname($message['params']['nickname']);
             }
             break;
             // Play client-server ping-pong
         // Play client-server ping-pong
         case 'PING':
             $write->ircPong($message['params']['server1']);
             break;
     }
 }