/**
  * Neutralise the existing timer, if present, and create a new timer.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleReceived(Event $event, Queue $queue)
 {
     $connection = $event->getConnection();
     $timers = $this->getTimers();
     if ($timers->contains($connection)) {
         $timers->offsetGet($connection)->cancel();
     } else {
         $this->getLogger()->debug('Attaching activity listener for connection');
     }
     $timer = $this->getLoop()->addTimer($this->wait, array($this, 'callbackPhoneHome'));
     $timer->setData($connection);
     $timers->attach($connection, $timer);
 }
 /**
  * Filters events over the specified connection.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @return boolean TRUE if the event connection matches the one associated
  *         with this filter, FALSE otherwise
  */
 public function filter(EventInterface $event)
 {
     return in_array($event->getConnection(), $this->connections);
 }
 /**
  * Stores a reference to the event queue for the connection on which a USER
  * event occurs.
  *
  * @param \Phergie\Irc\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function setEventQueue(Event $event, Queue $queue)
 {
     $mask = $this->getConnectionMask($event->getConnection());
     $this->getEventQueueDeferred($mask)->resolve($queue);
 }
 /**
  * Stores references to each connection and their corresponding event
  * queues when a USER event is received.
  *
  * @param \Phergie\Irc\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function getEventQueue(Event $event, Queue $queue)
 {
     $connection = $event->getConnection();
     $mask = $this->getConnectionMask($connection);
     $this->connections[$mask] = $connection;
     $this->queues[$mask] = $queue;
 }
 /**
  * Nick is in use, pick another.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleEvent(Event $event, Queue $queue)
 {
     $iterator = $this->getIterator($event->getConnection());
     if (!$iterator->valid()) {
         $queue->ircQuit('All specified alternate nicks are in use');
         return;
     }
     $nick = $iterator->current();
     $iterator->next();
     $this->logger->debug("[AltNick] Switching nick to '{$nick}'");
     $queue->ircNick($nick);
     $event->getConnection()->setNickname($nick);
 }
 /**
  * Nick is in use, pick another.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleEvent(Event $event, Queue $queue)
 {
     $iterator = $this->getIterator($event->getConnection());
     if (!$iterator->valid()) {
         $queue->ircQuit('All specified alternate nicks are in use');
         return;
     }
     if ($this->recovery && $this->primaryNick === null) {
         $params = $event->getParams();
         $primaryNick = $params[1];
         $this->logger->debug("[AltNick] Saving '{$primaryNick}' as primary nick");
         $this->primaryNick = $primaryNick;
     }
     $nick = $iterator->current();
     $iterator->next();
     $this->logger->debug("[AltNick] Switching nick to '{$nick}'");
     $queue->ircNick($nick);
 }
 public function getConnection()
 {
     return $this->event->getConnection();
 }
 /**
  * Loads initial user mode data when the bot joins a channel.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function loadUserModes(EventInterface $event, EventQueueInterface $queue)
 {
     $logger = $this->getLogger();
     $connectionMask = $this->getConnectionMask($event->getConnection());
     $params = $event->getParams();
     $channel = $params[1];
     $validPrefixes = implode('', array_keys($this->prefixes));
     $pattern = '/^([' . preg_quote($validPrefixes) . ']+)(.+)$/';
     $logger->debug('Gathering initial user mode data', array('connectionMask' => $connectionMask, 'channel' => $channel));
     foreach ($params['iterable'] as $fullNick) {
         if (!preg_match($pattern, $fullNick, $match)) {
             continue;
         }
         $nickPrefixes = str_split($match[1]);
         $nick = $match[2];
         foreach ($nickPrefixes as $prefix) {
             $mode = $this->prefixes[$prefix];
             $logger->debug('Recording user mode', array('connectionMask' => $connectionMask, 'channel' => $channel, 'nick' => $nick, 'mode' => $mode));
             $this->modes[$connectionMask][$channel][$nick][$mode] = true;
         }
     }
 }