Completed
Push — master ( 575823...f7fea2 )
by Stefano
02:38
created
TelegramBot/JarvisPHPTelegramBot.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use JarvisPHP\TelegramBot\GenericCurl;
6 6
 
7 7
 //Very important!
8
-define('_JARVISPHP_URL','http://localhost:8000');
8
+define('_JARVISPHP_URL', 'http://localhost:8000');
9 9
 
10 10
 /**
11 11
  * A TelegramBot for JarvisPHP
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		echo "JarvisPHP Telegram Bot started at ".date('Y-m-d H:i:s')."\n";
24 24
 		echo "-----------------------------------------------------\n";
25 25
 
26
-		while(true) {
26
+		while (true) {
27 27
 
28 28
 			$updates = $bot->apiRequestJson("getUpdates", array('offset'=>$offset));
29 29
 			
30
-			if($updates) {
31
-				foreach($updates as $update) {
30
+			if ($updates) {
31
+				foreach ($updates as $update) {
32 32
 
33
-					if(isset($update->message->text)) {
33
+					if (isset($update->message->text)) {
34 34
 
35 35
 						//TODO check if $update->message->chat->id is in enabled list
36 36
 
@@ -40,28 +40,28 @@  discard block
 block discarded – undo
40 40
 
41 41
 						$message = $update->message->text;
42 42
 
43
-						$offset = $update->update_id + 1;
43
+						$offset = $update->update_id+1;
44 44
 
45 45
 						$response = '';
46 46
 
47 47
 						//Understand if the message is a telegram command (begins with "/")
48
-						if(preg_match('$^/(.+)$', $message)) {
48
+						if (preg_match('$^/(.+)$', $message)) {
49 49
 							
50 50
 							//Telegram command
51
-							switch($message) {
52
-								case '/start': $response='I am JarvisPHP, a private bot. \u1F510'; break;
53
-								case '/info': $response='I am JarvisPHP, a private bot. \u1F510'; break;
51
+							switch ($message) {
52
+								case '/start': $response = 'I am JarvisPHP, a private bot. \u1F510'; break;
53
+								case '/info': $response = 'I am JarvisPHP, a private bot. \u1F510'; break;
54 54
 								case '/register': 
55
-												$response='Ok, i registered your ID in registerIdLog.log'; 
56
-												file_put_contents('TelegramBot/registerIdLog.log', '['.date('Y-m-d H:i:s').'] ID:'.$update->message->from->id . '; FIRSTNAME:'. $update->message->from->first_name . '; LASTNAME:'. $update->message->from->last_name. '; USERNAME:'. $update->message->from->username.PHP_EOL , FILE_APPEND | LOCK_EX);
55
+												$response = 'Ok, i registered your ID in registerIdLog.log'; 
56
+												file_put_contents('TelegramBot/registerIdLog.log', '['.date('Y-m-d H:i:s').'] ID:'.$update->message->from->id.'; FIRSTNAME:'.$update->message->from->first_name.'; LASTNAME:'.$update->message->from->last_name.'; USERNAME:'.$update->message->from->username.PHP_EOL, FILE_APPEND | LOCK_EX);
57 57
 												break;	
58
-								case '/say': $response='Use /say "sentence" (without quotes) to make JarvisPHP speak a sentence.'; break;	
58
+								case '/say': $response = 'Use /say "sentence" (without quotes) to make JarvisPHP speak a sentence.'; break;	
59 59
 							}
60 60
 
61 61
 							//"Say" Telegram command
62
-							if(preg_match('$^/say (.+)$', $message, $matches)) {
63
-								if($matches) {
64
-									if(in_array($update->message->chat->id, $allowedClientIdList)) {
62
+							if (preg_match('$^/say (.+)$', $message, $matches)) {
63
+								if ($matches) {
64
+									if (in_array($update->message->chat->id, $allowedClientIdList)) {
65 65
 										//Redirect message to JarvisPhp
66 66
 										$JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/answer', array('sentence'=>$matches[0]));
67 67
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 							}
74 74
 
75 75
 							//Encode emoji
76
-							$response = preg_replace_callback('/\\\\u([0-9a-fA-F]+)/', function ($match) {
76
+							$response = preg_replace_callback('/\\\\u([0-9a-fA-F]+)/', function($match) {
77 77
 							    return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($match[1])));
78 78
 							}, $response);
79 79
 
80 80
 						} else {
81
-							if(in_array($update->message->chat->id, $allowedClientIdList)) {
81
+							if (in_array($update->message->chat->id, $allowedClientIdList)) {
82 82
 								//Redirect message to JarvisPhp
83 83
 								$JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/answer', array('command'=>$message, 'tts' => 'None_tts'));
84 84
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 							}
89 89
 
90 90
 						}
91
-						if($response) {
91
+						if ($response) {
92 92
 							$bot->apiRequestJson("sendMessage", array('chat_id' => $update->message->chat->id, "text" => $response));
93 93
 						}
94 94
 					}
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -14,87 +14,87 @@
 block discarded – undo
14 14
  */
15 15
 class JarvisPHPTelegramBot {
16 16
 	
17
-	public static function run($allowedClientIdList) {
17
+    public static function run($allowedClientIdList) {
18 18
 
19
-		$bot = new TelegramBotApiWrapper();
19
+        $bot = new TelegramBotApiWrapper();
20 20
 
21
-		$offset = 0;
21
+        $offset = 0;
22 22
 
23
-		echo "JarvisPHP Telegram Bot started at ".date('Y-m-d H:i:s')."\n";
24
-		echo "-----------------------------------------------------\n";
23
+        echo "JarvisPHP Telegram Bot started at ".date('Y-m-d H:i:s')."\n";
24
+        echo "-----------------------------------------------------\n";
25 25
 
26
-		while(true) {
26
+        while(true) {
27 27
 
28
-			$updates = $bot->apiRequestJson("getUpdates", array('offset'=>$offset));
28
+            $updates = $bot->apiRequestJson("getUpdates", array('offset'=>$offset));
29 29
 			
30
-			if($updates) {
31
-				foreach($updates as $update) {
30
+            if($updates) {
31
+                foreach($updates as $update) {
32 32
 
33
-					if(isset($update->message->text)) {
33
+                    if(isset($update->message->text)) {
34 34
 
35
-						//TODO check if $update->message->chat->id is in enabled list
35
+                        //TODO check if $update->message->chat->id is in enabled list
36 36
 
37
-						$bot->apiRequestJson("sendChatAction", array('chat_id' => $update->message->chat->id, 'action' => 'typing'));
37
+                        $bot->apiRequestJson("sendChatAction", array('chat_id' => $update->message->chat->id, 'action' => 'typing'));
38 38
 
39
-						echo "Processing message ->".$update->message->text."\n";
39
+                        echo "Processing message ->".$update->message->text."\n";
40 40
 
41
-						$message = $update->message->text;
41
+                        $message = $update->message->text;
42 42
 
43
-						$offset = $update->update_id + 1;
43
+                        $offset = $update->update_id + 1;
44 44
 
45
-						$response = '';
45
+                        $response = '';
46 46
 
47
-						//Understand if the message is a telegram command (begins with "/")
48
-						if(preg_match('$^/(.+)$', $message)) {
47
+                        //Understand if the message is a telegram command (begins with "/")
48
+                        if(preg_match('$^/(.+)$', $message)) {
49 49
 							
50
-							//Telegram command
51
-							switch($message) {
52
-								case '/start': $response='I am JarvisPHP, a private bot. \u1F510'; break;
53
-								case '/info': $response='I am JarvisPHP, a private bot. \u1F510'; break;
54
-								case '/register': 
55
-												$response='Ok, i registered your ID in registerIdLog.log'; 
56
-												file_put_contents('TelegramBot/registerIdLog.log', '['.date('Y-m-d H:i:s').'] ID:'.$update->message->from->id . '; FIRSTNAME:'. $update->message->from->first_name . '; LASTNAME:'. $update->message->from->last_name. '; USERNAME:'. $update->message->from->username.PHP_EOL , FILE_APPEND | LOCK_EX);
57
-												break;	
58
-								case '/say': $response='Use /say "sentence" (without quotes) to make JarvisPHP speak a sentence.'; break;	
59
-							}
60
-
61
-							//"Say" Telegram command
62
-							if(preg_match('$^/say (.+)$', $message, $matches)) {
63
-								if($matches) {
64
-									if(in_array($update->message->chat->id, $allowedClientIdList)) {
65
-										//Redirect message to JarvisPhp
66
-										$JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/say', array('sentence'=>$matches[1]));
67
-
68
-										$response = $JarvisResponse->answer;
69
-									} else {
70
-										$response = 'You are not allowed to speak with me.';
71
-									}
72
-								}
73
-							}
74
-
75
-							//Encode emoji
76
-							$response = preg_replace_callback('/\\\\u([0-9a-fA-F]+)/', function ($match) {
77
-							    return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($match[1])));
78
-							}, $response);
79
-
80
-						} else {
81
-							if(in_array($update->message->chat->id, $allowedClientIdList)) {
82
-								//Redirect message to JarvisPhp
83
-								$JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/answer', array('command'=>$message, 'tts' => 'None_tts'));
84
-
85
-								$response = $JarvisResponse->answer;
86
-							} else {
87
-								$response = 'You are not allowed to speak with me.';
88
-							}
89
-
90
-						}
91
-						if($response) {
92
-							$bot->apiRequestJson("sendMessage", array('chat_id' => $update->message->chat->id, "text" => $response));
93
-						}
94
-					}
95
-				}
96
-			}
97
-			sleep(1);
98
-		}
99
-	}
50
+                            //Telegram command
51
+                            switch($message) {
52
+                                case '/start': $response='I am JarvisPHP, a private bot. \u1F510'; break;
53
+                                case '/info': $response='I am JarvisPHP, a private bot. \u1F510'; break;
54
+                                case '/register': 
55
+                                                $response='Ok, i registered your ID in registerIdLog.log'; 
56
+                                                file_put_contents('TelegramBot/registerIdLog.log', '['.date('Y-m-d H:i:s').'] ID:'.$update->message->from->id . '; FIRSTNAME:'. $update->message->from->first_name . '; LASTNAME:'. $update->message->from->last_name. '; USERNAME:'. $update->message->from->username.PHP_EOL , FILE_APPEND | LOCK_EX);
57
+                                                break;	
58
+                                case '/say': $response='Use /say "sentence" (without quotes) to make JarvisPHP speak a sentence.'; break;	
59
+                            }
60
+
61
+                            //"Say" Telegram command
62
+                            if(preg_match('$^/say (.+)$', $message, $matches)) {
63
+                                if($matches) {
64
+                                    if(in_array($update->message->chat->id, $allowedClientIdList)) {
65
+                                        //Redirect message to JarvisPhp
66
+                                        $JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/say', array('sentence'=>$matches[1]));
67
+
68
+                                        $response = $JarvisResponse->answer;
69
+                                    } else {
70
+                                        $response = 'You are not allowed to speak with me.';
71
+                                    }
72
+                                }
73
+                            }
74
+
75
+                            //Encode emoji
76
+                            $response = preg_replace_callback('/\\\\u([0-9a-fA-F]+)/', function ($match) {
77
+                                return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($match[1])));
78
+                            }, $response);
79
+
80
+                        } else {
81
+                            if(in_array($update->message->chat->id, $allowedClientIdList)) {
82
+                                //Redirect message to JarvisPhp
83
+                                $JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/answer', array('command'=>$message, 'tts' => 'None_tts'));
84
+
85
+                                $response = $JarvisResponse->answer;
86
+                            } else {
87
+                                $response = 'You are not allowed to speak with me.';
88
+                            }
89
+
90
+                        }
91
+                        if($response) {
92
+                            $bot->apiRequestJson("sendMessage", array('chat_id' => $update->message->chat->id, "text" => $response));
93
+                        }
94
+                    }
95
+                }
96
+            }
97
+            sleep(1);
98
+        }
99
+    }
100 100
 }
101 101
\ No newline at end of file
Please login to merge, or discard this patch.
TelegramBot/TelegramBot.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -9,75 +9,75 @@
 block discarded – undo
9 9
  */
10 10
 class TelegramBotApiWrapper {
11 11
 
12
-	function exec_curl_request($handle) {
13
-	  $response = curl_exec($handle);
12
+    function exec_curl_request($handle) {
13
+        $response = curl_exec($handle);
14 14
 
15
-	  if ($response === false) {
16
-	    $errno = curl_errno($handle);
17
-	    $error = curl_error($handle);
18
-	    echo("Curl returned error $errno: $error\n");
19
-	    curl_close($handle);
20
-	    return false;
21
-	  }
15
+        if ($response === false) {
16
+        $errno = curl_errno($handle);
17
+        $error = curl_error($handle);
18
+        echo("Curl returned error $errno: $error\n");
19
+        curl_close($handle);
20
+        return false;
21
+        }
22 22
 
23
-	  $http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
24
-	  curl_close($handle);
23
+        $http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
24
+        curl_close($handle);
25 25
 
26
-	  if ($http_code >= 500) {
27
-	    // do not want to DDOS server if something goes wrong
28
-	    sleep(10);
29
-	    return false;
30
-	  } else if ($http_code != 200) {
31
-	    $response = json_decode($response, false);
32
-	    echo("Request has failed with error ".$response->error_code." : ".$response->description."\n");
33
-	    if ($http_code == 401) {
34
-	      throw new Exception('Invalid access token provided');
35
-	    }
36
-	    return false;
37
-	  } else {
38
-	    $response = json_decode($response, false);
39
-	    if (isset($response->description)) {
40
-	      echo("Request was successfull: ".$response->description."\n");
41
-	    }
42
-	    $response = $response->result;
43
-	  }
26
+        if ($http_code >= 500) {
27
+        // do not want to DDOS server if something goes wrong
28
+        sleep(10);
29
+        return false;
30
+        } else if ($http_code != 200) {
31
+        $response = json_decode($response, false);
32
+        echo("Request has failed with error ".$response->error_code." : ".$response->description."\n");
33
+        if ($http_code == 401) {
34
+            throw new Exception('Invalid access token provided');
35
+        }
36
+        return false;
37
+        } else {
38
+        $response = json_decode($response, false);
39
+        if (isset($response->description)) {
40
+            echo("Request was successfull: ".$response->description."\n");
41
+        }
42
+        $response = $response->result;
43
+        }
44 44
 
45
-	  return $response;
46
-	}
45
+        return $response;
46
+    }
47 47
 
48
-	function apiRequestJson($method, $parameters) {
49
-	  if (!is_string($method)) {
50
-	    echo("Method name must be a string\n");
51
-	    return false;
52
-	  }
48
+    function apiRequestJson($method, $parameters) {
49
+        if (!is_string($method)) {
50
+        echo("Method name must be a string\n");
51
+        return false;
52
+        }
53 53
 
54
-	  if (!$parameters) {
55
-	    $parameters = array();
56
-	  } else if (!is_array($parameters)) {
57
-	    error_log("Parameters must be an array\n");
58
-	    return false;
59
-	  }
54
+        if (!$parameters) {
55
+        $parameters = array();
56
+        } else if (!is_array($parameters)) {
57
+        error_log("Parameters must be an array\n");
58
+        return false;
59
+        }
60 60
 
61
-	  $parameters["method"] = $method;
61
+        $parameters["method"] = $method;
62 62
 
63
-	  $_BOT_TOKEN = '';
64
-	  //Load API key from json config
65
-      if(file_exists('TelegramBot/api-key.json')) {
66
-          //Create your own bot token and put it in api-key.json
67
-          // like {"bot_token": "<your-bot-token>"}
68
-          $json_config = json_decode(file_get_contents('TelegramBot/api-key.json'));
69
-          $_BOT_TOKEN = $json_config->bot_token;
70
-      }
63
+        $_BOT_TOKEN = '';
64
+        //Load API key from json config
65
+        if(file_exists('TelegramBot/api-key.json')) {
66
+            //Create your own bot token and put it in api-key.json
67
+            // like {"bot_token": "<your-bot-token>"}
68
+            $json_config = json_decode(file_get_contents('TelegramBot/api-key.json'));
69
+            $_BOT_TOKEN = $json_config->bot_token;
70
+        }
71 71
 
72
-	  $handle = curl_init('https://api.telegram.org/bot'.$_BOT_TOKEN.'/');
73
-	  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
74
-	  curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
75
-	  curl_setopt($handle, CURLOPT_TIMEOUT, 60);
76
-	  curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
77
-	  curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
78
-	  curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
72
+        $handle = curl_init('https://api.telegram.org/bot'.$_BOT_TOKEN.'/');
73
+        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
74
+        curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
75
+        curl_setopt($handle, CURLOPT_TIMEOUT, 60);
76
+        curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
77
+        curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
78
+        curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
79 79
 
80
-	  return $this->exec_curl_request($handle);
81
-	}
80
+        return $this->exec_curl_request($handle);
81
+    }
82 82
 
83 83
 }
84 84
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
 
63 63
 	  $_BOT_TOKEN = '';
64 64
 	  //Load API key from json config
65
-      if(file_exists('TelegramBot/api-key.json')) {
65
+      if (file_exists('TelegramBot/api-key.json')) {
66 66
           //Create your own bot token and put it in api-key.json
67 67
           // like {"bot_token": "<your-bot-token>"}
68 68
           $json_config = json_decode(file_get_contents('TelegramBot/api-key.json'));
Please login to merge, or discard this patch.
TelegramBot/GenericCurl.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,38 +8,38 @@
 block discarded – undo
8 8
  */
9 9
 class GenericCurl {
10 10
 
11
-	static function exec($url, $fields) {
11
+    static function exec($url, $fields) {
12 12
 
13 13
 
14
-		$fields_string = "";
15
-		//url-ify the data for the POST
16
-		if(count($fields)>0) {
17
-			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
18
-			rtrim($fields_string, '&');
19
-		} 
14
+        $fields_string = "";
15
+        //url-ify the data for the POST
16
+        if(count($fields)>0) {
17
+            foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
18
+            rtrim($fields_string, '&');
19
+        } 
20 20
 		
21
-		//echo $fields_string;
22
-		//open connection
23
-		$ch = curl_init();
21
+        //echo $fields_string;
22
+        //open connection
23
+        $ch = curl_init();
24 24
 
25
-		//set the url, number of POST vars, POST data
26
-		curl_setopt($ch,CURLOPT_URL, $url);
27
-		curl_setopt($ch,CURLOPT_POST, count($fields));
28
-		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
29
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
-		curl_setopt ($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
31
-		curl_setopt($ch, CURLOPT_COOKIEJAR, "TelegramBot/JarvisPHPSession.cookie"); 
25
+        //set the url, number of POST vars, POST data
26
+        curl_setopt($ch,CURLOPT_URL, $url);
27
+        curl_setopt($ch,CURLOPT_POST, count($fields));
28
+        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
29
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
+        curl_setopt ($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
31
+        curl_setopt($ch, CURLOPT_COOKIEJAR, "TelegramBot/JarvisPHPSession.cookie"); 
32 32
 
33
-		//execute post
34
-		$result = @curl_exec($ch);
33
+        //execute post
34
+        $result = @curl_exec($ch);
35 35
 
36
-		$http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
36
+        $http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
37 37
 
38
-		//close connection
39
-		curl_close($ch);
38
+        //close connection
39
+        curl_close($ch);
40 40
 
41 41
 
42 42
 
43
-		return ($http_response_code==200) ? json_decode($result) : false;
44
-	}
43
+        return ($http_response_code==200) ? json_decode($result) : false;
44
+    }
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 
14 14
 		$fields_string = "";
15 15
 		//url-ify the data for the POST
16
-		if(count($fields)>0) {
17
-			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
16
+		if (count($fields) > 0) {
17
+			foreach ($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
18 18
 			rtrim($fields_string, '&');
19 19
 		} 
20 20
 		
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 		$ch = curl_init();
24 24
 
25 25
 		//set the url, number of POST vars, POST data
26
-		curl_setopt($ch,CURLOPT_URL, $url);
27
-		curl_setopt($ch,CURLOPT_POST, count($fields));
28
-		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
26
+		curl_setopt($ch, CURLOPT_URL, $url);
27
+		curl_setopt($ch, CURLOPT_POST, count($fields));
28
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
-		curl_setopt ($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
30
+		curl_setopt($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
31 31
 		curl_setopt($ch, CURLOPT_COOKIEJAR, "TelegramBot/JarvisPHPSession.cookie"); 
32 32
 
33 33
 		//execute post
@@ -40,6 +40,6 @@  discard block
 block discarded – undo
40 40
 
41 41
 
42 42
 
43
-		return ($http_response_code==200) ? json_decode($result) : false;
43
+		return ($http_response_code == 200) ? json_decode($result) : false;
44 44
 	}
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
config/Espeak_config.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@
 block discarded – undo
5 5
  * m1, m2, ... m8 male voices
6 6
  * f1, f2, f3, f4 female voices
7 7
  */
8
-define('_ESPEAK_VOICE','m2');
8
+define('_ESPEAK_VOICE', 'm2');
9 9
 
10 10
 //Language of text-to-speech
11 11
 define('_ESPEAK_LANGUAGE', _LANGUAGE);
12 12
 
13 13
 //Amplitude (espeak -a <amplitude>)
14
-define('_ESPEAK_AMPLITUDE','100');
15 14
\ No newline at end of file
15
+define('_ESPEAK_AMPLITUDE', '100');
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
config/Jarvis.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  */
5 5
 
6 6
 //Set locale
7
-define('_LANGUAGE','en');
7
+define('_LANGUAGE', 'en');
8 8
 
9 9
 //Command session timeout, in seconds
10 10
 define('_COMMAND_SESSION_TIMEOUT', 30);
@@ -13,4 +13,4 @@  discard block
 block discarded – undo
13 13
 define('_JARVIS_TTS', 'None_tts');
14 14
 
15 15
 //Define system's name
16
-define('_SYSTEM_NAME','JarvisPhp');
17 16
\ No newline at end of file
17
+define('_SYSTEM_NAME', 'JarvisPhp');
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
Plugins/Info_plugin/Info_plugin.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @author Stefano Bianchini
13 13
  * @website http://www.stefanobianchini.net
14 14
  */
15
-class Info_plugin implements \JarvisPHP\Core\JarvisPluginInterface{
15
+class Info_plugin implements \JarvisPHP\Core\JarvisPluginInterface {
16 16
     /**
17 17
      * Priority of plugin
18 18
      * @var int  
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
      */
26 26
     function answer($command) {
27 27
         $answer = '';
28
-        if(preg_match(JarvisLanguage::translate('preg_match_tell_more',get_called_class()), $command)) {
28
+        if (preg_match(JarvisLanguage::translate('preg_match_tell_more', get_called_class()), $command)) {
29 29
             //Testing session
30 30
             JarvisPHP::getLogger()->debug('User says: '.$command);
31
-            $answer = 'Ok, i am on '. php_uname();
31
+            $answer = 'Ok, i am on '.php_uname();
32 32
             JarvisSession::terminate();
33 33
         }
34 34
         else {
35 35
             JarvisPHP::getLogger()->debug('Answering to command: "'.$command.'"');
36
-            $answer = sprintf(JarvisLanguage::translate('my_name_is',get_called_class()),_SYSTEM_NAME, $_SERVER['SERVER_NAME'],$_SERVER['SERVER_ADDR']);
36
+            $answer = sprintf(JarvisLanguage::translate('my_name_is', get_called_class()), _SYSTEM_NAME, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_ADDR']);
37 37
             
38 38
         }
39 39
         JarvisTTS::speak($answer);
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @return boolean
55 55
      */
56 56
     function isLikely($command) {
57
-        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
57
+        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command);
58 58
     }
59 59
     
60 60
     /**
Please login to merge, or discard this patch.
Plugins/Weather_plugin/Weather_plugin.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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('&deg;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('&deg;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('&deg;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('&deg;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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Plugins/Echo_plugin/Echo_plugin.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Plugins/Movie_plugin/Movie_plugin.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.