Skip to content

Commit

Permalink
Titles for multi and non-image results
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfish committed Aug 12, 2016
1 parent c1dee42 commit f58fada
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions src/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@ public function getSlackParameters()

return $slackParams;
}

public function isImageSearch()
{
return isset($this->_request['searchType']) && ($this->_request['searchType'] === 'image');
}
}
12 changes: 8 additions & 4 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/User.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Wolfish;

use Wolfish\Config;
namespace Wolfish;

class User
{
Expand Down Expand Up @@ -37,5 +36,4 @@ public function checkAccess()

return true;
}

}

0 comments on commit f58fada

Please sign in to comment.