@@ -217,8 +217,9 @@ discard block |
||
217 | 217 | if (telegram::$status) { |
218 | 218 | $check = $check->status; |
219 | 219 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
220 | + } else { |
|
221 | + $result[$id] = null; |
|
220 | 222 | } |
221 | - else $result[$id] = null; |
|
222 | 223 | } |
223 | 224 | return $result; |
224 | 225 | } |
@@ -259,8 +260,7 @@ discard block |
||
259 | 260 | curl_exec($ch); |
260 | 261 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
261 | 262 | curl_close($ch); |
262 | - } |
|
263 | - else { |
|
263 | + } else { |
|
264 | 264 | $path = realpath($path); |
265 | 265 | $size = file_exists($path) ? filesize($path) : false; |
266 | 266 | } |
@@ -331,8 +331,7 @@ discard block |
||
331 | 331 | $zip->addFile($filePath, substr($filePath, $root_len)); |
332 | 332 | } |
333 | 333 | } |
334 | - } |
|
335 | - else { |
|
334 | + } else { |
|
336 | 335 | $zip->addFile($path, basename($path)); |
337 | 336 | } |
338 | 337 | return $zip->close(); |
@@ -351,9 +350,13 @@ discard block |
||
351 | 350 | */ |
352 | 351 | public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool { |
353 | 352 | $file = fopen($url, 'rb'); |
354 | - if (!$file) return false; |
|
353 | + if (!$file) { |
|
354 | + return false; |
|
355 | + } |
|
355 | 356 | $path = fopen($path, 'wb'); |
356 | - if (!$path) return false; |
|
357 | + if (!$path) { |
|
358 | + return false; |
|
359 | + } |
|
357 | 360 | |
358 | 361 | $length = $chunk_size * 1024; |
359 | 362 | while (!feof($file)){ |
@@ -462,8 +465,9 @@ discard block |
||
462 | 465 | foreach ($string as $k => &$v) { |
463 | 466 | if ($diff->$v) { |
464 | 467 | $v = $diff->$v; |
468 | + } else { |
|
469 | + unset($string[$k]); |
|
465 | 470 | } |
466 | - else unset($string[$k]); |
|
467 | 471 | } |
468 | 472 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
469 | 473 | |
@@ -529,8 +533,7 @@ discard block |
||
529 | 533 | if ($last === "\0") { |
530 | 534 | $new .= str_repeat($last, ord($char)); |
531 | 535 | $last = ''; |
532 | - } |
|
533 | - else { |
|
536 | + } else { |
|
534 | 537 | $new .= $last; |
535 | 538 | $last = $char; |
536 | 539 | } |
@@ -614,7 +617,9 @@ discard block |
||
614 | 617 | } |
615 | 618 | $rows = []; |
616 | 619 | foreach ($keyboard as $row) { |
617 | - if (!is_array($row)) continue; |
|
620 | + if (!is_array($row)) { |
|
621 | + continue; |
|
622 | + } |
|
618 | 623 | $buttons = []; |
619 | 624 | foreach ($row as $base_button) { |
620 | 625 | $button_info = explode('||', $base_button); |
@@ -623,15 +628,12 @@ discard block |
||
623 | 628 | if (count($button_info) > 1) { |
624 | 629 | if ($button_info[1] === 'con') { |
625 | 630 | $button->setRequest_contact(true); |
626 | - } |
|
627 | - elseif ($button_info[1] === 'loc') { |
|
631 | + } elseif ($button_info[1] === 'loc') { |
|
628 | 632 | $button->setRequest_location(true); |
629 | - } |
|
630 | - elseif ($button_info[1] === 'poll') { |
|
633 | + } elseif ($button_info[1] === 'poll') { |
|
631 | 634 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
632 | 635 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
633 | - } |
|
634 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
636 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
635 | 637 | $url = $button_info[2]; |
636 | 638 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
637 | 639 | } |
@@ -642,8 +644,7 @@ discard block |
||
642 | 644 | } |
643 | 645 | $keyboard_object->setKeyboard($rows); |
644 | 646 | return $keyboard_object; |
645 | - } |
|
646 | - elseif (!empty($inline)) { |
|
647 | + } elseif (!empty($inline)) { |
|
647 | 648 | $keyboard_object = new inlineKeyboardMarkup(); |
648 | 649 | $rows = []; |
649 | 650 | foreach ($inline as $row) { |
@@ -653,12 +654,10 @@ discard block |
||
653 | 654 | if (isset($button_info[1])) { |
654 | 655 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
655 | 656 | $button->setText($button_info[0])->setUrl($button_info[1]); |
656 | - } |
|
657 | - else { |
|
657 | + } else { |
|
658 | 658 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
659 | 659 | } |
660 | - } |
|
661 | - else { |
|
660 | + } else { |
|
662 | 661 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
663 | 662 | } |
664 | 663 | $buttons[] = $button; |
@@ -667,8 +666,7 @@ discard block |
||
667 | 666 | } |
668 | 667 | $keyboard_object->setInline_keyboard($rows); |
669 | 668 | return $keyboard_object; |
670 | - } |
|
671 | - else { |
|
669 | + } else { |
|
672 | 670 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
673 | 671 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
674 | 672 | } |
@@ -687,8 +685,12 @@ discard block |
||
687 | 685 | * @return string |
688 | 686 | */ |
689 | 687 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
690 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
691 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
688 | + if (empty($user_id)) { |
|
689 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
690 | + } |
|
691 | + if (empty($bot_username)) { |
|
692 | + $bot_username = telegram::getMe()->username; |
|
693 | + } |
|
692 | 694 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
693 | 695 | } |
694 | 696 | |
@@ -723,8 +725,7 @@ discard block |
||
723 | 725 | $iv = self::randomString(); |
724 | 726 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
725 | 727 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
726 | - } |
|
727 | - elseif ($action === cryptoAction::DECRYPT) { |
|
728 | + } elseif ($action === cryptoAction::DECRYPT) { |
|
728 | 729 | if (empty($key)) { |
729 | 730 | logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
730 | 731 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
@@ -734,8 +735,7 @@ discard block |
||
734 | 735 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
735 | 736 | } |
736 | 737 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
737 | - } |
|
738 | - else { |
|
738 | + } else { |
|
739 | 739 | logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
740 | 740 | return false; |
741 | 741 | } |
@@ -757,7 +757,9 @@ discard block |
||
757 | 757 | $array[] = $num % 62; |
758 | 758 | $num = floor($num / 62); |
759 | 759 | } |
760 | - if (count($array) < 1) $array = [0]; |
|
760 | + if (count($array) < 1) { |
|
761 | + $array = [0]; |
|
762 | + } |
|
761 | 763 | foreach ($array as &$value) { |
762 | 764 | $value = $codes[$value]; |
763 | 765 | } |
@@ -195,17 +195,13 @@ discard block |
||
195 | 195 | public static function process (): void { |
196 | 196 | if (isset(BPT::$update->message)) { |
197 | 197 | self::processMessage(BPT::$update->message); |
198 | - } |
|
199 | - elseif (isset(BPT::$update->edited_message)) { |
|
198 | + } elseif (isset(BPT::$update->edited_message)) { |
|
200 | 199 | self::processMessage(BPT::$update->edited_message); |
201 | - } |
|
202 | - elseif (isset(BPT::$update->callback_query)) { |
|
200 | + } elseif (isset(BPT::$update->callback_query)) { |
|
203 | 201 | self::processCallbackQuery(BPT::$update->callback_query); |
204 | - } |
|
205 | - elseif (isset(BPT::$update->inline_query)) { |
|
202 | + } elseif (isset(BPT::$update->inline_query)) { |
|
206 | 203 | self::processInlineQuery(BPT::$update->inline_query); |
207 | - } |
|
208 | - elseif (isset(BPT::$update->chat_member)) { |
|
204 | + } elseif (isset(BPT::$update->chat_member)) { |
|
209 | 205 | self::processChatMember(BPT::$update->chat_member); |
210 | 206 | } |
211 | 207 | } |
@@ -230,8 +226,7 @@ discard block |
||
230 | 226 | if (empty(self::$group)) { |
231 | 227 | $category = 'supergroups'; |
232 | 228 | $group_id = self::$supergroup_id; |
233 | - } |
|
234 | - else { |
|
229 | + } else { |
|
235 | 230 | $category = 'groups'; |
236 | 231 | $group_id = self::$group_id; |
237 | 232 | } |
@@ -247,8 +242,7 @@ discard block |
||
247 | 242 | if (empty(self::$group)) { |
248 | 243 | $category = 'supergroups'; |
249 | 244 | $group_id = self::$supergroup_id; |
250 | - } |
|
251 | - else { |
|
245 | + } else { |
|
252 | 246 | $category = 'groups'; |
253 | 247 | $group_id = self::$group_id; |
254 | 248 | } |
@@ -265,8 +259,7 @@ discard block |
||
265 | 259 | self::$user = self::read($category . '/' . self::$user_id); |
266 | 260 | self::$old_user = clone self::$user; |
267 | 261 | self::$user->last_active = time(); |
268 | - } |
|
269 | - else { |
|
262 | + } else { |
|
270 | 263 | self::$ids[$category][] = self::$user_id; |
271 | 264 | self::$user = (object) self::$user_default_data; |
272 | 265 | self::$user->first_active = self::$user->last_active = time(); |
@@ -279,19 +272,16 @@ discard block |
||
279 | 272 | } |
280 | 273 | } |
281 | 274 | } |
282 | - } |
|
283 | - elseif ($type === chatType::CHANNEL) { |
|
275 | + } elseif ($type === chatType::CHANNEL) { |
|
284 | 276 | self::$channel_id = $update->chat->id; |
285 | 277 | if (in_array(self::$channel_id,self::$ids[$category])) { |
286 | 278 | self::$channel = self::read($category . '/' . self::$channel_id); |
287 | 279 | self::$old_channel = clone self::$channel; |
288 | - } |
|
289 | - else { |
|
280 | + } else { |
|
290 | 281 | self::$ids[$category][] = self::$channel_id; |
291 | 282 | self::$channel = (object) self::$channel_default_data; |
292 | 283 | } |
293 | - } |
|
294 | - else { |
|
284 | + } else { |
|
295 | 285 | self::$user_id = $update->from->id; |
296 | 286 | self::$group_user_id = self::$user_id; |
297 | 287 | $chat_id = $update->chat->id; |
@@ -302,22 +292,19 @@ discard block |
||
302 | 292 | self::$old_supergroup = clone self::$supergroup; |
303 | 293 | self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
304 | 294 | self::$old_group_ids = clone self::$group_ids; |
305 | - } |
|
306 | - else { |
|
295 | + } else { |
|
307 | 296 | self::$ids[$category][] = $chat_id; |
308 | 297 | self::$supergroup = (object) self::$supergroup_default_data; |
309 | 298 | self::$group_ids = []; |
310 | 299 | } |
311 | - } |
|
312 | - else { |
|
300 | + } else { |
|
313 | 301 | self::$group_id = $update->chat->id; |
314 | 302 | if (in_array($chat_id,self::$ids[$category])) { |
315 | 303 | self::$group = self::read($category . '/' . $chat_id); |
316 | 304 | self::$old_group = clone self::$group; |
317 | 305 | self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
318 | 306 | self::$old_group_ids = clone self::$group_ids; |
319 | - } |
|
320 | - else { |
|
307 | + } else { |
|
321 | 308 | self::$ids[$category][] = $chat_id; |
322 | 309 | self::$group = (object) self::$group_default_data; |
323 | 310 | self::$group_ids = []; |
@@ -327,15 +314,16 @@ discard block |
||
327 | 314 | if (in_array(self::$user_id,self::$group_ids)) { |
328 | 315 | self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id); |
329 | 316 | self::$old_group_user = clone self::$group_user; |
330 | - } |
|
331 | - else { |
|
317 | + } else { |
|
332 | 318 | self::$group_ids[] = self::$user_id; |
333 | 319 | self::$group_user = (object) self::$group_user_default_data; |
334 | 320 | } |
335 | 321 | |
336 | 322 | self::$user = self::read($category.'/'.self::$user_id); |
337 | 323 | self::$old_user = clone self::$user; |
338 | - if (!empty(self::$user)) self::$user->last_active = time(); |
|
324 | + if (!empty(self::$user)) { |
|
325 | + self::$user->last_active = time(); |
|
326 | + } |
|
339 | 327 | } |
340 | 328 | } |
341 | 329 | |
@@ -349,15 +337,13 @@ discard block |
||
349 | 337 | self::$old_user = clone self::$user; |
350 | 338 | self::$user->last_active = time(); |
351 | 339 | } |
352 | - } |
|
353 | - elseif ($type === chatType::CHANNEL) { |
|
340 | + } elseif ($type === chatType::CHANNEL) { |
|
354 | 341 | self::$channel_id = $update->message->chat->id; |
355 | 342 | if (in_array(self::$channel_id,self::$ids[$category])) { |
356 | 343 | self::$channel = self::read($category . '/' . self::$channel_id); |
357 | 344 | self::$old_channel = clone self::$channel; |
358 | 345 | } |
359 | - } |
|
360 | - else { |
|
346 | + } else { |
|
361 | 347 | self::$user_id = $update->from->id; |
362 | 348 | $chat_id = $update->message->chat->id; |
363 | 349 | if (in_array($chat_id,self::$ids[$category])) { |
@@ -365,8 +351,7 @@ discard block |
||
365 | 351 | self::$supergroup_id = $update->message->chat->id; |
366 | 352 | self::$supergroup = self::read($category . '/' . $chat_id); |
367 | 353 | self::$old_supergroup = clone self::$supergroup; |
368 | - } |
|
369 | - else { |
|
354 | + } else { |
|
370 | 355 | self::$group_id = $update->message->chat->id; |
371 | 356 | self::$group = self::read($category . '/' . $chat_id); |
372 | 357 | self::$old_group = clone self::$group; |
@@ -383,7 +368,9 @@ discard block |
||
383 | 368 | |
384 | 369 | self::$user = self::read($category.'/'.self::$user_id); |
385 | 370 | self::$old_user = clone self::$user; |
386 | - if (!empty(self::$user)) self::$user->last_active = time(); |
|
371 | + if (!empty(self::$user)) { |
|
372 | + self::$user->last_active = time(); |
|
373 | + } |
|
387 | 374 | } |
388 | 375 | } |
389 | 376 | |
@@ -409,13 +396,11 @@ discard block |
||
409 | 396 | if (in_array(self::$channel_id,self::$ids[$category])) { |
410 | 397 | self::$channel = self::read($category . '/' . self::$channel_id); |
411 | 398 | self::$old_channel = clone self::$channel; |
412 | - } |
|
413 | - else { |
|
399 | + } else { |
|
414 | 400 | self::$ids[$category][] = self::$channel_id; |
415 | 401 | self::$channel = (object) self::$channel_default_data; |
416 | 402 | } |
417 | - } |
|
418 | - else { |
|
403 | + } else { |
|
419 | 404 | $chat_id = $update->chat->id; |
420 | 405 | $by_id = $update->from->id; |
421 | 406 | $old_user = $update->old_chat_member; |
@@ -431,22 +416,19 @@ discard block |
||
431 | 416 | self::$old_supergroup = clone self::$supergroup; |
432 | 417 | self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
433 | 418 | self::$old_group_ids = clone self::$group_ids; |
434 | - } |
|
435 | - else { |
|
419 | + } else { |
|
436 | 420 | self::$ids[$category][] = $chat_id; |
437 | 421 | self::$supergroup = (object) self::$supergroup_default_data; |
438 | 422 | self::$group_ids = []; |
439 | 423 | } |
440 | - } |
|
441 | - elseif ($type === chatType::GROUP) { |
|
424 | + } elseif ($type === chatType::GROUP) { |
|
442 | 425 | self::$group_id = $chat_id; |
443 | 426 | if (in_array($chat_id,self::$ids[$category])) { |
444 | 427 | self::$group = self::read($category . '/' . $chat_id); |
445 | 428 | self::$old_group = clone self::$group; |
446 | 429 | self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
447 | 430 | self::$old_group_ids = clone self::$group_ids; |
448 | - } |
|
449 | - else { |
|
431 | + } else { |
|
450 | 432 | self::$ids[$category][] = $chat_id; |
451 | 433 | self::$group = (object) self::$group_default_data; |
452 | 434 | self::$group_ids = []; |
@@ -456,8 +438,7 @@ discard block |
||
456 | 438 | if (!in_array($user_id,self::$group_ids)) { |
457 | 439 | self::$group_ids[] = $user_id; |
458 | 440 | self::$group_user = (object) self::$group_user_default_data; |
459 | - } |
|
460 | - else { |
|
441 | + } else { |
|
461 | 442 | self::$group_user_id = $by_id == $user_id ? $user_id : $by_id; |
462 | 443 | self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$group_user_id); |
463 | 444 | } |
@@ -470,8 +451,7 @@ discard block |
||
470 | 451 | self::$group_user->removed_by = $by_id; |
471 | 452 | } |
472 | 453 | } |
473 | - } |
|
474 | - else { |
|
454 | + } else { |
|
475 | 455 | if ($old_user->status === chatMemberStatus::LEFT || $old_user->status === chatMemberStatus::KICKED) { |
476 | 456 | self::$group_user->presence = true; |
477 | 457 | self::$group_user->removed = false; |
@@ -481,8 +461,7 @@ discard block |
||
481 | 461 | if (!empty($invite_link)) { |
482 | 462 | self::$group_user->accepted_by = $by_id; |
483 | 463 | self::$group_user->invited_by = null; |
484 | - } |
|
485 | - else { |
|
464 | + } else { |
|
486 | 465 | self::$group_user->invited_by = $by_id; |
487 | 466 | self::$group_user->accepted_by = null; |
488 | 467 | } |
@@ -501,7 +480,9 @@ discard block |
||
501 | 480 | * @throws bptException |
502 | 481 | */ |
503 | 482 | public static function deleteUser (int $user_id = null): bool { |
504 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
483 | + if (empty($user_id)) { |
|
484 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
485 | + } |
|
505 | 486 | if (!file_exists(realpath(self::$folder . '/privates/' . $user_id . '.json'))) { |
506 | 487 | return false; |
507 | 488 | } |
@@ -522,7 +503,9 @@ discard block |
||
522 | 503 | * @throws bptException |
523 | 504 | */ |
524 | 505 | public static function deleteGroup (int $group_id = null): bool { |
525 | - if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID); |
|
506 | + if (empty($group_id)) { |
|
507 | + $group_id = telegram::catchFields(fields::CHAT_ID); |
|
508 | + } |
|
526 | 509 | if (!file_exists(realpath(self::$folder . '/groups/' . $group_id . '.json'))) { |
527 | 510 | return false; |
528 | 511 | } |
@@ -544,7 +527,9 @@ discard block |
||
544 | 527 | * @throws bptException |
545 | 528 | */ |
546 | 529 | public static function deleteSuperGroup (int $group_id = null): bool { |
547 | - if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID); |
|
530 | + if (empty($group_id)) { |
|
531 | + $group_id = telegram::catchFields(fields::CHAT_ID); |
|
532 | + } |
|
548 | 533 | if (!file_exists(realpath(self::$folder . '/supergroups/' . $group_id . '.json'))) { |
549 | 534 | return false; |
550 | 535 | } |
@@ -566,7 +551,9 @@ discard block |
||
566 | 551 | * @throws bptException |
567 | 552 | */ |
568 | 553 | public static function deleteChannel (int $channel_id = null): bool { |
569 | - if (empty($channel_id)) $channel_id = telegram::catchFields(fields::CHAT_ID); |
|
554 | + if (empty($channel_id)) { |
|
555 | + $channel_id = telegram::catchFields(fields::CHAT_ID); |
|
556 | + } |
|
570 | 557 | if (!file_exists(realpath(self::$folder . '/channels/' . $channel_id . '.json'))) { |
571 | 558 | return false; |
572 | 559 | } |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | if (file_exists($log_file) && !(filesize($log_file) > self::$log_size * 1024 * 1024)) { |
24 | 24 | $mode = 'a'; |
25 | 25 | $write = false; |
26 | - } |
|
27 | - else { |
|
26 | + } else { |
|
28 | 27 | $mode = 'w'; |
29 | 28 | $write = true; |
30 | 29 | } |
@@ -55,8 +54,7 @@ discard block |
||
55 | 54 | $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" ); |
56 | 55 | if (!is_null(self::$handler)) { |
57 | 56 | fwrite(self::$handler, $text); |
58 | - } |
|
59 | - else { |
|
57 | + } else { |
|
60 | 58 | self::$waited_logs[] = $text; |
61 | 59 | } |
62 | 60 | } |
@@ -69,17 +69,13 @@ discard block |
||
69 | 69 | if (self::$auto_process) { |
70 | 70 | if (isset(BPT::$update->message)) { |
71 | 71 | self::processMessage(BPT::$update->message); |
72 | - } |
|
73 | - elseif (isset(BPT::$update->edited_message)) { |
|
72 | + } elseif (isset(BPT::$update->edited_message)) { |
|
74 | 73 | self::processMessage(BPT::$update->edited_message); |
75 | - } |
|
76 | - elseif (isset(BPT::$update->callback_query)) { |
|
74 | + } elseif (isset(BPT::$update->callback_query)) { |
|
77 | 75 | self::processCallbackQuery(BPT::$update->callback_query); |
78 | - } |
|
79 | - elseif (isset(BPT::$update->inline_query)) { |
|
76 | + } elseif (isset(BPT::$update->inline_query)) { |
|
80 | 77 | self::processInlineQuery(BPT::$update->inline_query); |
81 | - } |
|
82 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
78 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
83 | 79 | self::processMyChatMember(BPT::$update->my_chat_member); |
84 | 80 | } |
85 | 81 | } |
@@ -136,8 +132,7 @@ discard block |
||
136 | 132 | if ($type === chatType::PRIVATE) { |
137 | 133 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
138 | 134 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
139 | - } |
|
140 | - else { |
|
135 | + } else { |
|
141 | 136 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
142 | 137 | } |
143 | 138 | } |
@@ -217,11 +212,9 @@ discard block |
||
217 | 212 | foreach ($vars as $var) { |
218 | 213 | if (is_int($var)) { |
219 | 214 | $types .= 'i'; |
220 | - } |
|
221 | - elseif (is_double($var)) { |
|
215 | + } elseif (is_double($var)) { |
|
222 | 216 | $types .= 'd'; |
223 | - } |
|
224 | - else { |
|
217 | + } else { |
|
225 | 218 | $types .= 's'; |
226 | 219 | } |
227 | 220 | } |
@@ -239,8 +232,7 @@ discard block |
||
239 | 232 | foreach ($array as $name => $value) { |
240 | 233 | if ($first) { |
241 | 234 | $first = false; |
242 | - } |
|
243 | - else { |
|
235 | + } else { |
|
244 | 236 | $query .= $operator; |
245 | 237 | } |
246 | 238 | $query .= " `$name` = ?"; |
@@ -257,8 +249,7 @@ discard block |
||
257 | 249 | } |
258 | 250 | if (!empty($count)) { |
259 | 251 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
260 | - } |
|
261 | - elseif (!empty($offset)) { |
|
252 | + } elseif (!empty($offset)) { |
|
262 | 253 | $query .= " OFFSET $offset"; |
263 | 254 | } |
264 | 255 | return $values; |
@@ -316,7 +307,9 @@ discard block |
||
316 | 307 | public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
317 | 308 | $query = "INSERT INTO `$table`("; |
318 | 309 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
319 | - if (is_string($values)) $values = [$values]; |
|
310 | + if (is_string($values)) { |
|
311 | + $values = [$values]; |
|
312 | + } |
|
320 | 313 | $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
321 | 314 | return self::query($query, $values, false); |
322 | 315 | } |
@@ -340,8 +333,7 @@ discard block |
||
340 | 333 | $query = "SELECT "; |
341 | 334 | if ($columns == '*') { |
342 | 335 | $query .= "* "; |
343 | - } |
|
344 | - else { |
|
336 | + } else { |
|
345 | 337 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
346 | 338 | } |
347 | 339 | $query .= "FROM `$table`"; |
@@ -402,8 +394,11 @@ discard block |
||
402 | 394 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
403 | 395 | $res = self::select($table, $columns, $where, $count, $offset); |
404 | 396 | if ($res) { |
405 | - while ($row = $res->fetch_assoc()) yield $row; |
|
397 | + while ($row = $res->fetch_assoc()) { |
|
398 | + yield $row; |
|
399 | + } |
|
400 | + } else { |
|
401 | + return $res; |
|
406 | 402 | } |
407 | - else return $res; |
|
408 | 403 | } |
409 | 404 | } |
410 | 405 | \ No newline at end of file |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | if (file_exists('vendor/autoload.php')){ |
9 | 9 | require 'vendor/autoload.php'; |
10 | -} |
|
11 | -else{ |
|
10 | +} else{ |
|
12 | 11 | if(!file_exists('BPT.phar')) { |
13 | 12 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
14 | 13 | } |
@@ -45,8 +44,7 @@ discard block |
||
45 | 44 | |
46 | 45 | if ($text === '/start') { |
47 | 46 | $this->sendMessage(self::START_TEXT,answer: true); |
48 | - } |
|
49 | - else { |
|
47 | + } else { |
|
50 | 48 | /** You could use both style */ |
51 | 49 | $message_id = $update->message_id; |
52 | 50 | #$message_id = $update->id; |
@@ -54,16 +52,13 @@ discard block |
||
54 | 52 | if (self::ADMIN === $user_id) { |
55 | 53 | if ($text === '/help') { |
56 | 54 | $this->sendMessage(self::HELP, answer: true); |
57 | - } |
|
58 | - elseif ($text === '/reply_on') { |
|
55 | + } elseif ($text === '/reply_on') { |
|
59 | 56 | mysql::update('users',['value'=>'reply_on'],['id'=>$user_id],1); |
60 | 57 | $this->sendMessage(self::REPLY_ON, answer: true); |
61 | - } |
|
62 | - elseif ($text === '/reply_off') { |
|
58 | + } elseif ($text === '/reply_off') { |
|
63 | 59 | mysql::update('users',['value'=>'reply_off'],['id'=>$user_id],1); |
64 | 60 | $this->sendMessage(self::REPLY_OFF, answer: true); |
65 | - } |
|
66 | - elseif (isset($update->reply_to_message)) { |
|
61 | + } elseif (isset($update->reply_to_message)) { |
|
67 | 62 | $reply_message_id = $update->reply_to_message->message_id; |
68 | 63 | |
69 | 64 | if ($update->reply_to_message->from->id === $user_id) { |
@@ -76,13 +71,11 @@ discard block |
||
76 | 71 | $data = $check_message->fetch_object(); |
77 | 72 | $receiver_id = $data->receiver_id; |
78 | 73 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id); |
79 | - } |
|
80 | - else { |
|
74 | + } else { |
|
81 | 75 | $this->sendMessage(self::NOT_FOUND, answer: true); |
82 | 76 | return; |
83 | 77 | } |
84 | - } |
|
85 | - else { |
|
78 | + } else { |
|
86 | 79 | $data = mysql::select('messages', ['sender_message_id','sender_id'], [ |
87 | 80 | 'receiver_message_id' => $reply_message_id, |
88 | 81 | 'receiver_id' => $user_id |
@@ -93,8 +86,7 @@ discard block |
||
93 | 86 | if ($value === 'reply_on') { |
94 | 87 | mysql::update('users',['value'=>''],['id'=>$user_id]); |
95 | 88 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id); |
96 | - } |
|
97 | - else { |
|
89 | + } else { |
|
98 | 90 | $result = $this->copyMessage($receiver_id); |
99 | 91 | } |
100 | 92 | } |
@@ -107,13 +99,11 @@ discard block |
||
107 | 99 | if (self::SHOW_STATUS) { |
108 | 100 | $this->sendMessage(self::SEND_SUCCESSFUL, answer: true); |
109 | 101 | } |
110 | - } |
|
111 | - else { |
|
102 | + } else { |
|
112 | 103 | $this->sendMessage(self::SEND_FAILED, answer: true); |
113 | 104 | } |
114 | 105 | } |
115 | - } |
|
116 | - else { |
|
106 | + } else { |
|
117 | 107 | $username = $update->from->username; |
118 | 108 | if (empty($username)) { |
119 | 109 | $name = $update->from->first_name . (!empty($update->from->last_name) ? (' ' . $update->from->last_name) : ''); |
@@ -137,8 +127,7 @@ discard block |
||
137 | 127 | ] |
138 | 128 | ] |
139 | 129 | ]; |
140 | - } |
|
141 | - else { |
|
130 | + } else { |
|
142 | 131 | $keyboard = [ |
143 | 132 | 'inline_keyboard' => [ |
144 | 133 | [ |
@@ -161,25 +150,21 @@ discard block |
||
161 | 150 | ],1); |
162 | 151 | if ($check_message->num_rows > 0) { |
163 | 152 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard); |
164 | - } |
|
165 | - else { |
|
153 | + } else { |
|
166 | 154 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
167 | 155 | } |
168 | - } |
|
169 | - else { |
|
156 | + } else { |
|
170 | 157 | $check_message = mysql::select('messages', 'sender_message_id', [ |
171 | 158 | 'receiver_message_id' => $reply_message_id, |
172 | 159 | 'receiver_id' => $user_id |
173 | 160 | ],1); |
174 | 161 | if ($check_message->num_rows > 0) { |
175 | 162 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard); |
176 | - } |
|
177 | - else { |
|
163 | + } else { |
|
178 | 164 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
179 | 165 | } |
180 | 166 | } |
181 | - } |
|
182 | - else { |
|
167 | + } else { |
|
183 | 168 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
184 | 169 | } |
185 | 170 | |
@@ -195,8 +180,7 @@ discard block |
||
195 | 180 | if (self::SHOW_STATUS) { |
196 | 181 | $this->sendMessage(self::SEND_SUCCESSFUL, answer: true); |
197 | 182 | } |
198 | - } |
|
199 | - else { |
|
183 | + } else { |
|
200 | 184 | $this->sendMessage(self::SEND_FAILED, answer: true); |
201 | 185 | } |
202 | 186 | } |