@@ -10,7 +10,6 @@ |
||
10 | 10 | use Nopolabs\Yabot\Plugins\Giphy\GiphyService; |
11 | 11 | use Nopolabs\Yabot\Plugins\Rss\RssService; |
12 | 12 | use Psr\Log\LoggerInterface; |
13 | -use React\EventLoop\LoopInterface; |
|
14 | 13 | |
15 | 14 | class NytPlugin implements PluginInterface |
16 | 15 | { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $this->rssService |
51 | 51 | ->fetch($url) |
52 | 52 | ->then( |
53 | - function ($rss) use ($msg, $n) { |
|
53 | + function($rss) use ($msg, $n) { |
|
54 | 54 | $items = $rss->channel->item; |
55 | 55 | $n = min($n, count($items)); |
56 | 56 | $format = $this->get('format', 'fixed_height'); |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | $this->giphyService |
60 | 60 | ->search($title, $format) |
61 | 61 | ->then( |
62 | - function (string $gifUrl) use ($msg, $title, $i) { |
|
62 | + function(string $gifUrl) use ($msg, $title, $i) { |
|
63 | 63 | $msg->reply("<$gifUrl|$i: $title>"); |
64 | 64 | }, |
65 | - function (Exception $e) { |
|
65 | + function(Exception $e) { |
|
66 | 66 | $this->getLog()->warning($e->getMessage()); |
67 | 67 | } |
68 | 68 | ); |
69 | 69 | } |
70 | 70 | }, |
71 | - function (Exception $e) { |
|
71 | + function(Exception $e) { |
|
72 | 72 | $this->getLog()->warning($e->getMessage()); |
73 | 73 | } |
74 | 74 | ); |
@@ -71,7 +71,7 @@ |
||
71 | 71 | |
72 | 72 | $sink = new BufferedSink(); |
73 | 73 | $request->pipe($sink); |
74 | - $sink->promise()->then(function ($data) use ($response) { |
|
74 | + $sink->promise()->then(function($data) use ($response) { |
|
75 | 75 | if (mb_parse_str($data, $result)) { |
76 | 76 | $from = $result['From']; |
77 | 77 | $body = $result['Body']; |
@@ -52,7 +52,7 @@ |
||
52 | 52 | $this->getLog()->info($url); |
53 | 53 | |
54 | 54 | return $this->getAsync($url)->then( |
55 | - function (ResponseInterface $response) use ($format) { |
|
55 | + function(ResponseInterface $response) use ($format) { |
|
56 | 56 | return $this->extractGifUrl($format, $response); |
57 | 57 | } |
58 | 58 | ); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public function fetchRaw(string $url) : PromiseInterface |
37 | 37 | { |
38 | 38 | return $this->getAsync($url)->then( |
39 | - function (ResponseInterface $response) { |
|
39 | + function(ResponseInterface $response) { |
|
40 | 40 | return $response->getBody(); |
41 | 41 | } |
42 | 42 | ); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function fetchXml(string $url) : PromiseInterface |
46 | 46 | { |
47 | 47 | return $this->getAsync($url)->then( |
48 | - function (ResponseInterface $response) { |
|
48 | + function(ResponseInterface $response) { |
|
49 | 49 | $data = $response->getBody(); |
50 | 50 | $options = $this->get('SimpleXMLElementOptions', 0); |
51 | 51 | return new SimpleXMLElement($data, $options); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function fetchJson(string $url) : PromiseInterface |
57 | 57 | { |
58 | 58 | return $this->getAsync($url)->then( |
59 | - function (ResponseInterface $response) { |
|
59 | + function(ResponseInterface $response) { |
|
60 | 60 | $data = $response->getBody(); |
61 | 61 | $xmlOptions = $this->get('SimpleXMLElementOptions', 0); |
62 | 62 | $xml = new SimpleXMLElement($data, $xmlOptions); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function fetch(string $url) : PromiseInterface |
70 | 70 | { |
71 | 71 | return $this->getAsync($url)->then( |
72 | - function (ResponseInterface $response) { |
|
72 | + function(ResponseInterface $response) { |
|
73 | 73 | $data = $response->getBody(); |
74 | 74 | $xmlOptions = $this->get('SimpleXMLElementOptions', 0); |
75 | 75 | $xml = new SimpleXMLElement($data, $xmlOptions); |
@@ -40,7 +40,7 @@ |
||
40 | 40 | $url = $matches['url']; |
41 | 41 | |
42 | 42 | $this->rssService->fetchJson($url)->then( |
43 | - function (string $json) use ($msg) { |
|
43 | + function(string $json) use ($msg) { |
|
44 | 44 | $msg->reply($json); |
45 | 45 | } |
46 | 46 | ); |
@@ -53,6 +53,9 @@ discard block |
||
53 | 53 | $this->respond($msg); |
54 | 54 | } |
55 | 55 | |
56 | + /** |
|
57 | + * @param string $force |
|
58 | + */ |
|
56 | 59 | private function respond(Message $msg, $force = null) |
57 | 60 | { |
58 | 61 | $url = $this->url($force); |
@@ -67,6 +70,9 @@ discard block |
||
67 | 70 | ); |
68 | 71 | } |
69 | 72 | |
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
70 | 76 | private function url($force = null) |
71 | 77 | { |
72 | 78 | $query = $force ? "?force=$force" : ''; |
@@ -58,7 +58,7 @@ |
||
58 | 58 | $url = $this->url($force); |
59 | 59 | $this->guzzle->getAsync($url) |
60 | 60 | ->then( |
61 | - function (ResponseInterface $response) use ($msg) { |
|
61 | + function(ResponseInterface $response) use ($msg) { |
|
62 | 62 | $json = $response->getBody(); |
63 | 63 | $rsp = json_decode($json); |
64 | 64 |
@@ -54,7 +54,7 @@ |
||
54 | 54 | |
55 | 55 | $this->postAsync($url, ['body' => '{"query": "query { viewer { login }}"}']) |
56 | 56 | ->then( |
57 | - function (ResponseInterface $response) use ($msg) { |
|
57 | + function(ResponseInterface $response) use ($msg) { |
|
58 | 58 | $json = $response->getBody(); |
59 | 59 | $msg->reply($json); |
60 | 60 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | { |
67 | 67 | if (trim($matches[1]) === 'formats') { |
68 | 68 | $formats = $this->getFormats(); |
69 | - $msg->reply('Available formats: ' . implode(' ', $formats)); |
|
69 | + $msg->reply('Available formats: '.implode(' ', $formats)); |
|
70 | 70 | $msg->setHandled(true); |
71 | 71 | return; |
72 | 72 | } |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | $format = $this->getFormat($terms); |
77 | 77 | |
78 | 78 | $this->giphyService->search($query, $format)->then( |
79 | - function (string $gifUrl) use ($msg) { |
|
79 | + function(string $gifUrl) use ($msg) { |
|
80 | 80 | $msg->reply($gifUrl); |
81 | 81 | }, |
82 | - function (Exception $e) { |
|
82 | + function(Exception $e) { |
|
83 | 83 | $this->getLog()->warning($e->getMessage()); |
84 | 84 | } |
85 | 85 | ); |