示例#1
0
 /**
  * Sends reply messages.
  *
  * @param UserEventInterface $event
  * @param Queue              $queue
  * @param array|string       $messages
  */
 protected function sendReply(UserEventInterface $event, Queue $queue, $messages)
 {
     $method = 'irc' . $event->getCommand();
     if (is_array($messages)) {
         $target = $event->getSource();
         foreach ($messages as $message) {
             $queue->{$method}($target, $message);
         }
     } else {
         $queue->{$method}($event->getSource(), $messages);
     }
 }
 /**
  * Joins a channel if nickname and channel matches the own nickname
  * and a channel in 'channels' configuration respectively.
  *
  * @param string $nickname
  * @param \Phergie\Irc\Event\UserEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function joinOnMatch($nickname, UserEventInterface $event, EventQueueInterface $queue)
 {
     if ($nickname == $event->getConnection()->getNickname() && ($index = array_search($event->getSource(), $this->channels)) !== false) {
         $queue->ircJoin($this->channels[$index], $this->keys ? $this->keys[$index] : null);
     }
 }
 /**
  * Monitor channel notices.
  *
  * @param \Phergie\Irc\Event\UserEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function processNotice(UserEvent $event, Queue $queue)
 {
     $logger = $this->getLogger();
     $source = $event->getSource();
     $nick = $event->getNick();
     if ($source === null || $nick === null || $source == $nick) {
         $logger->debug('Incoming NOTICE not in channel, ignoring');
         return;
     }
     $server = strtolower($event->getConnection()->getServerHostname());
     $channel = $source;
     $params = $event->getParams();
     $message = $params['text'];
     $logger->debug('Processing incoming NOTICE', array('server' => $server, 'channel' => $channel, 'nick' => $nick, 'message' => $message));
     try {
         $this->db->fetchAssoc(self::SQL_UPDATE, array(':time' => time(), ':server' => $server, ':channel' => $channel, ':nick' => $nick, ':type' => self::TYPE_NOTICE, ':text' => $message));
     } catch (\Exception $e) {
         $logger->error($e->getMessage());
     }
 }
 /**
  * Handles a failed fetch of tweet data.
  *
  * @param \Exception $error
  * @param \Phergie\Irc\Event\UserEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleError(\Exception $error, Event $event, Queue $queue)
 {
     $this->logger->debug('Received error', array('error' => $error));
     $message = 'Error fetching tweet: ' . get_class($error) . ': ' . $error->getMessage();
     $queue->ircPrivmsg($event->getSource(), $message);
 }