public function nickChanged(IrcDataObject $data)
 {
     $logger = $this->getModulePool()->get('Logger');
     $logger->info('Nickname change detected; old: ' . $this->getNickname() . '; new: ' . $data->getParams()['nickname']);
     $this->setNickname($data->getParams()['nickname']);
     $configuration = $this->getModulePool()->get('Configuration');
     $configuration->set('nick', $data->getParams()['nickname']);
 }
 /**
  * @param IrcDataObject $resource
  */
 public function updateAvailableCapabilities(IrcDataObject $resource)
 {
     $params = $resource->getParams();
     if (is_array($params)) {
         return;
     }
     $matches = preg_match('/ACK :(.+)/i', $params, $out);
     if (empty($matches) || empty($out[1])) {
         return;
     }
     $capabilities = trim(strtolower($out[1]));
     $capabilities = explode(' ', $capabilities);
     foreach ($capabilities as $cap) {
         $this->parent->getEventEmitter()->emit('irc.connection.cap.acquired', [$cap]);
         $this->parent->getEventEmitter()->emit('irc.connection.cap.' . $cap . '.acquired', [$cap]);
     }
     $this->acquiredCapabilities = array_merge($this->acquiredCapabilities, $capabilities);
     $this->acquiredCapabilities = array_unique($this->acquiredCapabilities);
 }
 /**
  * @param IrcDataObject $message
  * @return void
  */
 public function sniffLinks(IrcDataObject $message)
 {
     $string = $message->getParams()['text'];
     $target = $message->getTargets()[0];
     try {
         $uri = SnifferHelper::extractUriFromString($string);
     } catch (NoUriFoundException $e) {
         return;
     }
     $cacheItem = $this->uriCache->getCacheItem($uri);
     if (!$cacheItem) {
         try {
             $shortUri = $this->createShortUri($uri);
             # We prefer is.gd for content type queries. This significantly reduces errors.
             $contentTypeUri = $shortUri;
             if ($contentTypeUri == 'No short url') {
                 $contentTypeUri = $uri;
             }
             $content_type = SnifferHelper::getContentTypeFromUri($contentTypeUri);
             $title = '(not a web page, content type: ' . $content_type . ')';
             if ($content_type == 'text/html') {
                 $title = SnifferHelper::getTitleFromUri($uri);
             }
         } catch (PageTitleDoesNotExistException $e) {
             $title = '(Page title not found or empty. Put that in your pipe and smoke it.)';
         } catch (ContentTypeNotFoundException $e) {
             return;
         } catch (GuzzleException $e) {
             $title = '(link was unresponsive: ' . $uri . ')';
         }
         if (!empty($title) && !empty($shortUri)) {
             $this->uriCache->addCacheItem($uri, $title, $shortUri);
         }
     } else {
         $title = $cacheItem->getTitle();
         $shortUri = $cacheItem->getShortUri();
     }
     if (empty($shortUri) || empty($title)) {
         return;
     }
     $connection = $this->getModule('Connection');
     $connection->write($connection->getGenerator()->ircNotice($target, '[' . $shortUri . '] ' . $title));
 }
示例#4
0
 public function parseCommands(IrcDataObject $data)
 {
     $configuration = $this->getModulePool()->get('Configuration');
     $command = '([a-zA-Z0-9]+)';
     $params = '(?: (.+))?';
     $tests = [$configuration->get('nick') . "[^a-zA-Z0-9]+{$command}{$params}", preg_quote($configuration->get('prefix')) . "{$command}{$params}"];
     $command = '';
     $params = '';
     foreach ($tests as $test) {
         if (preg_match('/^' . $test . '/', $data->getParams()['text'], $out) === false || empty($out)) {
             continue;
         }
         $command = strtolower($out[1]);
         // Done like this as to not cause an exception.
         $params = array_key_exists(2, $out) ? $out[2] : '';
         break;
     }
     if (empty($command)) {
         return;
     }
     $this->getEventEmitter()->emit('irc.command', [$command, $params, $data]);
     $this->getEventEmitter()->emit('irc.command.' . $command, [$command, $params, $data]);
 }
 public function channelJoined(IrcDataObject $object)
 {
     $channel = $object->getParams()[1];
     $this->getEventEmitter()->emit('irc.channel.joined', [$channel]);
 }
示例#6
0
 public function accountNotifyWatcher(IrcDataObject $object)
 {
     $nickname = $object->getMessage()['nick'];
     $accountname = trim($object->getParams());
     $this->accountMap[$nickname] = $accountname;
 }