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)); }
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)); }
/** * 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)); }
/** * @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)); }
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']); }
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)); }