From f58fada64ccac21ccdeeb02f6326da4fb9e81531 Mon Sep 17 00:00:00 2001 From: wolfish Date: Fri, 12 Aug 2016 21:49:35 +0200 Subject: [PATCH] Titles for multi and non-image results --- README.md | 4 +++- src/Parameters.php | 5 +++++ src/Response.php | 12 ++++++++---- src/User.php | 4 +--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index df33886..f3b83e7 100755 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Also, by configuring the CSE itself you can limit searches to one site, or make - `#link` - get result as standard link - `#one` - get one result (default) - `#multi` - get multiple results (10 by default) +- `#priv` - display results only for you +- `#pub` - display results public in conversation You can of course join commands, so `/xyz #multi #20 #link best cars` gives you list of ten links of "best cars" starting from 20 result. @@ -69,7 +71,7 @@ Any feedback or code contribution that is useful is welcome. Current TODO's are: * More commands providing rest of CSE parameters -* ~~User control (allowed/banned users)~~ (mostly done) +* ~~User control (allowed/banned users)~~ (basic done) * Time/query count limitation per user * ~~Command to control `in_channel` like `#pub` and `#priv`~~ (done) diff --git a/src/Parameters.php b/src/Parameters.php index 37a1428..e525ff9 100644 --- a/src/Parameters.php +++ b/src/Parameters.php @@ -111,4 +111,9 @@ public function getSlackParameters() return $slackParams; } + + public function isImageSearch() + { + return isset($this->_request['searchType']) && ($this->_request['searchType'] === 'image'); + } } diff --git a/src/Response.php b/src/Response.php index b3bbf18..de8d6c3 100644 --- a/src/Response.php +++ b/src/Response.php @@ -15,13 +15,13 @@ public function getSlackResponse(Parameters $params) { if (count($this->_items) > 1) { foreach ($this->_items as $k => $item) { - $responseText[] = $item->getLink(); + $responseText[] = $item; if ($k == 19) { break; } // Slack limitation } } elseif ($this->_items[0] instanceof \Google_Service_Customsearch_Result) { - $responseText = $this->_items[0]->getLink(); + $responseText = $this->_items[0]; } else { $responseText = Config::GOOGLE_NO_RESULT; } @@ -31,10 +31,14 @@ public function getSlackResponse(Parameters $params) if (is_array($responseText)) { $response['text'] = Config::MULTIPLE_RESULTS_TEXT; foreach ($responseText as $num => $t) { - $response['attachments'][] = array('text' => ($num + 1).'. '.$t."\n"); + $response['attachments'][] = array('text' => ($num + 1).'. '.$t->getTitle()."\n".$t->getLink()); } } else { - $response['text'] = $responseText; + if ($params->isImageSearch()) { + $response['text'] = $responseText->getLink(); + } else { + $response['text'] = $responseText->getTitle()."\n".$responseText->getLink(); + } } return json_encode($response); diff --git a/src/User.php b/src/User.php index 4edfe4a..9956514 100644 --- a/src/User.php +++ b/src/User.php @@ -1,7 +1,6 @@