@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | |
108 | - public function PDO(){ |
|
108 | + public function PDO() { |
|
109 | 109 | |
110 | - $servername ='YOUR_SERVER_NAME'; |
|
110 | + $servername = 'YOUR_SERVER_NAME'; |
|
111 | 111 | $username = 'YOUR_USERNAME'; |
112 | - $password ='YOUR_PASSWORD'; |
|
112 | + $password = 'YOUR_PASSWORD'; |
|
113 | 113 | $dbname = 'YOUR_DATABASE_NAME'; |
114 | 114 | try { |
115 | 115 | $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | return $conn; |
119 | 119 | } |
120 | - catch(PDOException $e) |
|
120 | + catch (PDOException $e) |
|
121 | 121 | { |
122 | 122 | return $e->getMessage(); |
123 | 123 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $result = $this->getUpdates(); |
143 | 143 | while (true) { |
144 | 144 | $update_id = isset($result->update_id) ? $result->update_id : 1; |
145 | - $result = $this->getUpdates($update_id + 1); |
|
145 | + $result = $this->getUpdates($update_id+1); |
|
146 | 146 | |
147 | 147 | $this->processPayload($result); |
148 | 148 | |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | $this->result = $result; |
167 | 167 | |
168 | 168 | // now i select the right triggers for payload received by Telegram |
169 | - if( isset($this->result->message->text) ) { |
|
169 | + if (isset($this->result->message->text)) { |
|
170 | 170 | $payload = $this->result->message->text; |
171 | 171 | $triggers = $this->commands; |
172 | - } elseif ( isset($this->result->inline_query) ) { |
|
172 | + } elseif (isset($this->result->inline_query)) { |
|
173 | 173 | $payload = $this->result->inline_query->query; |
174 | 174 | $triggers = $this->inlines; |
175 | - } else { |
|
175 | + }else { |
|
176 | 176 | throw new \Exception("Error Processing Request", 1); |
177 | 177 | } |
178 | 178 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | //find args pattern |
188 | 188 | $args = $this->getArgs($pattern, $payload); |
189 | 189 | |
190 | - $pattern = '/^' . $pattern . '/i'; |
|
190 | + $pattern = '/^'.$pattern.'/i'; |
|
191 | 191 | |
192 | 192 | preg_match($pattern, $payload, $matches); |
193 | 193 | |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | return call_user_func($func, $args); |
197 | 197 | } |
198 | 198 | } |
199 | - } catch (\Exception $e) { |
|
199 | + }catch (\Exception $e) { |
|
200 | 200 | error_log($e->getMessage()); |
201 | - echo "\r\n Exception :: " . $e->getMessage(); |
|
201 | + echo "\r\n Exception :: ".$e->getMessage(); |
|
202 | 202 | } |
203 | - } else { |
|
203 | + }else { |
|
204 | 204 | echo "\r\nNo new message\r\n"; |
205 | 205 | } |
206 | 206 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $tmp_args_pattern = str_replace(['<<', '>>'], ['(', ')'], $pattern); |
222 | 222 | |
223 | 223 | //if args set |
224 | - if (preg_match('/' . $tmp_args_pattern . '/i', $payload, $matches)) { |
|
224 | + if (preg_match('/'.$tmp_args_pattern.'/i', $payload, $matches)) { |
|
225 | 225 | //remove first element |
226 | 226 | array_shift($matches); |
227 | 227 | if (isset($matches[0])) { |
@@ -244,16 +244,16 @@ discard block |
||
244 | 244 | private function exec($command, $params = []) { |
245 | 245 | if (in_array($command, $this->available_commands)) { |
246 | 246 | // convert json to array then get the last messages info |
247 | - $output = json_decode($this->curl_get_contents($this->api . '/' . $command, $params), true); |
|
247 | + $output = json_decode($this->curl_get_contents($this->api.'/'.$command, $params), true); |
|
248 | 248 | |
249 | 249 | return $this->convertToObject($output); |
250 | - } else { |
|
250 | + }else { |
|
251 | 251 | echo 'command not found'; |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - private function convertToObject($jsonObject , $webhook = false) { |
|
256 | - if( ! $webhook) { |
|
255 | + private function convertToObject($jsonObject, $webhook = false) { |
|
256 | + if (!$webhook) { |
|
257 | 257 | if ($jsonObject['ok']) { |
258 | 258 | //error_log(print_r($jsonObject, true)); |
259 | 259 | |
@@ -261,12 +261,12 @@ discard block |
||
261 | 261 | $output = end($jsonObject); |
262 | 262 | |
263 | 263 | $result = is_array($output) ? end($output) : $output; |
264 | - if ( ! empty($result)) { |
|
264 | + if (!empty($result)) { |
|
265 | 265 | // convert to object |
266 | 266 | return json_decode(json_encode($result)); |
267 | 267 | } |
268 | 268 | } |
269 | - } else { |
|
269 | + }else { |
|
270 | 270 | return json_decode(json_encode($jsonObject)); |
271 | 271 | } |
272 | 272 | } |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | if ($chat_id) |
305 | 305 | return $chat_id; |
306 | 306 | |
307 | - if( isset($this->result->message) ) { |
|
307 | + if (isset($this->result->message)) { |
|
308 | 308 | return $this->result->message->chat->id; |
309 | - } elseif ( isset($this->result->inline_query) ) { |
|
309 | + } elseif (isset($this->result->inline_query)) { |
|
310 | 310 | return $this->result->inline_query->from->id; |
311 | - } else { |
|
311 | + }else { |
|
312 | 312 | throw new \Exception("Error Processing Request", 1); |
313 | 313 | } |
314 | - } catch (\Exception $e) { |
|
314 | + }catch (\Exception $e) { |
|
315 | 315 | error_log($e->getMessage()); |
316 | 316 | } |
317 | 317 | } |