Completed
Push — master ( 575823...f7fea2 )
by Stefano
02:38
created
Core/JarvisPHP.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
             $choosen_plugin = null;
126 126
             //Cycling plugins
127 127
             foreach(JarvisPHP::$active_plugins as $plugin_class) {
128
-               $plugin = new $plugin_class();
129
-               //Load plugin's languages
130
-               JarvisLanguage::loadPluginTranslation($plugin_class);
131
-               if($plugin->isLikely($command)) {
132
-                   JarvisPHP::getLogger()->debug('Maybe '.JarvisPHP::getRealClassName($plugin_class).', check priority');
133
-                   if($plugin->getPriority() > $max_priority_found) {
134
-                       $max_priority_found = $plugin->getPriority();
135
-                       $choosen_plugin = $plugin;
136
-                   }
137
-               }
128
+                $plugin = new $plugin_class();
129
+                //Load plugin's languages
130
+                JarvisLanguage::loadPluginTranslation($plugin_class);
131
+                if($plugin->isLikely($command)) {
132
+                    JarvisPHP::getLogger()->debug('Maybe '.JarvisPHP::getRealClassName($plugin_class).', check priority');
133
+                    if($plugin->getPriority() > $max_priority_found) {
134
+                        $max_priority_found = $plugin->getPriority();
135
+                        $choosen_plugin = $plugin;
136
+                    }
137
+                }
138 138
             }
139 139
             if(!is_null($choosen_plugin)) {
140 140
                 JarvisPHP::getLogger()->debug('Choosen plugin: '.JarvisPHP::getRealClassName(get_class($choosen_plugin)));
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     }
189 189
     
190 190
     public static function getNameSpace($fullClassName) {
191
-       //Explode class name
191
+        //Explode class name
192 192
         $classNameArray = explode('\\',$fullClassName);
193 193
         //Remove the pure class name
194 194
         array_pop($classNameArray);
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
             $pureClassName = JarvisPHP::getRealClassName($className);
27 27
             //Build the path
28 28
             $namespace = JarvisPHP::getNameSpace($className);
29
-            if(file_exists($namespace.'/'.$pureClassName.'.php')) {
29
+            if (file_exists($namespace.'/'.$pureClassName.'.php')) {
30 30
                 include_once($namespace.'/'.$pureClassName.'.php');
31 31
             }
32 32
         });
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
         JarvisPHP::$slim = new \Slim\Slim(array('debug' => false));
48 48
                 
49 49
         //POST /answer route
50
-        JarvisPHP::$slim->post('/answer/', function () {
50
+        JarvisPHP::$slim->post('/answer/', function() {
51 51
             //Detect if the request forces a TTS
52 52
             $ttsFromPostRequest = JarvisPHP::$slim->request->post('tts');
53
-            if(!empty($ttsFromPostRequest) && file_exists('Speakers\\'.JarvisPHP::$slim->request->post('tts').'.php')) {
53
+            if (!empty($ttsFromPostRequest) && file_exists('Speakers\\'.JarvisPHP::$slim->request->post('tts').'.php')) {
54 54
                 $forcedTTS = JarvisPHP::$slim->request->post('tts');
55 55
             } else {
56 56
                 $forcedTTS = _JARVIS_TTS;
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
         });
60 60
 
61 61
         //POST /answer route
62
-        JarvisPHP::$slim->post('/say/', function () {         
62
+        JarvisPHP::$slim->post('/say/', function() {         
63 63
             JarvisPHP::say(mb_strtolower(preg_replace("/\s+/", " ", JarvisPHP::$slim->request->post('sentence')), 'UTF-8'));
64 64
         });
65 65
 
66 66
         //Slim Framework Custom Error handler
67
-        JarvisPHP::$slim->error(function (\Exception $e) {
67
+        JarvisPHP::$slim->error(function(\Exception $e) {
68 68
             JarvisPHP::getLogger()->error('Code: '.$e->getCode().' - '.$e->getMessage().' in '.$e->getFile().' on line '.$e->getLine().'');
69 69
         });
70 70
         
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
         JarvisPHP::$TTS_name = $forcedTTS;
105 105
 
106 106
         //Jarvis tries to understand if the magic words that stop the session were pronounced
107
-        if(preg_match(JarvisLanguage::translate('preg_match_magic_words_to_stop_session'),$command)) {
107
+        if (preg_match(JarvisLanguage::translate('preg_match_magic_words_to_stop_session'), $command)) {
108 108
             JarvisSession::terminate();
109 109
         }
110 110
 
111 111
         //Verify if there is an active plugin and the command session timeout
112
-        if(JarvisSession::sessionInProgress() && (time() < (JarvisSession::get('last_command_timestamp')+_COMMAND_SESSION_TIMEOUT))) {
113
-            JarvisPHP::getLogger()->debug('Detected active session: '.JarvisSession::getActivePlugin() . ' - last command '.JarvisSession::get('last_command_timestamp').', now is '.time());
112
+        if (JarvisSession::sessionInProgress() && (time() < (JarvisSession::get('last_command_timestamp')+_COMMAND_SESSION_TIMEOUT))) {
113
+            JarvisPHP::getLogger()->debug('Detected active session: '.JarvisSession::getActivePlugin().' - last command '.JarvisSession::get('last_command_timestamp').', now is '.time());
114 114
             $plugin_class = JarvisSession::getActivePlugin();
115 115
             //Load plugin's languages
116 116
             JarvisLanguage::loadPluginTranslation($plugin_class);
@@ -121,29 +121,29 @@  discard block
 block discarded – undo
121 121
             //Clear all session variable
122 122
             JarvisSession::reset();
123 123
             JarvisPHP::getLogger()->debug('Active session not detected or expired');
124
-            $max_priority_found=-9999;
124
+            $max_priority_found = -9999;
125 125
             $choosen_plugin = null;
126 126
             //Cycling plugins
127
-            foreach(JarvisPHP::$active_plugins as $plugin_class) {
127
+            foreach (JarvisPHP::$active_plugins as $plugin_class) {
128 128
                $plugin = new $plugin_class();
129 129
                //Load plugin's languages
130 130
                JarvisLanguage::loadPluginTranslation($plugin_class);
131
-               if($plugin->isLikely($command)) {
131
+               if ($plugin->isLikely($command)) {
132 132
                    JarvisPHP::getLogger()->debug('Maybe '.JarvisPHP::getRealClassName($plugin_class).', check priority');
133
-                   if($plugin->getPriority() > $max_priority_found) {
133
+                   if ($plugin->getPriority() > $max_priority_found) {
134 134
                        $max_priority_found = $plugin->getPriority();
135 135
                        $choosen_plugin = $plugin;
136 136
                    }
137 137
                }
138 138
             }
139
-            if(!is_null($choosen_plugin)) {
139
+            if (!is_null($choosen_plugin)) {
140 140
                 JarvisPHP::getLogger()->debug('Choosen plugin: '.JarvisPHP::getRealClassName(get_class($choosen_plugin)));
141
-                if($choosen_plugin->hasSession()) {
141
+                if ($choosen_plugin->hasSession()) {
142 142
                     JarvisSession::setActivePlugin(get_class($choosen_plugin));
143 143
                 }
144 144
                 $choosen_plugin->answer($command);
145 145
             } else {
146
-                if(preg_match(JarvisLanguage::translate('preg_match_magic_words_to_stop_session'),$command)) {
146
+                if (preg_match(JarvisLanguage::translate('preg_match_magic_words_to_stop_session'), $command)) {
147 147
                     JarvisTTS::speak(JarvisLanguage::translate('response_to_magic_words_to_stop_session'));
148 148
                     $response = new \JarvisPHP\Core\JarvisResponse(JarvisLanguage::translate('response_to_magic_words_to_stop_session'));
149 149
                     $response->send();
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
                 else {
152 152
                     JarvisBehaviourLanguage::loadBehaviourLanguage();
153 153
                     $answer = JarvisBehaviourLanguage::answer($command);
154
-                    if($answer) {
154
+                    if ($answer) {
155 155
                         $response = new \JarvisPHP\Core\JarvisResponse($answer, 'none', true);
156 156
                         JarvisTTS::speak($answer);
157 157
                     } else {
158 158
                         JarvisPHP::getLogger()->debug('No plugin found for command: '.$command);
159 159
                         JarvisTTS::speak(JarvisLanguage::translate('core_command_not_understand'));
160 160
                         //Log the command
161
-                        file_put_contents('notUnderstandCommands.log', '['.date('Y-m-d H:i:s').'] Command:'.$command. PHP_EOL , FILE_APPEND | LOCK_EX);
161
+                        file_put_contents('notUnderstandCommands.log', '['.date('Y-m-d H:i:s').'] Command:'.$command.PHP_EOL, FILE_APPEND | LOCK_EX);
162 162
                         $response = new \JarvisPHP\Core\JarvisResponse(JarvisLanguage::translate('core_command_not_understand'));
163 163
                     }
164 164
                     $response->send();
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 
183 183
     public static function getRealClassName($fullClassName) {
184 184
         //Explode class name
185
-        $classNameArray = explode('\\',$fullClassName);
185
+        $classNameArray = explode('\\', $fullClassName);
186 186
         //Obtain the pure class name
187 187
         return end($classNameArray);
188 188
     }
189 189
     
190 190
     public static function getNameSpace($fullClassName) {
191 191
        //Explode class name
192
-        $classNameArray = explode('\\',$fullClassName);
192
+        $classNameArray = explode('\\', $fullClassName);
193 193
         //Remove the pure class name
194 194
         array_pop($classNameArray);
195 195
         //Remove the JarvisPHP main namespace
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -116,8 +116,7 @@  discard block
 block discarded – undo
116 116
             JarvisLanguage::loadPluginTranslation($plugin_class);
117 117
             $plugin = new $plugin_class();
118 118
             $plugin->answer($command);
119
-        }
120
-        else {
119
+        } else {
121 120
             //Clear all session variable
122 121
             JarvisSession::reset();
123 122
             JarvisPHP::getLogger()->debug('Active session not detected or expired');
@@ -147,8 +146,7 @@  discard block
 block discarded – undo
147 146
                     JarvisTTS::speak(JarvisLanguage::translate('response_to_magic_words_to_stop_session'));
148 147
                     $response = new \JarvisPHP\Core\JarvisResponse(JarvisLanguage::translate('response_to_magic_words_to_stop_session'));
149 148
                     $response->send();
150
-                }
151
-                else {
149
+                } else {
152 150
                     JarvisBehaviourLanguage::loadBehaviourLanguage();
153 151
                     $answer = JarvisBehaviourLanguage::answer($command);
154 152
                     if($answer) {
Please login to merge, or discard this patch.
Core/JarvisResponse.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     private $answer = '';
14 14
     private $choosen_plugin = 'none';
15 15
     
16
-    public function __construct($answer, $choosen_plugin='none', $success=false) {
16
+    public function __construct($answer, $choosen_plugin = 'none', $success = false) {
17 17
         $this->answer = $answer;
18 18
         $this->choosen_plugin = $choosen_plugin;
19 19
         $this->success = $success;
Please login to merge, or discard this patch.
Speakers/Google_tts.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,23 +12,23 @@
 block discarded – undo
12 12
     
13 13
     public static function speak($sentence) {
14 14
 
15
-    	//Do not request a new mp3 if it exists in cache folder
16
-    	if(!file_exists(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3')) {
17
-			$curl = curl_init();
15
+        //Do not request a new mp3 if it exists in cache folder
16
+        if(!file_exists(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3')) {
17
+            $curl = curl_init();
18 18
 			
19
-			curl_setopt_array($curl, array(
20
-			    CURLOPT_RETURNTRANSFER => 1,
21
-			    CURLOPT_URL => 'http://translate.google.com/translate_tts?ie=UTF-8&client=t&tl='._LANGUAGE.'&q='.urlencode($sentence),
22
-			    CURLOPT_USERAGENT => 'stagefright/1.2 (Linux;Android 5.0)',
23
-			    CURLOPT_REFERER => 'http://translate.google.com/'
24
-			));
19
+            curl_setopt_array($curl, array(
20
+                CURLOPT_RETURNTRANSFER => 1,
21
+                CURLOPT_URL => 'http://translate.google.com/translate_tts?ie=UTF-8&client=t&tl='._LANGUAGE.'&q='.urlencode($sentence),
22
+                CURLOPT_USERAGENT => 'stagefright/1.2 (Linux;Android 5.0)',
23
+                CURLOPT_REFERER => 'http://translate.google.com/'
24
+            ));
25 25
 
26
-			$resp = curl_exec($curl);
26
+            $resp = curl_exec($curl);
27 27
 
28
-			curl_close($curl);
28
+            curl_close($curl);
29 29
 
30
-	        file_put_contents(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3', $resp);
31
-    	}
30
+            file_put_contents(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3', $resp);
31
+        }
32 32
 
33 33
         exec('aplay '._JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3');
34 34
     }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     public static function speak($sentence) {
14 14
 
15 15
     	//Do not request a new mp3 if it exists in cache folder
16
-    	if(!file_exists(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3')) {
16
+    	if (!file_exists(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3')) {
17 17
 			$curl = curl_init();
18 18
 			
19 19
 			curl_setopt_array($curl, array(
Please login to merge, or discard this patch.
JarvisPHPBot.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,6 +14,6 @@
 block discarded – undo
14 14
 }
15 15
 
16 16
 if($json_config) {
17
-	//Let's start the bot
18
-	JarvisPHPTelegramBot::run($json_config->allowedClientIdList);
17
+    //Let's start the bot
18
+    JarvisPHPTelegramBot::run($json_config->allowedClientIdList);
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@
 block discarded – undo
9 9
 use JarvisPHP\TelegramBot\JarvisPHPTelegramBot;
10 10
 
11 11
 //Load allowedClientIdList
12
-if(file_exists('TelegramBot/allowedClientIdList.json')) {
12
+if (file_exists('TelegramBot/allowedClientIdList.json')) {
13 13
     $json_config = json_decode(file_get_contents('TelegramBot/allowedClientIdList.json'));
14 14
 }
15 15
 
16
-if($json_config) {
16
+if ($json_config) {
17 17
 	//Let's start the bot
18 18
 	JarvisPHPTelegramBot::run($json_config->allowedClientIdList);
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.