private function getResult(Message $message) : \Generator { $pattern = strtr(implode(' ', $message->getParameters()), '::', '.'); $url = 'http://php.net/manual-lookup.php?scope=quickref&pattern=' . rawurlencode($pattern); $response = (yield from $this->chatClient->request($url)); if ($response->getPreviousResponse() !== null) { yield from $this->chatClient->postMessage($this->getMessageFromMatch($response)); } else { yield from $this->chatClient->postMessage(yield from $this->getMessageFromSearch($response)); } }
private function getResponse(Message $message) : string { $text = $this->normalize($message->getText()); foreach ($this->matches as $match) { if ($this->textDoesMatch($match['insult'], $text)) { return $match['response']['text'] . 'first'; } if ($this->textDoesMatch($match['response'], $text)) { return $match['insult']['text'] . 'second'; } } }
private function postNoResult(Message $message) : \Generator { yield from $this->chatClient->postMessage(sprintf(':%s %s', $message->getOrigin(), 'Sorry I couldn\'t find that page.')); }
private function getResult(Message $message) : \Generator { $response = (yield from $this->chatClient->request('http://www.imdb.com/xml/find?xml=1&nr=1&tt=on&q=' . rawurlencode(implode(' ', $message->getParameters())))); yield from $this->chatClient->postMessage($this->getMessage($response)); }
private function getResult(Message $message) : \Generator { $response = (yield from $this->chatClient->request('http://api.urbandictionary.com/v0/define?term=' . rawurlencode(implode('%20', $message->getParameters())))); $result = json_decode($response->getBody(), true); yield from $this->chatClient->postMessage($this->getMessage($result)); }