@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public static int $log_size = 10; |
| 27 | 27 | |
| 28 | - public static string|CURLFile|null $certificate = null; |
|
| 28 | + public static string | CURLFile | null $certificate = null; |
|
| 29 | 29 | |
| 30 | 30 | public static bool $handler = true; |
| 31 | 31 | |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query']; |
| 61 | 61 | |
| 62 | - public static array|null $db = ['type' => 'json']; |
|
| 62 | + public static array | null $db = ['type' => 'json']; |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * @internal Only for BPT self usage , Don't use it in your source! |
| 66 | 66 | */ |
| 67 | - public static function init (array|stdClass $settings): void { |
|
| 67 | + public static function init(array | stdClass $settings): void { |
|
| 68 | 68 | $settings = (array) $settings; |
| 69 | 69 | foreach ($settings as $setting => $value) { |
| 70 | 70 | try { |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | if (!is_dir(realpath('bots_files'))) { |
| 73 | 73 | mkdir('bots_files'); |
| 74 | 74 | } |
| 75 | - if (!is_dir(realpath('bots_files/' . $value))) { |
|
| 76 | - mkdir('bots_files/' . $value); |
|
| 75 | + if (!is_dir(realpath('bots_files/'.$value))) { |
|
| 76 | + mkdir('bots_files/'.$value); |
|
| 77 | 77 | } |
| 78 | - $value = 'bots_files/' . $value . '/'; |
|
| 78 | + $value = 'bots_files/'.$value.'/'; |
|
| 79 | 79 | } |
| 80 | 80 | self::$$setting = $value; |
| 81 | 81 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * @internal Only for BPT self usage , Don't use it in your source! |
| 110 | 110 | */ |
| 111 | - public static function done (): void { |
|
| 111 | + public static function done(): void { |
|
| 112 | 112 | if (self::$logger) { |
| 113 | 113 | $estimated = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2); |
| 114 | 114 | $status_message = match (true) { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - private static function security (): void { |
|
| 126 | + private static function security(): void { |
|
| 127 | 127 | if (self::$security) { |
| 128 | 128 | ini_set('magic_quotes_gpc', 'off'); |
| 129 | 129 | ini_set('sql.safe_mode', 'on'); |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - private static function secureFolder (): void { |
|
| 141 | + private static function secureFolder(): void { |
|
| 142 | 142 | if (self::$secure_folder) { |
| 143 | 143 | $address = explode('/', $_SERVER['REQUEST_URI']); |
| 144 | 144 | unset($address[count($address) - 1]); |
| 145 | - $address = implode('/', $address) . '/BPT.php'; |
|
| 145 | + $address = implode('/', $address).'/BPT.php'; |
|
| 146 | 146 | $text = "ErrorDocument 404 $address\nErrorDocument 403 $address\n Options -Indexes\n Order Deny,Allow\nDeny from all\nAllow from 127.0.0.1\n<Files *.php>\n Order Allow,Deny\n Allow from all\n</Files>"; |
| 147 | 147 | $htaccess = realpath('.htaccess'); |
| 148 | 148 | if (!file_exists($htaccess) || filesize($htaccess) != strlen($text)) { |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - private static function getUpdates (): void { |
|
| 154 | + private static function getUpdates(): void { |
|
| 155 | 155 | if (!self::$handler) { |
| 156 | 156 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler', loggerTypes::ERROR); |
| 157 | 157 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
@@ -748,8 +748,7 @@ discard block |
||
| 748 | 748 | self::setDefaults($action,$arguments); |
| 749 | 749 | if (isset($arguments['answer'])) { |
| 750 | 750 | return answer::init($action,$arguments); |
| 751 | - } |
|
| 752 | - else { |
|
| 751 | + } else { |
|
| 753 | 752 | $result = curl::init($action,$arguments); |
| 754 | 753 | if (!is_object($result)) { |
| 755 | 754 | return false; |
@@ -784,8 +783,7 @@ discard block |
||
| 784 | 783 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
| 785 | 784 | } |
| 786 | 785 | } |
| 787 | - } |
|
| 788 | - elseif ($file_params = self::methodFile($name)) { |
|
| 786 | + } elseif ($file_params = self::methodFile($name)) { |
|
| 789 | 787 | foreach ($file_params as $param) { |
| 790 | 788 | if (isset($arguments[$param]) && is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
| 791 | 789 | $arguments[$param] = new CURLFile($arguments[$param]); |
@@ -807,12 +805,10 @@ discard block |
||
| 807 | 805 | $value = new ($return[0]) ($value); |
| 808 | 806 | } |
| 809 | 807 | return $response; |
| 810 | - } |
|
| 811 | - else { |
|
| 808 | + } else { |
|
| 812 | 809 | return new ($return) ($response->result); |
| 813 | 810 | } |
| 814 | - } |
|
| 815 | - else { |
|
| 811 | + } else { |
|
| 816 | 812 | return $response->result; |
| 817 | 813 | } |
| 818 | 814 | } |
@@ -824,8 +820,7 @@ discard block |
||
| 824 | 820 | if (!isset($arguments[$default])){ |
| 825 | 821 | $arguments[$default] = self::catchFields($default); |
| 826 | 822 | } |
| 827 | - } |
|
| 828 | - elseif (isset(BPT::$update->$key) || $key === 'other') { |
|
| 823 | + } elseif (isset(BPT::$update->$key) || $key === 'other') { |
|
| 829 | 824 | foreach ($default as $def) { |
| 830 | 825 | if (!isset($arguments[$def])){ |
| 831 | 826 | $arguments[$def] = self::catchFields($def); |
@@ -841,8 +836,7 @@ discard block |
||
| 841 | 836 | self::$status = true; |
| 842 | 837 | self::$pure_response = $response; |
| 843 | 838 | return self::methodReturn($name,$response); |
| 844 | - } |
|
| 845 | - else { |
|
| 839 | + } else { |
|
| 846 | 840 | self::$status = false; |
| 847 | 841 | self::$pure_response = $response; |
| 848 | 842 | return new responseError($response); |
@@ -885,9 +879,13 @@ discard block |
||
| 885 | 879 | default => false |
| 886 | 880 | }; |
| 887 | 881 | case fields::FILE_ID : |
| 888 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
| 889 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
| 890 | - else return false; |
|
| 882 | + if (isset(BPT::$update->message)) { |
|
| 883 | + $type = 'message'; |
|
| 884 | + } elseif (isset(BPT::$update->edited_message)) { |
|
| 885 | + $type = 'edited_message'; |
|
| 886 | + } else { |
|
| 887 | + return false; |
|
| 888 | + } |
|
| 891 | 889 | |
| 892 | 890 | return match(true) { |
| 893 | 891 | isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id, |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return bool|int |
| 37 | 37 | */ |
| 38 | - public static function save(string $name, string $data): bool|int { |
|
| 39 | - return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock",0640); |
|
| 38 | + public static function save(string $name, string $data): bool | int { |
|
| 39 | + return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock", 0640); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return bool|string |
| 48 | 48 | */ |
| 49 | - public static function read(string $name): bool|string { |
|
| 49 | + public static function read(string $name): bool | string { |
|
| 50 | 50 | return file_get_contents(realpath(settings::$name."$name.lock")); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return bool|int |
| 59 | 59 | */ |
| 60 | - public static function mtime(string $name): bool|int { |
|
| 60 | + public static function mtime(string $name): bool | int { |
|
| 61 | 61 | return filemtime(realpath(settings::$name."$name.lock")); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -23,15 +23,13 @@ discard block |
||
| 23 | 23 | public static function init () { |
| 24 | 24 | if (settings::$multi) { |
| 25 | 25 | multi::init(); |
| 26 | - } |
|
| 27 | - else { |
|
| 26 | + } else { |
|
| 28 | 27 | if (lock::exist('BPT-HOOK')) { |
| 29 | 28 | receiver::telegramVerify(); |
| 30 | 29 | self::checkSecret(); |
| 31 | 30 | logger::write('Update received , lets process it ;)'); |
| 32 | 31 | receiver::processUpdate(); |
| 33 | - } |
|
| 34 | - else { |
|
| 32 | + } else { |
|
| 35 | 33 | self::processSetWebhook(); |
| 36 | 34 | } |
| 37 | 35 | } |
@@ -74,8 +72,7 @@ discard block |
||
| 74 | 72 | if (is_string(settings::$certificate)) { |
| 75 | 73 | if (file_exists(realpath(settings::$certificate))) { |
| 76 | 74 | settings::$certificate = new CURLFile(settings::$certificate); |
| 77 | - } |
|
| 78 | - else { |
|
| 75 | + } else { |
|
| 79 | 76 | settings::$certificate = null; |
| 80 | 77 | } |
| 81 | 78 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * tools class , gather what ever you need |
| 31 | 31 | */ |
| 32 | -class tools{ |
|
| 32 | +class tools { |
|
| 33 | 33 | /** |
| 34 | 34 | * Check the given username format |
| 35 | 35 | * |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public static function isUsername (string $username): bool { |
|
| 44 | + public static function isUsername(string $username): bool { |
|
| 45 | 45 | $length = strlen($username); |
| 46 | 46 | return !str_contains($username, '__') && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username); |
| 47 | 47 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - public static function ipInRange (string $ip, string $range): bool { |
|
| 61 | + public static function ipInRange(string $ip, string $range): bool { |
|
| 62 | 62 | if (!str_contains($range, '/')) { |
| 63 | 63 | $range .= '/32'; |
| 64 | 64 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return bool |
| 80 | 80 | */ |
| 81 | - public static function isTelegram (string $ip): bool { |
|
| 81 | + public static function isTelegram(string $ip): bool { |
|
| 82 | 82 | return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22'); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - public static function isCloudFlare (string $ip): bool { |
|
| 96 | + public static function isCloudFlare(string $ip): bool { |
|
| 97 | 97 | $cf_ips = ['173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22', '103.31.4.0/22', '141.101.64.0/18', '108.162.192.0/18', '190.93.240.0/20', '188.114.96.0/20', '197.234.240.0/22', '198.41.128.0/17', '162.158.0.0/15', '104.16.0.0/12', '104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22']; |
| 98 | 98 | foreach ($cf_ips as $cf_ip) { |
| 99 | - if (self::ipInRange($ip,$cf_ip)) { |
|
| 99 | + if (self::ipInRange($ip, $cf_ip)) { |
|
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return bool |
| 116 | 116 | */ |
| 117 | - public static function isArvanCloud (string $ip): bool { |
|
| 117 | + public static function isArvanCloud(string $ip): bool { |
|
| 118 | 118 | $ar_ips = ['185.143.232.0/22', '92.114.16.80/28', '2.146.0.0/28', '46.224.2.32/29', '89.187.178.96/29', '195.181.173.128/29', '89.187.169.88/29', '188.229.116.16/29', '83.123.255.56/31', '164.138.128.28/31', '94.182.182.28/30', '185.17.115.176/30', '5.213.255.36/31', '138.128.139.144/29', '5.200.14.8/29', '188.122.68.224/29', '188.122.83.176/29', '213.179.217.16/29', '185.179.201.192/29', '43.239.139.192/29', '213.179.197.16/29', '213.179.201.192/29', '109.200.214.248/29', '138.128.141.16/29', '188.122.78.136/29', '213.179.211.32/29', '103.194.164.24/29', '185.50.105.136/29', '213.179.213.16/29', '162.244.52.120/29', '188.122.80.240/29', '109.200.195.64/29', '109.200.199.224/29', '185.228.238.0/28', '94.182.153.24/29', '94.101.182.0/27', '37.152.184.208/28', '78.39.156.192/28', '158.255.77.238/31', '81.12.28.16/29', '176.65.192.202/31', '2.144.3.128/28', '89.45.48.64/28', '37.32.16.0/27', '37.32.17.0/27', '37.32.18.0/27']; |
| 119 | 119 | foreach ($ar_ips as $ar_ip) { |
| 120 | - if (self::ipInRange($ip,$ar_ip)) { |
|
| 120 | + if (self::ipInRange($ip, $ar_ip)) { |
|
| 121 | 121 | return true; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return bool|user return array when verify is active and token is true array of telegram getMe result |
| 139 | 139 | */ |
| 140 | - public static function isToken (string $token, bool $verify = false): bool|user { |
|
| 140 | + public static function isToken(string $token, bool $verify = false): bool | user { |
|
| 141 | 141 | if (!preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) { |
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | - if (!$verify){ |
|
| 144 | + if (!$verify) { |
|
| 145 | 145 | return true; |
| 146 | 146 | } |
| 147 | 147 | $res = telegram::me($token); |
@@ -171,14 +171,14 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return bool |
| 173 | 173 | */ |
| 174 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool { |
|
| 174 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool { |
|
| 175 | 175 | if (!is_array($ids)) { |
| 176 | 176 | $ids = [$ids]; |
| 177 | 177 | } |
| 178 | 178 | $user_id = $user_id ?? request::catchFields('user_id'); |
| 179 | 179 | |
| 180 | 180 | foreach ($ids as $id) { |
| 181 | - $check = telegram::getChatMember($id,$user_id); |
|
| 181 | + $check = telegram::getChatMember($id, $user_id); |
|
| 182 | 182 | if (telegram::$status) { |
| 183 | 183 | $check = $check->status; |
| 184 | 184 | if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) { |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return array keys will be id and values will be bool(null for not founded ids) |
| 207 | 207 | */ |
| 208 | - public static function joinChecker (array|string|int $ids , int|null $user_id = null): array { |
|
| 208 | + public static function joinChecker(array | string | int $ids, int | null $user_id = null): array { |
|
| 209 | 209 | if (!is_array($ids)) { |
| 210 | 210 | $ids = [$ids]; |
| 211 | 211 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | $result = []; |
| 215 | 215 | foreach ($ids as $id) { |
| 216 | - $check = telegram::getChatMember($id,$user_id); |
|
| 216 | + $check = telegram::getChatMember($id, $user_id); |
|
| 217 | 217 | if (telegram::$status) { |
| 218 | 218 | $check = $check->status; |
| 219 | 219 | $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @return bool |
| 234 | 234 | */ |
| 235 | 235 | public static function isShorted(string $text): bool{ |
| 236 | - return preg_match('/^[a-zA-Z0-9]+$/',$text); |
|
| 236 | + return preg_match('/^[a-zA-Z0-9]+$/', $text); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
| 252 | 252 | */ |
| 253 | - public static function size (string $path, bool $format = true): string|int|false { |
|
| 253 | + public static function size(string $path, bool $format = true): string | int | false { |
|
| 254 | 254 | if (filter_var($path, FILTER_VALIDATE_URL)) { |
| 255 | 255 | $ch = curl_init($path); |
| 256 | 256 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return bool |
| 284 | 284 | * @throws bptException |
| 285 | 285 | */ |
| 286 | - public static function delete (string $path, bool $sub = true): bool { |
|
| 286 | + public static function delete(string $path, bool $sub = true): bool { |
|
| 287 | 287 | $path = realpath($path); |
| 288 | 288 | if (!is_dir($path)) { |
| 289 | 289 | return unlink($path); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | return rmdir($path); |
| 293 | 293 | } |
| 294 | 294 | if (!$sub) { |
| 295 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
| 295 | + logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR); |
|
| 296 | 296 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
| 297 | 297 | } |
| 298 | 298 | $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @return bool |
| 315 | 315 | * @throws bptException when zip extension not found |
| 316 | 316 | */ |
| 317 | - public static function zip (string $path, string $destination): bool { |
|
| 317 | + public static function zip(string $path, string $destination): bool { |
|
| 318 | 318 | if (!extension_loaded('zip')) { |
| 319 | 319 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
| 320 | 320 | throw new bptException('ZIP_EXTENSION_MISSING'); |
@@ -349,14 +349,14 @@ discard block |
||
| 349 | 349 | * |
| 350 | 350 | * @return bool true on success and false in failure |
| 351 | 351 | */ |
| 352 | - public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool { |
|
| 352 | + public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool { |
|
| 353 | 353 | $file = fopen($url, 'rb'); |
| 354 | 354 | if (!$file) return false; |
| 355 | 355 | $path = fopen($path, 'wb'); |
| 356 | 356 | if (!$path) return false; |
| 357 | 357 | |
| 358 | 358 | $length = $chunk_size * 1024; |
| 359 | - while (!feof($file)){ |
|
| 359 | + while (!feof($file)) { |
|
| 360 | 360 | fwrite($path, fread($file, $length), $length); |
| 361 | 361 | } |
| 362 | 362 | fclose($path); |
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | * |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public static function byteFormat (int $byte, int $precision = 2): string { |
|
| 381 | + public static function byteFormat(int $byte, int $precision = 2): string { |
|
| 382 | 382 | $rate_counter = 0; |
| 383 | 383 | |
| 384 | - while ($byte > 1024){ |
|
| 384 | + while ($byte > 1024) { |
|
| 385 | 385 | $byte /= 1024; |
| 386 | 386 | $rate_counter++; |
| 387 | 387 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | $byte = round($byte, $precision); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 393 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -407,10 +407,10 @@ discard block |
||
| 407 | 407 | * |
| 408 | 408 | * @return string|false return false when mode is incorrect |
| 409 | 409 | */ |
| 410 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
| 410 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
| 411 | 411 | return match ($mode) { |
| 412 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
| 413 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
| 412 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
| 413 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
| 414 | 414 | parseMode::MARKDOWNV2 => str_replace( |
| 415 | 415 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
| 416 | 416 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -449,12 +449,12 @@ discard block |
||
| 449 | 449 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
| 450 | 450 | * @throws Exception |
| 451 | 451 | */ |
| 452 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
| 452 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
| 453 | 453 | if (!isset($base_time)) { |
| 454 | 454 | $base_time = '@'.time(); |
| 455 | 455 | } |
| 456 | 456 | $base_time = new DateTime($base_time); |
| 457 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
| 457 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
| 458 | 458 | |
| 459 | 459 | $diff = $base_time->diff($target_time); |
| 460 | 460 | |
@@ -481,12 +481,12 @@ discard block |
||
| 481 | 481 | * |
| 482 | 482 | * @return string[]|string |
| 483 | 483 | */ |
| 484 | - public static function realEscapeString(string|array $input): string|array { |
|
| 485 | - if(is_array($input)) { |
|
| 484 | + public static function realEscapeString(string | array $input): string | array { |
|
| 485 | + if (is_array($input)) { |
|
| 486 | 486 | return array_map(__METHOD__, $input); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if(!empty($input) && is_string($input)) { |
|
| 489 | + if (!empty($input) && is_string($input)) { |
|
| 490 | 490 | return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input); |
| 491 | 491 | } |
| 492 | 492 | |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | * |
| 505 | 505 | * @return string[]|string |
| 506 | 506 | */ |
| 507 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
| 507 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
| 508 | 508 | $pos = strpos($subject, $search); |
| 509 | 509 | if ($pos !== false) { |
| 510 | 510 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | * |
| 522 | 522 | * @return string see possible values in fileType class |
| 523 | 523 | */ |
| 524 | - public static function fileType (string $file_id): string { |
|
| 524 | + public static function fileType(string $file_id): string { |
|
| 525 | 525 | $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '=')); |
| 526 | 526 | $new = ''; |
| 527 | 527 | $last = ''; |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $last = $char; |
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | - $data = unpack('VtypeId/Vdc_id', $new . $last); |
|
| 538 | + $data = unpack('VtypeId/Vdc_id', $new.$last); |
|
| 539 | 539 | $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216; |
| 540 | 540 | return [ |
| 541 | 541 | fileTypes::THUMBNAIL, |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * |
| 574 | 574 | * @return string |
| 575 | 575 | */ |
| 576 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
| 576 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
| 577 | 577 | $rand_string = ''; |
| 578 | 578 | $char_len = strlen($characters) - 1; |
| 579 | - for ($i = 0; $i < $length; $i ++) { |
|
| 579 | + for ($i = 0; $i < $length; $i++) { |
|
| 580 | 580 | $rand_string .= $characters[rand(0, $char_len)]; |
| 581 | 581 | } |
| 582 | 582 | return $rand_string; |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
| 606 | 606 | * @throws bptException |
| 607 | 607 | */ |
| 608 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
| 608 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
| 609 | 609 | if (!empty($keyboard)) { |
| 610 | 610 | $keyboard_object = new replyKeyboardMarkup(); |
| 611 | 611 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | return $keyboard_object; |
| 670 | 670 | } |
| 671 | 671 | else { |
| 672 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
| 672 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
| 673 | 673 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
| 674 | 674 | } |
| 675 | 675 | } |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | * |
| 687 | 687 | * @return string |
| 688 | 688 | */ |
| 689 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
| 689 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
| 690 | 690 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
| 691 | 691 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
| 692 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
| 692 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -713,9 +713,9 @@ discard block |
||
| 713 | 713 | * @return string|bool|array{hash:string, key:string, iv:string} |
| 714 | 714 | * @throws bptException |
| 715 | 715 | */ |
| 716 | - public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
| 716 | + public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
| 717 | 717 | if (!extension_loaded('openssl')) { |
| 718 | - logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
| 718 | + logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
| 719 | 719 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
| 720 | 720 | } |
| 721 | 721 | if ($action === cryptoAction::ENCRYPT) { |
@@ -726,17 +726,17 @@ discard block |
||
| 726 | 726 | } |
| 727 | 727 | elseif ($action === cryptoAction::DECRYPT) { |
| 728 | 728 | if (empty($key)) { |
| 729 | - logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
|
| 729 | + logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR); |
|
| 730 | 730 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
| 731 | 731 | } |
| 732 | 732 | if (empty($iv)) { |
| 733 | - logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
|
| 733 | + logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR); |
|
| 734 | 734 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
| 735 | 735 | } |
| 736 | 736 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
| 737 | 737 | } |
| 738 | 738 | else { |
| 739 | - logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
| 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 | } |
| 742 | 742 | } |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | public static function shortEncode(int $num): string { |
| 754 | 754 | $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 755 | 755 | $array = []; |
| 756 | - while ($num > 0){ |
|
| 756 | + while ($num > 0) { |
|
| 757 | 757 | $array[] = $num % 62; |
| 758 | 758 | $num = floor($num / 62); |
| 759 | 759 | } |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | foreach ($array as &$value) { |
| 762 | 762 | $value = $codes[$value]; |
| 763 | 763 | } |
| 764 | - return strrev(implode('',$array)); |
|
| 764 | + return strrev(implode('', $array)); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | $num = 0; |
| 779 | 779 | $text = str_split(strrev($text)); |
| 780 | 780 | foreach ($text as $key=>$value) { |
| 781 | - $num += strpos($codes,$value) * pow(62,$key); |
|
| 781 | + $num += strpos($codes, $value) * pow(62, $key); |
|
| 782 | 782 | } |
| 783 | 783 | return $num; |
| 784 | 784 | } |
@@ -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 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @internal Only for BPT self usage , Don't use it in your source! |
| 29 | 29 | */ |
| 30 | - public static function init (): void { |
|
| 30 | + public static function init(): void { |
|
| 31 | 31 | $host = settings::$db['host'] ?? 'localhost'; |
| 32 | 32 | $port = settings::$db['port'] ?? 3306; |
| 33 | 33 | $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown'; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $dbname = settings::$db['dbname']; |
| 37 | 37 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
| 38 | 38 | if (self::$connection->connect_errno) { |
| 39 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
| 39 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
| 40 | 40 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
| 41 | 41 | } |
| 42 | 42 | if (self::$auto_process && !lock::exist('BPT-MYSQL')) { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private static function install (): void { |
|
| 47 | + private static function install(): void { |
|
| 48 | 48 | self::pureQuery(" |
| 49 | 49 | CREATE TABLE `users` |
| 50 | 50 | ( |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @internal Only for BPT self usage , Don't use it in your source! |
| 67 | 67 | */ |
| 68 | - public static function process (): void { |
|
| 68 | + public static function process(): void { |
|
| 69 | 69 | if (self::$auto_process) { |
| 70 | 70 | if (isset(BPT::$update->message)) { |
| 71 | 71 | self::processMessage(BPT::$update->message); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - private static function processMessage (message $update): void { |
|
| 88 | + private static function processMessage(message $update): void { |
|
| 89 | 89 | $type = $update->chat->type; |
| 90 | 90 | if ($type === chatType::PRIVATE) { |
| 91 | 91 | $user_id = $update->from->id; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
| 114 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
| 115 | 115 | $type = $update->message->chat->type; |
| 116 | 116 | if ($type === chatType::PRIVATE) { |
| 117 | 117 | $user_id = $update->from->id; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private static function processInlineQuery (inlineQuery $update): void { |
|
| 124 | + private static function processInlineQuery(inlineQuery $update): void { |
|
| 125 | 125 | $type = $update->chat_type; |
| 126 | 126 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
| 127 | 127 | $user_id = $update->from->id; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
| 134 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
| 135 | 135 | $type = $update->chat->type; |
| 136 | 136 | if ($type === chatType::PRIVATE) { |
| 137 | 137 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return mysqli |
| 150 | 150 | */ |
| 151 | - public static function getMysqli (): mysqli { |
|
| 151 | + public static function getMysqli(): mysqli { |
|
| 152 | 152 | return self::$connection; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return int|string |
| 159 | 159 | */ |
| 160 | - public static function affected_rows (): int|string { |
|
| 160 | + public static function affected_rows(): int | string { |
|
| 161 | 161 | return self::$connection->affected_rows; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return int|string |
| 168 | 168 | */ |
| 169 | - public static function insert_id (): int|string { |
|
| 169 | + public static function insert_id(): int | string { |
|
| 170 | 170 | return self::$connection->insert_id; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public static function escapeString (string $text): string { |
|
| 180 | + public static function escapeString(string $text): string { |
|
| 181 | 181 | return self::$connection->real_escape_string($text); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return mysqli_result|bool |
| 194 | 194 | */ |
| 195 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
| 195 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
| 196 | 196 | return self::$connection->query($query); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return mysqli_result|bool |
| 213 | 213 | */ |
| 214 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
| 214 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
| 215 | 215 | $prepare = self::$connection->prepare($query); |
| 216 | 216 | if (!$prepare->execute($vars)) { |
| 217 | 217 | logger::write(loggerTypes::WARNING, $prepare->error); |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | return $need_result ? $prepare->get_result() : true; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array { |
|
| 223 | + private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array { |
|
| 224 | 224 | $first = true; |
| 225 | 225 | $values = []; |
| 226 | 226 | foreach ($array as $name => $value) { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | return $values; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 239 | + private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 240 | 240 | $values = []; |
| 241 | 241 | if (!empty($where)) { |
| 242 | 242 | $query .= " WHERE"; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @return mysqli_result|bool |
| 265 | 265 | */ |
| 266 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 266 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 267 | 267 | $query = "DELETE FROM `$table`"; |
| 268 | 268 | $res = self::makeQueryReady($query, $where, $count, $offset); |
| 269 | 269 | return self::query($query, $res, false); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return mysqli_result|bool |
| 284 | 284 | */ |
| 285 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 285 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 286 | 286 | $query = "UPDATE `$table` SET"; |
| 287 | 287 | $values = self::makeArrayReady($query, $modify, ', '); |
| 288 | 288 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -300,11 +300,11 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @return mysqli_result|bool |
| 302 | 302 | */ |
| 303 | - public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
|
| 303 | + public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool { |
|
| 304 | 304 | $query = "INSERT INTO `$table`("; |
| 305 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
|
| 305 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES ('; |
|
| 306 | 306 | if (is_string($values)) $values = [$values]; |
| 307 | - $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
|
| 307 | + $query .= '?'.str_repeat(',?', count($values) - 1).')'; |
|
| 308 | 308 | return self::query($query, $values, false); |
| 309 | 309 | } |
| 310 | 310 | |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | * |
| 324 | 324 | * @return mysqli_result|bool |
| 325 | 325 | */ |
| 326 | - public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 326 | + public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 327 | 327 | $query = "SELECT "; |
| 328 | 328 | if ($columns == '*') { |
| 329 | 329 | $query .= "* "; |
| 330 | 330 | } |
| 331 | 331 | else { |
| 332 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
|
| 332 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` '; |
|
| 333 | 333 | } |
| 334 | 334 | $query .= "FROM `$table`"; |
| 335 | 335 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * |
| 348 | 348 | * @return null|bool|array |
| 349 | 349 | */ |
| 350 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null { |
|
| 350 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null { |
|
| 351 | 351 | $res = self::select($table, $columns, $where, 1); |
| 352 | 352 | if ($res) { |
| 353 | 353 | return $res->fetch_assoc(); |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*' |
| 365 | 365 | * @param array|null $where Set your ifs default : null |
| 366 | 366 | */ |
| 367 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null) { |
|
| 367 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null) { |
|
| 368 | 368 | $res = self::select($table, $columns, $where, 1); |
| 369 | 369 | if ($res) { |
| 370 | 370 | return $res->fetch_object(); |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | * |
| 387 | 387 | * @return bool|Generator |
| 388 | 388 | */ |
| 389 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
|
| 389 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator { |
|
| 390 | 390 | $res = self::select($table, $columns, $where, $count, $offset); |
| 391 | 391 | if ($res) { |
| 392 | 392 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -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 | } |
@@ -226,8 +221,7 @@ discard block |
||
| 226 | 221 | foreach ($array as $name => $value) { |
| 227 | 222 | if ($first) { |
| 228 | 223 | $first = false; |
| 229 | - } |
|
| 230 | - else { |
|
| 224 | + } else { |
|
| 231 | 225 | $query .= $operator; |
| 232 | 226 | } |
| 233 | 227 | $query .= " `$name` = ?"; |
@@ -244,8 +238,7 @@ discard block |
||
| 244 | 238 | } |
| 245 | 239 | if (!empty($count)) { |
| 246 | 240 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
| 247 | - } |
|
| 248 | - elseif (!empty($offset)) { |
|
| 241 | + } elseif (!empty($offset)) { |
|
| 249 | 242 | $query .= " OFFSET $offset"; |
| 250 | 243 | } |
| 251 | 244 | return $values; |
@@ -303,7 +296,9 @@ discard block |
||
| 303 | 296 | public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
| 304 | 297 | $query = "INSERT INTO `$table`("; |
| 305 | 298 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
| 306 | - if (is_string($values)) $values = [$values]; |
|
| 299 | + if (is_string($values)) { |
|
| 300 | + $values = [$values]; |
|
| 301 | + } |
|
| 307 | 302 | $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
| 308 | 303 | return self::query($query, $values, false); |
| 309 | 304 | } |
@@ -327,8 +322,7 @@ discard block |
||
| 327 | 322 | $query = "SELECT "; |
| 328 | 323 | if ($columns == '*') { |
| 329 | 324 | $query .= "* "; |
| 330 | - } |
|
| 331 | - else { |
|
| 325 | + } else { |
|
| 332 | 326 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
| 333 | 327 | } |
| 334 | 328 | $query .= "FROM `$table`"; |
@@ -389,8 +383,11 @@ discard block |
||
| 389 | 383 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
| 390 | 384 | $res = self::select($table, $columns, $where, $count, $offset); |
| 391 | 385 | if ($res) { |
| 392 | - while ($row = $res->fetch_assoc()) yield $row; |
|
| 386 | + while ($row = $res->fetch_assoc()) { |
|
| 387 | + yield $row; |
|
| 388 | + } |
|
| 389 | + } else { |
|
| 390 | + return $res; |
|
| 393 | 391 | } |
| 394 | - else return $res; |
|
| 395 | 392 | } |
| 396 | 393 | } |
| 397 | 394 | \ No newline at end of file |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | /** |
| 104 | 104 | * @internal Only for BPT self usage , Don't use it in your source! |
| 105 | 105 | */ |
| 106 | - public static function init (): void { |
|
| 106 | + public static function init(): void { |
|
| 107 | 107 | self::$folder = settings::$name.'database'; |
| 108 | 108 | self::$global_default_data = settings::$db['global'] ?? self::$global_default_data; |
| 109 | 109 | self::setUserDefaultData(); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | self::load(); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - private static function setUserDefaultData (): void { |
|
| 118 | + private static function setUserDefaultData(): void { |
|
| 119 | 119 | self::$user_default_data = settings::$db['user'] ?? self::$user_default_data; |
| 120 | 120 | if (!isset(self::$user_default_data['step'])) { |
| 121 | 121 | self::$user_default_data['step'] = 'none'; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - private static function setGroupUserDefaultData (): void { |
|
| 137 | + private static function setGroupUserDefaultData(): void { |
|
| 138 | 138 | self::$group_user_default_data = settings::$db['group_user'] ?? self::$group_user_default_data; |
| 139 | 139 | if (!isset(self::$group_user_default_data['step'])) { |
| 140 | 140 | self::$group_user_default_data['step'] = 'none'; |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (!file_exists(realpath(self::$folder.'/global.json'))) { |
| 165 | - file_put_contents(self::$folder.'/global.json',self::$global_default_data); |
|
| 165 | + file_put_contents(self::$folder.'/global.json', self::$global_default_data); |
|
| 166 | 166 | } |
| 167 | 167 | if (!file_exists(realpath(self::$folder.'/ids.json'))) { |
| 168 | - file_put_contents(self::$folder.'/ids.json',json_encode([ |
|
| 168 | + file_put_contents(self::$folder.'/ids.json', json_encode([ |
|
| 169 | 169 | 'privates' => [], |
| 170 | 170 | 'groups' => [], |
| 171 | 171 | 'supergroups' => [], |
@@ -174,25 +174,25 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - private static function load (): void { |
|
| 177 | + private static function load(): void { |
|
| 178 | 178 | self::$global = json_decode(file_get_contents(self::$folder.'/global.json')); |
| 179 | 179 | self::$old_global = clone self::$global; |
| 180 | - self::$ids = json_decode(file_get_contents(self::$folder.'/ids.json'),true); |
|
| 180 | + self::$ids = json_decode(file_get_contents(self::$folder.'/ids.json'), true); |
|
| 181 | 181 | self::$old_ids = clone self::$ids; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - private static function read (string $address) { |
|
| 184 | + private static function read(string $address) { |
|
| 185 | 185 | return file_exists(realpath(self::$folder.'/'.$address.'.json')) ? json_decode(file_get_contents(self::$folder.'/'.$address.'.json'), false) : null; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - private static function write (string $address,string $data): void { |
|
| 189 | - file_put_contents(self::$folder.'/'.$address.'.json',$data); |
|
| 188 | + private static function write(string $address, string $data): void { |
|
| 189 | + file_put_contents(self::$folder.'/'.$address.'.json', $data); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | 193 | * @internal Only for BPT self usage , Don't use it in your source! |
| 194 | 194 | */ |
| 195 | - public static function process (): void { |
|
| 195 | + public static function process(): void { |
|
| 196 | 196 | if (isset(BPT::$update->message)) { |
| 197 | 197 | self::processMessage(BPT::$update->message); |
| 198 | 198 | } |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | public static function save(): void { |
| 217 | 217 | if (self::$user !== self::$old_user && !empty(self::$user_id)) { |
| 218 | - self::write('privates/' . self::$user_id,json_encode(self::$user)); |
|
| 218 | + self::write('privates/'.self::$user_id, json_encode(self::$user)); |
|
| 219 | 219 | } |
| 220 | 220 | if (self::$group !== self::$old_group && !empty(self::$group_id)) { |
| 221 | - self::write('groups/' . self::$group_id,json_encode(self::$group)); |
|
| 221 | + self::write('groups/'.self::$group_id, json_encode(self::$group)); |
|
| 222 | 222 | } |
| 223 | 223 | if (self::$supergroup !== self::$old_supergroup && !empty(self::$supergroup_id)) { |
| 224 | - self::write('supergroups/' . self::$supergroup_id,json_encode(self::$supergroup)); |
|
| 224 | + self::write('supergroups/'.self::$supergroup_id, json_encode(self::$supergroup)); |
|
| 225 | 225 | } |
| 226 | 226 | if (self::$channel !== self::$old_channel && !empty(self::$channel_id)) { |
| 227 | - self::write('channels/' . self::$channel_id,json_encode(self::$channel)); |
|
| 227 | + self::write('channels/'.self::$channel_id, json_encode(self::$channel)); |
|
| 228 | 228 | } |
| 229 | 229 | if (self::$group_user !== self::$old_group_user && !empty(self::$group_user_id)) { |
| 230 | 230 | if (empty(self::$group)) { |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | $category = 'groups'; |
| 236 | 236 | $group_id = self::$group_id; |
| 237 | 237 | } |
| 238 | - self::write($category . '/' . $group_id . '/' . self::$group_user_id,json_encode(self::$group_user)); |
|
| 238 | + self::write($category.'/'.$group_id.'/'.self::$group_user_id, json_encode(self::$group_user)); |
|
| 239 | 239 | } |
| 240 | 240 | if (self::$ids !== self::$old_ids) { |
| 241 | - self::write('ids',json_encode(self::$ids)); |
|
| 241 | + self::write('ids', json_encode(self::$ids)); |
|
| 242 | 242 | } |
| 243 | 243 | if (self::$global !== self::$old_global) { |
| 244 | - self::write('global',json_encode(self::$global)); |
|
| 244 | + self::write('global', json_encode(self::$global)); |
|
| 245 | 245 | } |
| 246 | 246 | if (self::$group_ids !== self::$old_group_ids) { |
| 247 | 247 | if (empty(self::$group)) { |
@@ -252,17 +252,17 @@ discard block |
||
| 252 | 252 | $category = 'groups'; |
| 253 | 253 | $group_id = self::$group_id; |
| 254 | 254 | } |
| 255 | - self::write($category . '/' . $group_id . '/users',json_encode(self::$group_user)); |
|
| 255 | + self::write($category.'/'.$group_id.'/users', json_encode(self::$group_user)); |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | private static function processMessage(message $update): void { |
| 260 | 260 | $type = $update->chat->type; |
| 261 | - $category = $type . 's'; |
|
| 261 | + $category = $type.'s'; |
|
| 262 | 262 | if ($type === chatType::PRIVATE) { |
| 263 | 263 | self::$user_id = $update->from->id; |
| 264 | - if (in_array(self::$user_id,self::$ids[$category])) { |
|
| 265 | - self::$user = self::read($category . '/' . self::$user_id); |
|
| 264 | + if (in_array(self::$user_id, self::$ids[$category])) { |
|
| 265 | + self::$user = self::read($category.'/'.self::$user_id); |
|
| 266 | 266 | self::$old_user = clone self::$user; |
| 267 | 267 | self::$user->last_active = time(); |
| 268 | 268 | } |
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | self::$ids[$category][] = self::$user_id; |
| 271 | 271 | self::$user = (object) self::$user_default_data; |
| 272 | 272 | self::$user->first_active = self::$user->last_active = time(); |
| 273 | - if (isset($update->commend) && isset($update->commend_payload) && $update->commend === 'start' && str_starts_with($update->commend_payload,'ref_')) { |
|
| 274 | - if (tools::isShorted(substr($update->commend_payload,4))) { |
|
| 275 | - $referral = tools::shortDecode(substr($update->commend_payload,4)); |
|
| 276 | - if (in_array($referral,self::$ids[$category])) { |
|
| 273 | + if (isset($update->commend) && isset($update->commend_payload) && $update->commend === 'start' && str_starts_with($update->commend_payload, 'ref_')) { |
|
| 274 | + if (tools::isShorted(substr($update->commend_payload, 4))) { |
|
| 275 | + $referral = tools::shortDecode(substr($update->commend_payload, 4)); |
|
| 276 | + if (in_array($referral, self::$ids[$category])) { |
|
| 277 | 277 | self::$user->referral = $referral; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | elseif ($type === chatType::CHANNEL) { |
| 284 | 284 | self::$channel_id = $update->chat->id; |
| 285 | - if (in_array(self::$channel_id,self::$ids[$category])) { |
|
| 286 | - self::$channel = self::read($category . '/' . self::$channel_id); |
|
| 285 | + if (in_array(self::$channel_id, self::$ids[$category])) { |
|
| 286 | + self::$channel = self::read($category.'/'.self::$channel_id); |
|
| 287 | 287 | self::$old_channel = clone self::$channel; |
| 288 | 288 | } |
| 289 | 289 | else { |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | $chat_id = $update->chat->id; |
| 298 | 298 | if ($type === chatType::SUPERGROUP) { |
| 299 | 299 | self::$supergroup_id = $update->chat->id; |
| 300 | - if (in_array($chat_id,self::$ids[$category])) { |
|
| 301 | - self::$supergroup = self::read($category . '/' . $chat_id); |
|
| 300 | + if (in_array($chat_id, self::$ids[$category])) { |
|
| 301 | + self::$supergroup = self::read($category.'/'.$chat_id); |
|
| 302 | 302 | self::$old_supergroup = clone self::$supergroup; |
| 303 | - self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
|
| 303 | + self::$group_ids = self::read($category.'/'.$chat_id.'/users'); |
|
| 304 | 304 | self::$old_group_ids = clone self::$group_ids; |
| 305 | 305 | } |
| 306 | 306 | else { |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | else { |
| 313 | 313 | self::$group_id = $update->chat->id; |
| 314 | - if (in_array($chat_id,self::$ids[$category])) { |
|
| 315 | - self::$group = self::read($category . '/' . $chat_id); |
|
| 314 | + if (in_array($chat_id, self::$ids[$category])) { |
|
| 315 | + self::$group = self::read($category.'/'.$chat_id); |
|
| 316 | 316 | self::$old_group = clone self::$group; |
| 317 | - self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
|
| 317 | + self::$group_ids = self::read($category.'/'.$chat_id.'/users'); |
|
| 318 | 318 | self::$old_group_ids = clone self::$group_ids; |
| 319 | 319 | } |
| 320 | 320 | else { |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if (in_array(self::$user_id,self::$group_ids)) { |
|
| 328 | - self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id); |
|
| 327 | + if (in_array(self::$user_id, self::$group_ids)) { |
|
| 328 | + self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$user_id); |
|
| 329 | 329 | self::$old_group_user = clone self::$group_user; |
| 330 | 330 | } |
| 331 | 331 | else { |
@@ -341,42 +341,42 @@ discard block |
||
| 341 | 341 | |
| 342 | 342 | private static function processCallbackQuery(callbackQuery $update): void { |
| 343 | 343 | $type = $update->message->chat->type; |
| 344 | - $category = $type . 's'; |
|
| 344 | + $category = $type.'s'; |
|
| 345 | 345 | if ($type === chatType::PRIVATE) { |
| 346 | 346 | self::$user_id = $update->from->id; |
| 347 | - if (in_array(self::$user_id,self::$ids[$category])) { |
|
| 348 | - self::$user = self::read($category . '/' . self::$user_id); |
|
| 347 | + if (in_array(self::$user_id, self::$ids[$category])) { |
|
| 348 | + self::$user = self::read($category.'/'.self::$user_id); |
|
| 349 | 349 | self::$old_user = clone self::$user; |
| 350 | 350 | self::$user->last_active = time(); |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | elseif ($type === chatType::CHANNEL) { |
| 354 | 354 | self::$channel_id = $update->message->chat->id; |
| 355 | - if (in_array(self::$channel_id,self::$ids[$category])) { |
|
| 356 | - self::$channel = self::read($category . '/' . self::$channel_id); |
|
| 355 | + if (in_array(self::$channel_id, self::$ids[$category])) { |
|
| 356 | + self::$channel = self::read($category.'/'.self::$channel_id); |
|
| 357 | 357 | self::$old_channel = clone self::$channel; |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | else { |
| 361 | 361 | self::$user_id = $update->from->id; |
| 362 | 362 | $chat_id = $update->message->chat->id; |
| 363 | - if (in_array($chat_id,self::$ids[$category])) { |
|
| 363 | + if (in_array($chat_id, self::$ids[$category])) { |
|
| 364 | 364 | if ($type === chatType::SUPERGROUP) { |
| 365 | 365 | self::$supergroup_id = $update->message->chat->id; |
| 366 | - self::$supergroup = self::read($category . '/' . $chat_id); |
|
| 366 | + self::$supergroup = self::read($category.'/'.$chat_id); |
|
| 367 | 367 | self::$old_supergroup = clone self::$supergroup; |
| 368 | 368 | } |
| 369 | 369 | else { |
| 370 | 370 | self::$group_id = $update->message->chat->id; |
| 371 | - self::$group = self::read($category . '/' . $chat_id); |
|
| 371 | + self::$group = self::read($category.'/'.$chat_id); |
|
| 372 | 372 | self::$old_group = clone self::$group; |
| 373 | 373 | } |
| 374 | - self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
|
| 374 | + self::$group_ids = self::read($category.'/'.$chat_id.'/users'); |
|
| 375 | 375 | self::$old_group_ids = clone self::$group_ids; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if (in_array(self::$user_id,self::$group_ids)) { |
|
| 379 | - self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id); |
|
| 378 | + if (in_array(self::$user_id, self::$group_ids)) { |
|
| 379 | + self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$user_id); |
|
| 380 | 380 | self::$group_user_id = self::$user_id; |
| 381 | 381 | self::$old_group_user = clone self::$group_user; |
| 382 | 382 | } |
@@ -390,10 +390,10 @@ discard block |
||
| 390 | 390 | private static function processInlineQuery(inlineQuery $update): void { |
| 391 | 391 | $type = $update->chat_type; |
| 392 | 392 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
| 393 | - $category = chatType::PRIVATE . 's'; |
|
| 393 | + $category = chatType::PRIVATE.'s'; |
|
| 394 | 394 | self::$user_id = $update->from->id; |
| 395 | - if (in_array(self::$user_id,self::$ids[$category])) { |
|
| 396 | - self::$user = self::read($category . '/' . self::$user_id); |
|
| 395 | + if (in_array(self::$user_id, self::$ids[$category])) { |
|
| 396 | + self::$user = self::read($category.'/'.self::$user_id); |
|
| 397 | 397 | self::$old_user = clone self::$user; |
| 398 | 398 | self::$user->last_active = time(); |
| 399 | 399 | } |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | private static function processChatMember(chatMemberUpdated $update): void { |
| 404 | 404 | $type = $update->chat->type; |
| 405 | 405 | |
| 406 | - $category = $type . 's'; |
|
| 406 | + $category = $type.'s'; |
|
| 407 | 407 | if ($type === chatType::CHANNEL) { |
| 408 | 408 | self::$channel_id = $update->chat->id; |
| 409 | - if (in_array(self::$channel_id,self::$ids[$category])) { |
|
| 410 | - self::$channel = self::read($category . '/' . self::$channel_id); |
|
| 409 | + if (in_array(self::$channel_id, self::$ids[$category])) { |
|
| 410 | + self::$channel = self::read($category.'/'.self::$channel_id); |
|
| 411 | 411 | self::$old_channel = clone self::$channel; |
| 412 | 412 | } |
| 413 | 413 | else { |
@@ -426,10 +426,10 @@ discard block |
||
| 426 | 426 | |
| 427 | 427 | if ($type === chatType::SUPERGROUP) { |
| 428 | 428 | self::$supergroup_id = $chat_id; |
| 429 | - if (in_array($chat_id,self::$ids[$category])) { |
|
| 430 | - self::$supergroup = self::read($category . '/' . $chat_id); |
|
| 429 | + if (in_array($chat_id, self::$ids[$category])) { |
|
| 430 | + self::$supergroup = self::read($category.'/'.$chat_id); |
|
| 431 | 431 | self::$old_supergroup = clone self::$supergroup; |
| 432 | - self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
|
| 432 | + self::$group_ids = self::read($category.'/'.$chat_id.'/users'); |
|
| 433 | 433 | self::$old_group_ids = clone self::$group_ids; |
| 434 | 434 | } |
| 435 | 435 | else { |
@@ -440,10 +440,10 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | elseif ($type === chatType::GROUP) { |
| 442 | 442 | self::$group_id = $chat_id; |
| 443 | - if (in_array($chat_id,self::$ids[$category])) { |
|
| 444 | - self::$group = self::read($category . '/' . $chat_id); |
|
| 443 | + if (in_array($chat_id, self::$ids[$category])) { |
|
| 444 | + self::$group = self::read($category.'/'.$chat_id); |
|
| 445 | 445 | self::$old_group = clone self::$group; |
| 446 | - self::$group_ids = self::read($category . '/' . $chat_id . '/users'); |
|
| 446 | + self::$group_ids = self::read($category.'/'.$chat_id.'/users'); |
|
| 447 | 447 | self::$old_group_ids = clone self::$group_ids; |
| 448 | 448 | } |
| 449 | 449 | else { |
@@ -453,13 +453,13 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - if (!in_array($user_id,self::$group_ids)) { |
|
| 456 | + if (!in_array($user_id, self::$group_ids)) { |
|
| 457 | 457 | self::$group_ids[] = $user_id; |
| 458 | 458 | self::$group_user = (object) self::$group_user_default_data; |
| 459 | 459 | } |
| 460 | 460 | else { |
| 461 | 461 | self::$group_user_id = $by_id == $user_id ? $user_id : $by_id; |
| 462 | - self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$group_user_id); |
|
| 462 | + self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$group_user_id); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | if ($new_user->status === chatMemberStatus::LEFT || $new_user->status === chatMemberStatus::KICKED) { |
@@ -500,9 +500,9 @@ discard block |
||
| 500 | 500 | * @return bool |
| 501 | 501 | * @throws bptException |
| 502 | 502 | */ |
| 503 | - public static function deleteUser (int $user_id = null): bool { |
|
| 503 | + public static function deleteUser(int $user_id = null): bool { |
|
| 504 | 504 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
| 505 | - if (!file_exists(realpath(self::$folder . '/privates/' . $user_id . '.json'))) { |
|
| 505 | + if (!file_exists(realpath(self::$folder.'/privates/'.$user_id.'.json'))) { |
|
| 506 | 506 | return false; |
| 507 | 507 | } |
| 508 | 508 | unset(self::$ids['privates'][array_search($user_id, self::$ids['privates'])]); |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | if ($user_id === self::$user_id) { |
| 511 | 511 | self::$user = self::$old_user = null; |
| 512 | 512 | } |
| 513 | - return tools::delete(self::$folder . '/privates/' . $user_id . '.json'); |
|
| 513 | + return tools::delete(self::$folder.'/privates/'.$user_id.'.json'); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -521,18 +521,18 @@ discard block |
||
| 521 | 521 | * @return bool |
| 522 | 522 | * @throws bptException |
| 523 | 523 | */ |
| 524 | - public static function deleteGroup (int $group_id = null): bool { |
|
| 524 | + public static function deleteGroup(int $group_id = null): bool { |
|
| 525 | 525 | if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID); |
| 526 | - if (!file_exists(realpath(self::$folder . '/groups/' . $group_id . '.json'))) { |
|
| 526 | + if (!file_exists(realpath(self::$folder.'/groups/'.$group_id.'.json'))) { |
|
| 527 | 527 | return false; |
| 528 | 528 | } |
| 529 | 529 | unset(self::$ids['groups'][array_search($group_id, self::$ids['groups'])]); |
| 530 | 530 | sort(self::$ids['groups']); |
| 531 | - tools::delete(self::$folder . '/groups/' . $group_id); |
|
| 531 | + tools::delete(self::$folder.'/groups/'.$group_id); |
|
| 532 | 532 | if ($group_id === self::$group_id) { |
| 533 | 533 | self::$group = self::$old_group = null; |
| 534 | 534 | } |
| 535 | - return tools::delete(self::$folder . '/groups/' . $group_id . '.json'); |
|
| 535 | + return tools::delete(self::$folder.'/groups/'.$group_id.'.json'); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
@@ -543,18 +543,18 @@ discard block |
||
| 543 | 543 | * @return bool |
| 544 | 544 | * @throws bptException |
| 545 | 545 | */ |
| 546 | - public static function deleteSuperGroup (int $group_id = null): bool { |
|
| 546 | + public static function deleteSuperGroup(int $group_id = null): bool { |
|
| 547 | 547 | if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID); |
| 548 | - if (!file_exists(realpath(self::$folder . '/supergroups/' . $group_id . '.json'))) { |
|
| 548 | + if (!file_exists(realpath(self::$folder.'/supergroups/'.$group_id.'.json'))) { |
|
| 549 | 549 | return false; |
| 550 | 550 | } |
| 551 | 551 | unset(self::$ids['supergroups'][array_search($group_id, self::$ids['supergroups'])]); |
| 552 | 552 | sort(self::$ids['supergroups']); |
| 553 | - tools::delete(self::$folder . '/supergroups/' . $group_id); |
|
| 553 | + tools::delete(self::$folder.'/supergroups/'.$group_id); |
|
| 554 | 554 | if ($group_id === self::$supergroup_id) { |
| 555 | 555 | self::$supergroup = self::$old_supergroup = null; |
| 556 | 556 | } |
| 557 | - return tools::delete(self::$folder . '/supergroups/' . $group_id . '.json'); |
|
| 557 | + return tools::delete(self::$folder.'/supergroups/'.$group_id.'.json'); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -565,9 +565,9 @@ discard block |
||
| 565 | 565 | * @return bool |
| 566 | 566 | * @throws bptException |
| 567 | 567 | */ |
| 568 | - public static function deleteChannel (int $channel_id = null): bool { |
|
| 568 | + public static function deleteChannel(int $channel_id = null): bool { |
|
| 569 | 569 | if (empty($channel_id)) $channel_id = telegram::catchFields(fields::CHAT_ID); |
| 570 | - if (!file_exists(realpath(self::$folder . '/channels/' . $channel_id . '.json'))) { |
|
| 570 | + if (!file_exists(realpath(self::$folder.'/channels/'.$channel_id.'.json'))) { |
|
| 571 | 571 | return false; |
| 572 | 572 | } |
| 573 | 573 | unset(self::$ids['channels'][array_search($channel_id, self::$ids['channels'])]); |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | if ($channel_id === self::$channel_id) { |
| 576 | 576 | self::$channel = self::$old_channel = null; |
| 577 | 577 | } |
| 578 | - return tools::delete(self::$folder . '/channels/' . $channel_id . '.json'); |
|
| 578 | + return tools::delete(self::$folder.'/channels/'.$channel_id.'.json'); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | * |
| 584 | 584 | * @return int[] |
| 585 | 585 | */ |
| 586 | - public static function getUsers (): array { |
|
| 586 | + public static function getUsers(): array { |
|
| 587 | 587 | return self::$ids['privates'] ?? []; |
| 588 | 588 | } |
| 589 | 589 | |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * |
| 593 | 593 | * @return int[] |
| 594 | 594 | */ |
| 595 | - public static function getGroups (): array { |
|
| 595 | + public static function getGroups(): array { |
|
| 596 | 596 | return self::$ids['groups'] ?? []; |
| 597 | 597 | } |
| 598 | 598 | |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | * |
| 602 | 602 | * @return int[] |
| 603 | 603 | */ |
| 604 | - public static function getSuperGroups (): array { |
|
| 604 | + public static function getSuperGroups(): array { |
|
| 605 | 605 | return self::$ids['supergroups'] ?? []; |
| 606 | 606 | } |
| 607 | 607 | |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * |
| 611 | 611 | * @return int[] |
| 612 | 612 | */ |
| 613 | - public static function getChannels (): array { |
|
| 613 | + public static function getChannels(): array { |
|
| 614 | 614 | return self::$ids['channels'] ?? []; |
| 615 | 615 | } |
| 616 | 616 | } |
@@ -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 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
| 19 | 19 | */ |
| 20 | - public static function init (int $log_size = 10): void { |
|
| 20 | + public static function init(int $log_size = 10): void { |
|
| 21 | 21 | self::$log_size = $log_size; |
| 22 | 22 | $log_file = realpath(settings::$name.'BPT.log'); |
| 23 | 23 | if (file_exists($log_file) && !(filesize($log_file) > self::$log_size * 1024 * 1024)) { |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | self::$handler = fopen(settings::$name.'BPT.log', $mode); |
| 32 | 32 | |
| 33 | 33 | if ($write) { |
| 34 | - fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 34 | + fwrite(self::$handler, "♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | if (self::$waited_logs != []) { |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | 54 | public static function write(string $data, string $type = loggerTypes::NONE): void { |
| 55 | - $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" ); |
|
| 55 | + $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n"); |
|
| 56 | 56 | if (!is_null(self::$handler)) { |
| 57 | 57 | fwrite(self::$handler, $text); |
| 58 | 58 | } |
@@ -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 | } |