@@ -13,7 +13,7 @@ |
||
13 | 13 | public function __construct($title, $content) { |
14 | 14 | $this->title = $title; |
15 | 15 | $this->input_message_content = $content; |
16 | - $this->id = '' . rand(); |
|
16 | + $this->id = ''.rand(); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return object |
17 | 17 | */ |
18 | - public function addRow(){ |
|
18 | + public function addRow() { |
|
19 | 19 | $this->current_row++; |
20 | 20 | |
21 | 21 | return $this; |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row. |
33 | 33 | * @return object |
34 | 34 | */ |
35 | - public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){ |
|
35 | + public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = '') { |
|
36 | 36 | $btn['text'] = $text; |
37 | - if($url != '') |
|
37 | + if ($url != '') |
|
38 | 38 | $btn['url'] = $url; |
39 | - elseif($callback_data != '') |
|
39 | + elseif ($callback_data != '') |
|
40 | 40 | $btn['callback_data'] = $callback_data; |
41 | - elseif($switch_inline_query != '') |
|
41 | + elseif ($switch_inline_query != '') |
|
42 | 42 | $btn['switch_inline_query'] = $switch_inline_query; |
43 | - elseif($switch_inline_query_current_chat != '') |
|
43 | + elseif ($switch_inline_query_current_chat != '') |
|
44 | 44 | $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat; |
45 | - elseif($callback_game != '') |
|
45 | + elseif ($callback_game != '') |
|
46 | 46 | $btn['callback_game'] = $callback_game; |
47 | 47 | else |
48 | 48 | $btn['callback_data'] = $text; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return object Standard |
26 | 26 | */ |
27 | - public function addRow(){ |
|
27 | + public function addRow() { |
|
28 | 28 | $this->current_row++; |
29 | 29 | |
30 | 30 | return $this; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param boolean $request_location Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only |
39 | 39 | * @return object |
40 | 40 | */ |
41 | - public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null){ |
|
41 | + public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null) { |
|
42 | 42 | $this->keyboard[$this->current_row][] = [ |
43 | 43 | 'text' => $text, |
44 | 44 | 'request_contact' => ($request_contact != null) ? $request_contact : false, |
@@ -13,7 +13,7 @@ |
||
13 | 13 | * |
14 | 14 | * @param boolean $selective Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. |
15 | 15 | */ |
16 | - public function __construct($selective = false){ |
|
17 | - $this->selective = $selective; |
|
16 | + public function __construct($selective = false) { |
|
17 | + $this->selective = $selective; |
|
18 | 18 | } |
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $result = $this->getUpdates(); |
124 | 124 | while (true) { |
125 | 125 | $update_id = isset($result->update_id) ? $result->update_id : 1; |
126 | - $result = $this->getUpdates($update_id + 1); |
|
126 | + $result = $this->getUpdates($update_id+1); |
|
127 | 127 | |
128 | 128 | $this->processPayload($result); |
129 | 129 | |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | $this->result = $result; |
148 | 148 | |
149 | 149 | // now i select the right triggers for payload received by Telegram |
150 | - if( isset($this->result->message->text) ) { |
|
150 | + if (isset($this->result->message->text)) { |
|
151 | 151 | $payload = $this->result->message->text; |
152 | 152 | $triggers = $this->commands; |
153 | - } elseif ( isset($this->result->inline_query) ) { |
|
153 | + } elseif (isset($this->result->inline_query)) { |
|
154 | 154 | $payload = $this->result->inline_query->query; |
155 | 155 | $triggers = $this->inlines; |
156 | - } else { |
|
156 | + }else { |
|
157 | 157 | throw new \Exception("Error Processing Request", 1); |
158 | 158 | } |
159 | 159 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | //find args pattern |
169 | 169 | $args = $this->getArgs($pattern, $payload); |
170 | 170 | |
171 | - $pattern = '/^' . $pattern . '/i'; |
|
171 | + $pattern = '/^'.$pattern.'/i'; |
|
172 | 172 | |
173 | 173 | preg_match($pattern, $payload, $matches); |
174 | 174 | |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | call_user_func($func, $args); |
178 | 178 | } |
179 | 179 | } |
180 | - } catch (\Exception $e) { |
|
180 | + }catch (\Exception $e) { |
|
181 | 181 | error_log($e->getMessage()); |
182 | - echo "\r\n Exception :: " . $e->getMessage(); |
|
182 | + echo "\r\n Exception :: ".$e->getMessage(); |
|
183 | 183 | } |
184 | - } else { |
|
184 | + }else { |
|
185 | 185 | echo "\r\nNo new message\r\n"; |
186 | 186 | } |
187 | 187 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $tmp_args_pattern = str_replace(['<<', '>>'], ['(', ')'], $pattern); |
203 | 203 | |
204 | 204 | //if args set |
205 | - if (preg_match('/' . $tmp_args_pattern . '/i', $payload, $matches)) { |
|
205 | + if (preg_match('/'.$tmp_args_pattern.'/i', $payload, $matches)) { |
|
206 | 206 | //remove first element |
207 | 207 | array_shift($matches); |
208 | 208 | if (isset($matches[0])) { |
@@ -225,16 +225,16 @@ discard block |
||
225 | 225 | private function exec($command, $params = []) { |
226 | 226 | if (in_array($command, $this->available_commands)) { |
227 | 227 | // convert json to array then get the last messages info |
228 | - $output = json_decode($this->curl_get_contents($this->api . '/' . $command, $params), true); |
|
228 | + $output = json_decode($this->curl_get_contents($this->api.'/'.$command, $params), true); |
|
229 | 229 | |
230 | 230 | return $this->convertToObject($output); |
231 | - } else { |
|
231 | + }else { |
|
232 | 232 | echo 'command not found'; |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - private function convertToObject($jsonObject , $webhook = false) { |
|
237 | - if( ! $webhook) { |
|
236 | + private function convertToObject($jsonObject, $webhook = false) { |
|
237 | + if (!$webhook) { |
|
238 | 238 | if ($jsonObject['ok']) { |
239 | 239 | //error_log(print_r($jsonObject, true)); |
240 | 240 | |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | $output = end($jsonObject); |
243 | 243 | |
244 | 244 | $result = is_array($output) ? end($output) : $output; |
245 | - if ( ! empty($result)) { |
|
245 | + if (!empty($result)) { |
|
246 | 246 | // convert to object |
247 | 247 | return json_decode(json_encode($result)); |
248 | 248 | } |
249 | 249 | } |
250 | - } else { |
|
250 | + }else { |
|
251 | 251 | return json_decode(json_encode($jsonObject)); |
252 | 252 | } |
253 | 253 | } |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | if ($chat_id) |
286 | 286 | return $chat_id; |
287 | 287 | |
288 | - if( isset($this->result->message) ) { |
|
288 | + if (isset($this->result->message)) { |
|
289 | 289 | return $this->result->message->chat->id; |
290 | - } elseif ( isset($this->result->inline_query) ) { |
|
290 | + } elseif (isset($this->result->inline_query)) { |
|
291 | 291 | return $this->result->inline_query->from->id; |
292 | - } else { |
|
292 | + }else { |
|
293 | 293 | throw new \Exception("Error Processing Request", 1); |
294 | 294 | } |
295 | - } catch (\Exception $e) { |
|
295 | + }catch (\Exception $e) { |
|
296 | 296 | error_log($e->getMessage()); |
297 | 297 | } |
298 | 298 | } |
@@ -7,14 +7,14 @@ |
||
7 | 7 | |
8 | 8 | $tg = new Telegram('API_TOKEN'); |
9 | 9 | |
10 | -$tg->cmd('name:<<[a-zA-Z]{0,}>>', function ($args) use ($tg){ |
|
10 | +$tg->cmd('name:<<[a-zA-Z]{0,}>>', function($args) use ($tg){ |
|
11 | 11 | |
12 | - $tg->sendMessage("my username is @".$args , $tg->getChatId()); |
|
12 | + $tg->sendMessage("my username is @".$args, $tg->getChatId()); |
|
13 | 13 | }); |
14 | 14 | |
15 | 15 | |
16 | -$tg->cmd('<<:any>>',function ($arg) use ($tg){ |
|
17 | - $tg->sendMessage("You Message is : " . $arg, $tg->getChatId()); |
|
16 | +$tg->cmd('<<:any>>', function($arg) use ($tg){ |
|
17 | + $tg->sendMessage("You Message is : ".$arg, $tg->getChatId()); |
|
18 | 18 | }); |
19 | 19 | |
20 | 20 | $tg->run(); |