Exemplo n.º 1
0
 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']);
 }
Exemplo n.º 2
0
 public function amiauthorizedCommand($command, $params, IrcDataObject $object)
 {
     $user = !empty($params) ? trim($params) : $object->getMessage()['nick'];
     $channel = $object->getTargets()[0];
     $authorized = $this->parent->nicknameIsTrusted($user);
     $message = $authorized ? $user . ' is authorized.' : $user . ' is NOT authorized.';
     $connection = $this->parent->getModule('Connection');
     $connection->write($connection->getGenerator()->ircPrivmsg($channel, $message));
 }
Exemplo n.º 3
0
 public function onCanAuthenticate(IrcDataObject $resource)
 {
     if (trim($resource->getIrcMessage()) != 'AUTHENTICATE +') {
         return;
     }
     $configuration = $this->getModule('Configuration');
     $saslHive = $configuration->get('sasl');
     $string = base64_encode($saslHive['user'] . "" . $saslHive['user'] . "" . $saslHive['password']);
     $this->connection->write('AUTHENTICATE ' . $string . "\r\n");
     $this->authenticationComplete = true;
     $logger = $this->getModule('Logger');
     $logger->debug('Stage 3 SASL complete; Authentication complete; Awaiting result.');
 }
Exemplo n.º 4
0
 public function partCommand($command, $params, IrcDataObject $data)
 {
     $auth = $this->parent->getModule('Auth');
     if (!$auth->nicknameIsTrusted($data->getMessage()['nick'])) {
         return;
     }
     $channel = !empty($params) ? $params : $data->getTargets()[0];
     if (!Validation::isChannelName($channel) || !$this->parent->isInChannel($channel)) {
         return;
     }
     $connection = $this->parent->getModule('Connection');
     $connection->write($connection->getGenerator()->ircPart($channel));
 }
 /**
  * @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);
 }
Exemplo n.º 6
0
 /**
  * @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));
 }
Exemplo n.º 7
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]);
 }
Exemplo n.º 8
0
 /**
  * The wiki command itself.
  * @param IrcDataObject $data The data received.
  */
 public function wikiCommand($command, $params, IrcDataObject $data)
 {
     $params = trim($params);
     $user = $data->getMessage()['nick'];
     if (preg_match('/ @ ([\\S]+)$/', $params, $out) && !empty($out[1])) {
         $user = $out[1];
         $params = preg_replace('/ @ ([\\S]+)$/', '', $params);
     }
     // Merge multiple spaces into one, trim the result, urlencode it.
     $query = urlencode(trim(preg_replace('/\\s\\s+/', ' ', $params)));
     $url = $this->wikiURL . '/api.php?' . 'action=opensearch' . '&limit=1&namespace=0' . '&format=json&redirects=resolve&search=';
     $bodyResource = Remote::getUriBody($url . $query);
     $contents = $bodyResource->getContents();
     $result = json_decode($contents);
     $connection = $this->getModule('Connection');
     if ($result === false || empty($result[1])) {
         $connection->write($connection->getGenerator()->ircPrivmsg($data->getTargets()[0], $user . ': Sorry, I could not find a page matching your query. Please try again.'));
         return;
     }
     // OpenSearch API
     $title = $result[1][0];
     $link = $result[3][0];
     $connection->write($connection->getGenerator()->ircPrivmsg($data->getTargets()[0], $user . ': ' . $title . ' - ' . $link));
 }
 public function channelJoined(IrcDataObject $object)
 {
     $channel = $object->getParams()[1];
     $this->getEventEmitter()->emit('irc.channel.joined', [$channel]);
 }
Exemplo n.º 10
0
 public function accountNotifyWatcher(IrcDataObject $object)
 {
     $nickname = $object->getMessage()['nick'];
     $accountname = trim($object->getParams());
     $this->accountMap[$nickname] = $accountname;
 }
Exemplo n.º 11
0
 public function keywordListener($command, $params, IrcDataObject $data)
 {
     $sourcePool = $this->getSourcePool();
     $originChannel = $data->getTargets()[0];
     if (!$sourcePool->sourceKeyExists($command)) {
         return;
     }
     $paramData = $this->parseParams($params);
     if (empty($params) || empty($paramData)) {
         $this->replyToChannel($originChannel, 'Invalid parameters. Usage: ' . $command . ' [search term] (@ [user])');
         return;
     }
     $this->handleResult($command, $paramData['search'], $originChannel, $paramData['user']);
 }
Exemplo n.º 12
0
 public function get($command, $params, IrcDataObject $object)
 {
     $channel = $object->getTargets()[0];
     $channelStorage = $this->getChannelStorage($channel);
     $value = $channelStorage->get($command);
     if (!$value) {
         $value = $this->globalStorage->get($command);
     }
     if (!$value) {
         return;
     }
     $connection = $this->getModule('Connection');
     $connection->write($connection->getGenerator()->ircPrivmsg($channel, $value));
 }