@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @author Stefano Bianchini |
16 | 16 | * @website http://www.stefanobianchini.net |
17 | 17 | */ |
18 | -class Weather_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
|
18 | +class Weather_plugin implements \JarvisPHP\Core\JarvisPluginInterface { |
|
19 | 19 | /** |
20 | 20 | * Priority of plugin |
21 | 21 | * @var int |
@@ -38,40 +38,40 @@ discard block |
||
38 | 38 | $_OPENWEATHERMAP_API_KEY = ''; |
39 | 39 | |
40 | 40 | //Load API key from json config |
41 | - if(file_exists('Plugins/Weather_plugin/api-key.json')) { |
|
41 | + if (file_exists('Plugins/Weather_plugin/api-key.json')) { |
|
42 | 42 | //Create your own api key and put it in api-key.json |
43 | 43 | $json_config = json_decode(file_get_contents('Plugins/Weather_plugin/api-key.json')); |
44 | 44 | $_OPENWEATHERMAP_API_KEY = $json_config->openweathermap_key; |
45 | 45 | } |
46 | 46 | |
47 | 47 | try { |
48 | - $forecast = $owm->getWeatherForecast('Rimini', 'metric', _LANGUAGE, $_OPENWEATHERMAP_API_KEY,2); |
|
49 | - } catch(OWMException $e) { |
|
50 | - JarvisPHP::getLogger()->error('OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); |
|
51 | - $answer = JarvisLanguage::translate('weather_error',get_called_class()); |
|
52 | - } catch(\Exception $e) { |
|
53 | - JarvisPHP::getLogger()->error('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); |
|
54 | - $answer = JarvisLanguage::translate('weather_error',get_called_class()); |
|
48 | + $forecast = $owm->getWeatherForecast('Rimini', 'metric', _LANGUAGE, $_OPENWEATHERMAP_API_KEY, 2); |
|
49 | + } catch (OWMException $e) { |
|
50 | + JarvisPHP::getLogger()->error('OpenWeatherMap exception: '.$e->getMessage().' (Code '.$e->getCode().').'); |
|
51 | + $answer = JarvisLanguage::translate('weather_error', get_called_class()); |
|
52 | + } catch (\Exception $e) { |
|
53 | + JarvisPHP::getLogger()->error('General exception: '.$e->getMessage().' (Code '.$e->getCode().').'); |
|
54 | + $answer = JarvisLanguage::translate('weather_error', get_called_class()); |
|
55 | 55 | } |
56 | 56 | |
57 | - if(preg_match(JarvisLanguage::translate('preg_match_today',get_called_class()), $command)) { |
|
58 | - $answer = JarvisLanguage::translate('forecast_for_today',get_called_class()); |
|
57 | + if (preg_match(JarvisLanguage::translate('preg_match_today', get_called_class()), $command)) { |
|
58 | + $answer = JarvisLanguage::translate('forecast_for_today', get_called_class()); |
|
59 | 59 | foreach ($forecast as $weather) { |
60 | - if($weather->time->day->format('d.m.Y')==date('d.m.Y')) { |
|
61 | - $answer.=JarvisLanguage::translate('from',get_called_class()) . " " .$weather->time->from->format('H:i') . " ". JarvisLanguage::translate('to',get_called_class()) . " " . $weather->time->to->format('H:i').": "; |
|
62 | - $answer.=$weather->weather->description." ".sprintf(JarvisLanguage::translate('temperature',get_called_class()),trim(str_replace('°C','',$weather->temperature))); |
|
60 | + if ($weather->time->day->format('d.m.Y') == date('d.m.Y')) { |
|
61 | + $answer .= JarvisLanguage::translate('from', get_called_class())." ".$weather->time->from->format('H:i')." ".JarvisLanguage::translate('to', get_called_class())." ".$weather->time->to->format('H:i').": "; |
|
62 | + $answer .= $weather->weather->description." ".sprintf(JarvisLanguage::translate('temperature', get_called_class()), trim(str_replace('°C', '', $weather->temperature))); |
|
63 | 63 | } |
64 | 64 | } |
65 | - } else if(preg_match(JarvisLanguage::translate('preg_match_tomorrow',get_called_class()), $command)) { |
|
66 | - $answer = JarvisLanguage::translate('forecast_for_tomorrow',get_called_class()); |
|
65 | + } else if (preg_match(JarvisLanguage::translate('preg_match_tomorrow', get_called_class()), $command)) { |
|
66 | + $answer = JarvisLanguage::translate('forecast_for_tomorrow', get_called_class()); |
|
67 | 67 | foreach ($forecast as $weather) { |
68 | - if($weather->time->day->format('d.m.Y')==$tomorrow->format('d.m.Y')) { |
|
69 | - $answer.=JarvisLanguage::translate('from',get_called_class()) . " " .$weather->time->from->format('H:i') . " ". JarvisLanguage::translate('to',get_called_class()) . " " . $weather->time->to->format('H:i').": "; |
|
70 | - $answer.=$weather->weather->description." ".sprintf(JarvisLanguage::translate('temperature',get_called_class()),trim(str_replace('°C','',$weather->temperature))); |
|
68 | + if ($weather->time->day->format('d.m.Y') == $tomorrow->format('d.m.Y')) { |
|
69 | + $answer .= JarvisLanguage::translate('from', get_called_class())." ".$weather->time->from->format('H:i')." ".JarvisLanguage::translate('to', get_called_class())." ".$weather->time->to->format('H:i').": "; |
|
70 | + $answer .= $weather->weather->description." ".sprintf(JarvisLanguage::translate('temperature', get_called_class()), trim(str_replace('°C', '', $weather->temperature))); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | } else { |
74 | - $answer = JarvisLanguage::translate('not_understand_weather_day',get_called_class()); |
|
74 | + $answer = JarvisLanguage::translate('not_understand_weather_day', get_called_class()); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return boolean |
96 | 96 | */ |
97 | 97 | function isLikely($command) { |
98 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
98 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace JarvisPHP\Plugins\Wemo_plugin; |
4 | 4 | |
5 | -use JarvisPHP\Core\JarvisSession; |
|
6 | 5 | use JarvisPHP\Core\JarvisPHP; |
7 | 6 | use JarvisPHP\Core\JarvisLanguage; |
8 | 7 | use JarvisPHP\Core\JarvisTTS; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Stefano Bianchini |
13 | 13 | * @website http://www.stefanobianchini.net |
14 | 14 | */ |
15 | -class Echo_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
|
15 | +class Echo_plugin implements \JarvisPHP\Core\JarvisPluginInterface { |
|
16 | 16 | /** |
17 | 17 | * Priority of plugin |
18 | 18 | * @var int |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function answer($command) { |
27 | 27 | $answer = ''; |
28 | - if(JarvisSession::get('echo_not_first_passage')) { |
|
28 | + if (JarvisSession::get('echo_not_first_passage')) { |
|
29 | 29 | $answer = $command; |
30 | 30 | } else { |
31 | - JarvisSession::set('echo_not_first_passage',true); |
|
31 | + JarvisSession::set('echo_not_first_passage', true); |
|
32 | 32 | JarvisPHP::getLogger()->debug('Answering to command: "'.$command.'"'); |
33 | - $answer = JarvisLanguage::translate('let_s_play',get_called_class()); |
|
33 | + $answer = JarvisLanguage::translate('let_s_play', get_called_class()); |
|
34 | 34 | } |
35 | 35 | JarvisTTS::speak($answer); |
36 | 36 | $response = new \JarvisPHP\Core\JarvisResponse($answer, JarvisPHP::getRealClassName(get_called_class()), true); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @return boolean |
52 | 52 | */ |
53 | 53 | function isLikely($command) { |
54 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
54 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Stefano Bianchini |
13 | 13 | * @website http://www.stefanobianchini.net |
14 | 14 | */ |
15 | -class Movie_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
|
15 | +class Movie_plugin implements \JarvisPHP\Core\JarvisPluginInterface { |
|
16 | 16 | /** |
17 | 17 | * Priority of plugin |
18 | 18 | * @var int |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | JarvisPHP::getLogger()->debug('Answering to command: "'.$command.'"'); |
29 | 29 | |
30 | 30 | //Understand the movie |
31 | - preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command, $matches); |
|
31 | + preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command, $matches); |
|
32 | 32 | |
33 | 33 | $movie_title = end($matches); |
34 | 34 | |
35 | 35 | $_THEMOVIEDB_API_KEY = ''; |
36 | 36 | |
37 | 37 | //Load API key from json config |
38 | - if(file_exists('Plugins/Movie_plugin/api-key.json')) { |
|
38 | + if (file_exists('Plugins/Movie_plugin/api-key.json')) { |
|
39 | 39 | //Create your own api key and put it in api-key.json |
40 | 40 | $json_config = json_decode(file_get_contents('Plugins/Movie_plugin/api-key.json')); |
41 | 41 | $_THEMOVIEDB_API_KEY = $json_config->themoviedb_key; |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | |
47 | 47 | $result = $client->getSearchApi()->searchMovies($movie_title, ['language'=>_LANGUAGE, 'page'=>1]); |
48 | 48 | |
49 | - if(count($result['results'])>0) { |
|
50 | - $answer = ($result['results'][0]['overview']) ? ($result['results'][0]['overview']) : JarvisLanguage::translate('no_results',get_called_class()); |
|
49 | + if (count($result['results']) > 0) { |
|
50 | + $answer = ($result['results'][0]['overview']) ? ($result['results'][0]['overview']) : JarvisLanguage::translate('no_results', get_called_class()); |
|
51 | 51 | } else { |
52 | 52 | //No results |
53 | - $answer = JarvisLanguage::translate('no_results',get_called_class()); |
|
53 | + $answer = JarvisLanguage::translate('no_results', get_called_class()); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | JarvisTTS::speak($answer); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @return boolean |
73 | 73 | */ |
74 | 74 | function isLikely($command) { |
75 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
75 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace JarvisPHP\Plugins\Wemo_plugin; |
4 | 4 | |
5 | -use JarvisPHP\Core\JarvisSession; |
|
6 | 5 | use JarvisPHP\Core\JarvisPHP; |
7 | 6 | use JarvisPHP\Core\JarvisLanguage; |
8 | 7 | use JarvisPHP\Core\JarvisTTS; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Stefano Bianchini |
13 | 13 | * @website http://www.stefanobianchini.net |
14 | 14 | */ |
15 | -class CheckMail_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
|
15 | +class CheckMail_plugin implements \JarvisPHP\Core\JarvisPluginInterface { |
|
16 | 16 | /** |
17 | 17 | * Priority of plugin |
18 | 18 | * @var int |
@@ -27,27 +27,27 @@ discard block |
||
27 | 27 | $answer = ''; |
28 | 28 | |
29 | 29 | //Load credentials from json config |
30 | - if(file_exists('Plugins/CheckMail_plugin/credentials.json')) { |
|
30 | + if (file_exists('Plugins/CheckMail_plugin/credentials.json')) { |
|
31 | 31 | $json_config = json_decode(file_get_contents('Plugins/CheckMail_plugin/credentials.json')); |
32 | 32 | } |
33 | 33 | |
34 | - if($json_config) { |
|
34 | + if ($json_config) { |
|
35 | 35 | |
36 | 36 | $mbox = imap_open($json_config->connection_string, $json_config->user, $json_config->password, OP_READONLY); |
37 | 37 | |
38 | - $uids = imap_search($mbox, 'UNSEEN', SE_UID); |
|
38 | + $uids = imap_search($mbox, 'UNSEEN', SE_UID); |
|
39 | 39 | |
40 | - if(is_array($uids)) { |
|
41 | - $answer = sprintf(JarvisLanguage::translate('you_have_new_messages',get_called_class()), count($uids)); |
|
40 | + if (is_array($uids)) { |
|
41 | + $answer = sprintf(JarvisLanguage::translate('you_have_new_messages', get_called_class()), count($uids)); |
|
42 | 42 | } else { |
43 | - $answer = JarvisLanguage::translate('no_messages',get_called_class()); |
|
43 | + $answer = JarvisLanguage::translate('no_messages', get_called_class()); |
|
44 | 44 | } |
45 | 45 | |
46 | - if(preg_match(JarvisLanguage::translate('preg_match_read',get_called_class()), $command) && is_array($uids)) { |
|
46 | + if (preg_match(JarvisLanguage::translate('preg_match_read', get_called_class()), $command) && is_array($uids)) { |
|
47 | 47 | //Read last message |
48 | 48 | $result = imap_fetch_overview($mbox, end($uids), FT_UID); |
49 | 49 | $mail = end($result); |
50 | - $answer = JarvisLanguage::translate('from',get_called_class()).': '.$mail->from.'. '.JarvisLanguage::translate('subject',get_called_class()).': '.imap_utf8($mail->subject); |
|
50 | + $answer = JarvisLanguage::translate('from', get_called_class()).': '.$mail->from.'. '.JarvisLanguage::translate('subject', get_called_class()).': '.imap_utf8($mail->subject); |
|
51 | 51 | JarvisSession::terminate(); |
52 | 52 | } |
53 | 53 | imap_close($mbox); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @return boolean |
72 | 72 | */ |
73 | 73 | function isLikely($command) { |
74 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
74 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | |
30 | 30 | $BASE_URL = "http://query.yahooapis.com/v1/public/yql"; |
31 | 31 | $yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="'.$this->place.'") and u="c"'; |
32 | - $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json"; |
|
32 | + $yql_query_url = $BASE_URL."?q=".urlencode($yql_query)."&format=json"; |
|
33 | 33 | |
34 | 34 | // Make call with cURL |
35 | 35 | $session = curl_init($yql_query_url); |
36 | - curl_setopt($session, CURLOPT_RETURNTRANSFER,true); |
|
36 | + curl_setopt($session, CURLOPT_RETURNTRANSFER, true); |
|
37 | 37 | $json = curl_exec($session); |
38 | 38 | // Convert JSON to PHP object |
39 | - $phpObj = json_decode($json); |
|
40 | - $answer = sprintf(JarvisLanguage::translate('actual_temperature_outside_is',get_called_class()),$phpObj->query->results->channel->item->condition->temp, $phpObj->query->results->channel->atmosphere->humidity); |
|
39 | + $phpObj = json_decode($json); |
|
40 | + $answer = sprintf(JarvisLanguage::translate('actual_temperature_outside_is', get_called_class()), $phpObj->query->results->channel->item->condition->temp, $phpObj->query->results->channel->atmosphere->humidity); |
|
41 | 41 | JarvisTTS::speak($answer); |
42 | 42 | $response = new \JarvisPHP\Core\JarvisResponse($answer, JarvisPHP::getRealClassName(get_called_class()), true); |
43 | 43 | $response->send(); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @return boolean |
59 | 59 | */ |
60 | 60 | function isLikely($command) { |
61 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
61 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace JarvisPHP\Plugins\Wemo_plugin; |
4 | 4 | |
5 | -use JarvisPHP\Core\JarvisSession; |
|
6 | 5 | use JarvisPHP\Core\JarvisPHP; |
7 | 6 | use JarvisPHP\Core\JarvisLanguage; |
8 | 7 | use JarvisPHP\Core\JarvisTTS; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Stefano Bianchini |
13 | 13 | * @website http://www.stefanobianchini.net |
14 | 14 | */ |
15 | -class Hello_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
|
15 | +class Hello_plugin implements \JarvisPHP\Core\JarvisPluginInterface { |
|
16 | 16 | /** |
17 | 17 | * Priority of plugin |
18 | 18 | * @var int |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | $answer = ''; |
28 | 28 | JarvisPHP::getLogger()->debug('Answering to command: "'.$command.'"'); |
29 | 29 | $hour = date("H"); |
30 | - if($hour>5 && $hour<=13) { |
|
30 | + if ($hour > 5 && $hour <= 13) { |
|
31 | 31 | //Morning |
32 | - $answer = JarvisLanguage::translate('hello_morning',get_called_class()); |
|
32 | + $answer = JarvisLanguage::translate('hello_morning', get_called_class()); |
|
33 | 33 | } |
34 | - else if($hour>13 && $hour<18) { |
|
34 | + else if ($hour > 13 && $hour < 18) { |
|
35 | 35 | //Afternoon |
36 | - $answer = JarvisLanguage::translate('hello_afternoon',get_called_class()); |
|
36 | + $answer = JarvisLanguage::translate('hello_afternoon', get_called_class()); |
|
37 | 37 | } else { |
38 | 38 | //Evening (and night, of course) |
39 | - $answer = JarvisLanguage::translate('hello_evening',get_called_class()); |
|
39 | + $answer = JarvisLanguage::translate('hello_evening', get_called_class()); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @return boolean |
60 | 60 | */ |
61 | 61 | function isLikely($command) { |
62 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
62 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -30,8 +30,7 @@ |
||
30 | 30 | if($hour>5 && $hour<=13) { |
31 | 31 | //Morning |
32 | 32 | $answer = JarvisLanguage::translate('hello_morning',get_called_class()); |
33 | - } |
|
34 | - else if($hour>13 && $hour<18) { |
|
33 | + } else if($hour>13 && $hour<18) { |
|
35 | 34 | //Afternoon |
36 | 35 | $answer = JarvisLanguage::translate('hello_afternoon',get_called_class()); |
37 | 36 | } else { |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace JarvisPHP\Plugins\Wemo_plugin; |
4 | 4 | |
5 | -use JarvisPHP\Core\JarvisSession; |
|
6 | 5 | use JarvisPHP\Core\JarvisPHP; |
7 | 6 | use JarvisPHP\Core\JarvisLanguage; |
8 | 7 | use JarvisPHP\Core\JarvisTTS; |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | function answer($command) { |
27 | 27 | |
28 | 28 | $start_vlc = false; |
29 | - $stream_url=''; |
|
30 | - $answer='nothing done'; |
|
29 | + $stream_url = ''; |
|
30 | + $answer = 'nothing done'; |
|
31 | 31 | |
32 | 32 | $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
33 | 33 | |
34 | - if(preg_match(JarvisLanguage::translate('preg_match_relax_music',get_called_class()), $command)) { |
|
34 | + if (preg_match(JarvisLanguage::translate('preg_match_relax_music', get_called_class()), $command)) { |
|
35 | 35 | $stream_url = 'http://pub4.radiotunes.com:80/radiotunes_relaxation_aacplus.flv'; |
36 | 36 | JarvisPHP::getLogger()->debug('Playing relaxation'); |
37 | 37 | $start_vlc = true; |
38 | 38 | } |
39 | - if(preg_match(JarvisLanguage::translate('preg_match_lounge_music',get_called_class()), $command)) { |
|
39 | + if (preg_match(JarvisLanguage::translate('preg_match_lounge_music', get_called_class()), $command)) { |
|
40 | 40 | $stream_url = 'http://pub4.radiotunes.com:80/radiotunes_smoothlounge_aacplus.flv'; |
41 | 41 | JarvisPHP::getLogger()->debug('Playing lounge'); |
42 | 42 | $start_vlc = true; |
43 | 43 | } |
44 | - if(preg_match(JarvisLanguage::translate('preg_match_jazz_music',get_called_class()), $command)) { |
|
44 | + if (preg_match(JarvisLanguage::translate('preg_match_jazz_music', get_called_class()), $command)) { |
|
45 | 45 | $stream_url = 'http://pub4.radiotunes.com:80/radiotunes_smoothjazz_aacplus.flv'; |
46 | 46 | JarvisPHP::getLogger()->debug('Playing jazz'); |
47 | 47 | $start_vlc = true; |
48 | 48 | } |
49 | - if(preg_match(JarvisLanguage::translate('preg_match_stop',get_called_class()), $command)) { |
|
49 | + if (preg_match(JarvisLanguage::translate('preg_match_stop', get_called_class()), $command)) { |
|
50 | 50 | $result = @socket_connect($socket, 'localhost', 9999); |
51 | 51 | if ($result === false) { |
52 | 52 | //Error handling |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | $start_vlc = false; |
65 | 65 | } |
66 | - if($start_vlc) { |
|
66 | + if ($start_vlc) { |
|
67 | 67 | //Start Vlc on port 9999 |
68 | 68 | //exec('vlc -I rc --rc-host localhost:9999'); |
69 | 69 | @exec('/usr/bin/nohup /usr/bin/vlc -I rc --rc-host localhost:9999 &'); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return boolean |
105 | 105 | */ |
106 | 106 | function isLikely($command) { |
107 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
107 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | //Error handling |
53 | 53 | JarvisPHP::getLogger()->warn('Failed to connect!'); |
54 | 54 | $answer = 'Failed to connect!'; |
55 | - } |
|
56 | - else { |
|
55 | + } else { |
|
57 | 56 | $vlc_remote_command = 'stop'.chr(13); |
58 | 57 | $vlc_remote_command = 'quit'.chr(13); |
59 | 58 | socket_write($socket, $vlc_remote_command, strlen($vlc_remote_command)); |
@@ -75,8 +74,7 @@ discard block |
||
75 | 74 | //Error handling |
76 | 75 | JarvisPHP::getLogger()->warn('Failed to connect!'); |
77 | 76 | $answer = 'Failed to connect!'; |
78 | - } |
|
79 | - else { |
|
77 | + } else { |
|
80 | 78 | $vlc_remote_command = 'add '.$stream_url.chr(13); |
81 | 79 | socket_write($socket, $vlc_remote_command, strlen($vlc_remote_command)); |
82 | 80 | socket_close($socket); |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -2,10 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace JarvisPHP\Plugins\RaspPIVolume_plugin; |
4 | 4 | |
5 | -use JarvisPHP\Core\JarvisSession; |
|
6 | 5 | use JarvisPHP\Core\JarvisPHP; |
7 | 6 | use JarvisPHP\Core\JarvisLanguage; |
8 | -use JarvisPHP\Core\JarvisTTS; |
|
9 | 7 | |
10 | 8 | /** |
11 | 9 | * RaspberryPI Volume Control Plugin |
@@ -5,20 +5,20 @@ discard block |
||
5 | 5 | define('CREDENTIALS_PATH', 'api-key.json'); |
6 | 6 | define('CLIENT_SECRET_PATH', 'secret-client-key.json'); |
7 | 7 | define('SCOPES', implode(' ', array( |
8 | - \Google_Service_Calendar::CALENDAR_READONLY) |
|
8 | + \Google_Service_Calendar::CALENDAR_READONLY) |
|
9 | 9 | )); |
10 | 10 | |
11 | - $client = new Google_Client(); |
|
12 | - $client->setApplicationName(APPLICATION_NAME); |
|
13 | - $client->setScopes(SCOPES); |
|
14 | - $client->setAuthConfigFile(CLIENT_SECRET_PATH); |
|
15 | - $client->setAccessType('offline'); |
|
11 | + $client = new Google_Client(); |
|
12 | + $client->setApplicationName(APPLICATION_NAME); |
|
13 | + $client->setScopes(SCOPES); |
|
14 | + $client->setAuthConfigFile(CLIENT_SECRET_PATH); |
|
15 | + $client->setAccessType('offline'); |
|
16 | 16 | |
17 | - // Load previously authorized credentials from a file. |
|
18 | - $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); |
|
19 | - if (file_exists($credentialsPath)) { |
|
17 | + // Load previously authorized credentials from a file. |
|
18 | + $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); |
|
19 | + if (file_exists($credentialsPath)) { |
|
20 | 20 | $accessToken = file_get_contents($credentialsPath); |
21 | - } else { |
|
21 | + } else { |
|
22 | 22 | // Request authorization from the user. |
23 | 23 | $authUrl = $client->createAuthUrl(); |
24 | 24 | printf("Open the following link in your browser:\n%s\n", $authUrl); |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | |
31 | 31 | // Store the credentials to disk. |
32 | 32 | if(!file_exists(dirname($credentialsPath))) { |
33 | - mkdir(dirname($credentialsPath), 0700, true); |
|
33 | + mkdir(dirname($credentialsPath), 0700, true); |
|
34 | 34 | } |
35 | 35 | file_put_contents($credentialsPath, $accessToken); |
36 | 36 | printf("Credentials saved to %s\n", $credentialsPath); |
37 | - } |
|
38 | - $client->setAccessToken($accessToken); |
|
37 | + } |
|
38 | + $client->setAccessToken($accessToken); |
|
39 | 39 | |
40 | - // Refresh the token if it's expired. |
|
41 | - if ($client->isAccessTokenExpired()) { |
|
40 | + // Refresh the token if it's expired. |
|
41 | + if ($client->isAccessTokenExpired()) { |
|
42 | 42 | $client->refreshToken($client->getRefreshToken()); |
43 | 43 | file_put_contents($credentialsPath, $client->getAccessToken()); |
44 | - } |
|
44 | + } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | $accessToken = $client->authenticate($authCode); |
30 | 30 | |
31 | 31 | // Store the credentials to disk. |
32 | - if(!file_exists(dirname($credentialsPath))) { |
|
32 | + if (!file_exists(dirname($credentialsPath))) { |
|
33 | 33 | mkdir(dirname($credentialsPath), 0700, true); |
34 | 34 | } |
35 | 35 | file_put_contents($credentialsPath, $accessToken); |
@@ -28,8 +28,8 @@ |
||
28 | 28 | //Extract search term |
29 | 29 | preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command, $matches); |
30 | 30 | $search_term = $matches[2]; |
31 | - $wiki_query_url = _WIKI_URL . "?action=opensearch&search=" . urlencode($search_term) . "&format=xml&limit=5"; |
|
32 | - $xml = simplexml_load_string(file_get_contents($wiki_query_url)); |
|
31 | + $wiki_query_url = _WIKI_URL . "?action=opensearch&search=" . urlencode($search_term) . "&format=xml&limit=5"; |
|
32 | + $xml = simplexml_load_string(file_get_contents($wiki_query_url)); |
|
33 | 33 | $item_array = $xml->Section->Item; |
34 | 34 | $answer = JarvisLanguage::translate('nothing_found',get_called_class()); |
35 | 35 | //Have i got results? |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @website http://www.stefanobianchini.net |
14 | 14 | * Based on Wiki_plugin of UgoRaffaele https://github.com/UgoRaffaele/ |
15 | 15 | */ |
16 | -class InformationOn_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
|
16 | +class InformationOn_plugin implements \JarvisPHP\Core\JarvisPluginInterface { |
|
17 | 17 | /** |
18 | 18 | * Priority of plugin |
19 | 19 | * @var int |
@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | */ |
27 | 27 | function answer($command) { |
28 | 28 | //Extract search term |
29 | - preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command, $matches); |
|
29 | + preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command, $matches); |
|
30 | 30 | $search_term = $matches[2]; |
31 | - $wiki_query_url = _WIKI_URL . "?action=opensearch&search=" . urlencode($search_term) . "&format=xml&limit=5"; |
|
31 | + $wiki_query_url = _WIKI_URL."?action=opensearch&search=".urlencode($search_term)."&format=xml&limit=5"; |
|
32 | 32 | $xml = simplexml_load_string(file_get_contents($wiki_query_url)); |
33 | 33 | $item_array = $xml->Section->Item; |
34 | - $answer = JarvisLanguage::translate('nothing_found',get_called_class()); |
|
34 | + $answer = JarvisLanguage::translate('nothing_found', get_called_class()); |
|
35 | 35 | //Have i got results? |
36 | - if(count($item_array)>0) { |
|
36 | + if (count($item_array) > 0) { |
|
37 | 37 | foreach ($item_array as $item) { |
38 | 38 | if (strlen($item->Description) > 0) { |
39 | - $answer = sprintf(JarvisLanguage::translate('search_result_is',get_called_class()), $item->Description); |
|
39 | + $answer = sprintf(JarvisLanguage::translate('search_result_is', get_called_class()), $item->Description); |
|
40 | 40 | break; |
41 | 41 | } |
42 | 42 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return boolean |
61 | 61 | */ |
62 | 62 | function isLikely($command) { |
63 | - return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
63 | + return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -86,7 +86,7 @@ |
||
86 | 86 | /** |
87 | 87 | * Is it the right plugin for the command? |
88 | 88 | * @param string $command |
89 | - * @return boolean |
|
89 | + * @return integer |
|
90 | 90 | */ |
91 | 91 | function isLikely($command) { |
92 | 92 | return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace JarvisPHP\Plugins\Wemo_plugin; |
4 | 4 | |
5 | -use JarvisPHP\Core\JarvisSession; |
|
6 | 5 | use JarvisPHP\Core\JarvisPHP; |
7 | 6 | use JarvisPHP\Core\JarvisLanguage; |
8 | 7 | use JarvisPHP\Core\JarvisTTS; |