@@ -16,23 +16,23 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class getUpdates extends receiver { |
18 | 18 | #[NoReturn] |
19 | - public static function init () { |
|
19 | + public static function init() { |
|
20 | 20 | $last_update_id = self::loadData(); |
21 | - while(true) { |
|
21 | + while (true) { |
|
22 | 22 | if (!lock::exist('getUpdate')) { |
23 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates); |
|
23 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates); |
|
24 | 24 | if (!telegram::$status) { |
25 | - logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
|
26 | - BPT::exit(print_r($updates,true)); |
|
25 | + logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR); |
|
26 | + BPT::exit(print_r($updates, true)); |
|
27 | 27 | } |
28 | 28 | self::handleUpdates($updates); |
29 | - lock::save('getUpdate',BPT::$update->update_id+1); |
|
30 | - $last_update_id = BPT::$update->update_id+1; |
|
29 | + lock::save('getUpdate', BPT::$update->update_id + 1); |
|
30 | + $last_update_id = BPT::$update->update_id + 1; |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | - private static function loadData(): bool|int|string { |
|
35 | + private static function loadData(): bool | int | string { |
|
36 | 36 | if (lock::exist('getUpdate')) { |
37 | 37 | $last_update_id = lock::read('getUpdate'); |
38 | 38 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | self::deleteOldLocks(); |
41 | 41 | telegram::deleteWebhook(); |
42 | 42 | $last_update_id = 0; |
43 | - lock::save('getUpdate',0); |
|
43 | + lock::save('getUpdate', 0); |
|
44 | 44 | } |
45 | 45 | return $last_update_id; |
46 | 46 | } |
@@ -35,8 +35,7 @@ |
||
35 | 35 | private static function loadData(): bool|int|string { |
36 | 36 | if (lock::exist('getUpdate')) { |
37 | 37 | $last_update_id = lock::read('getUpdate'); |
38 | - } |
|
39 | - else { |
|
38 | + } else { |
|
40 | 39 | self::deleteOldLocks(); |
41 | 40 | telegram::deleteWebhook(); |
42 | 41 | $last_update_id = 0; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @internal Only for BPT self usage , Don't use it in your source! |
22 | 22 | */ |
23 | - public static function init () { |
|
23 | + public static function init() { |
|
24 | 24 | if (settings::$multi) { |
25 | 25 | multi::init(); |
26 | 26 | } |
@@ -49,24 +49,24 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - protected static function setWebhook(string $url,string $secret = '') { |
|
52 | + protected static function setWebhook(string $url, string $secret = '') { |
|
53 | 53 | $res = telegram::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret); |
54 | 54 | if (!telegram::$status) { |
55 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
|
56 | - BPT::exit(print_r($res,true)); |
|
55 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR); |
|
56 | + BPT::exit(print_r($res, true)); |
|
57 | 57 | } |
58 | - logger::write('Webhook was set successfully',loggerTypes::INFO); |
|
58 | + logger::write('Webhook was set successfully', loggerTypes::INFO); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | protected static function checkURL() { |
62 | 62 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
63 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR); |
|
63 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR); |
|
64 | 64 | throw new bptException('WEBHOOK_NEED_URL'); |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | private static function setURL(): string { |
69 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
69 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | protected static function setCertificate() { |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | self::setCertificate(); |
90 | 90 | $url = self::setURL(); |
91 | 91 | $secret = !empty(settings::$secret) ? settings::$secret : tools::randomString(64); |
92 | - self::setWebhook($url,$secret); |
|
93 | - lock::save('BPT-HOOK',$secret); |
|
92 | + self::setWebhook($url, $secret); |
|
93 | + lock::save('BPT-HOOK', $secret); |
|
94 | 94 | BPT::exit('Done'); |
95 | 95 | } |
96 | 96 | |
97 | 97 | private static function checkSecret() { |
98 | 98 | $secret = lock::read('BPT-HOOK'); |
99 | 99 | if ($secret !== self::getSecret()) { |
100 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING); |
|
100 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING); |
|
101 | 101 | self::processSetWebhook(); |
102 | 102 | } |
103 | 103 | } |
@@ -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(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); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return bool |
283 | 283 | * @throws bptException |
284 | 284 | */ |
285 | - public static function delete (string $path, bool $sub = true): bool { |
|
285 | + public static function delete(string $path, bool $sub = true): bool { |
|
286 | 286 | if (!is_dir($path)) { |
287 | 287 | return unlink($path); |
288 | 288 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | return rmdir($path); |
291 | 291 | } |
292 | 292 | if (!$sub) { |
293 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
293 | + logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR); |
|
294 | 294 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
295 | 295 | } |
296 | 296 | $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @return bool |
313 | 313 | * @throws bptException when zip extension not found |
314 | 314 | */ |
315 | - public static function zip (string $path, string $destination): bool { |
|
315 | + public static function zip(string $path, string $destination): bool { |
|
316 | 316 | if (!extension_loaded('zip')) { |
317 | 317 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
318 | 318 | throw new bptException('ZIP_EXTENSION_MISSING'); |
@@ -347,14 +347,14 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return bool true on success and false in failure |
349 | 349 | */ |
350 | - public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool { |
|
350 | + public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool { |
|
351 | 351 | $file = fopen($url, 'rb'); |
352 | 352 | if (!$file) return false; |
353 | 353 | $path = fopen($path, 'wb'); |
354 | 354 | if (!$path) return false; |
355 | 355 | |
356 | 356 | $length = $chunk_size * 1024; |
357 | - while (!feof($file)){ |
|
357 | + while (!feof($file)) { |
|
358 | 358 | fwrite($path, fread($file, $length), $length); |
359 | 359 | } |
360 | 360 | fclose($path); |
@@ -376,10 +376,10 @@ discard block |
||
376 | 376 | * |
377 | 377 | * @return string |
378 | 378 | */ |
379 | - public static function byteFormat (int $byte, int $precision = 2): string { |
|
379 | + public static function byteFormat(int $byte, int $precision = 2): string { |
|
380 | 380 | $rate_counter = 0; |
381 | 381 | |
382 | - while ($byte > 1024){ |
|
382 | + while ($byte > 1024) { |
|
383 | 383 | $byte /= 1024; |
384 | 384 | $rate_counter++; |
385 | 385 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $byte = round($byte, $precision); |
389 | 389 | } |
390 | 390 | |
391 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
391 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -405,10 +405,10 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @return string|false return false when mode is incorrect |
407 | 407 | */ |
408 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
408 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
409 | 409 | return match ($mode) { |
410 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
411 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
410 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
411 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
412 | 412 | parseMode::MARKDOWNV2 => str_replace( |
413 | 413 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
414 | 414 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
448 | 448 | * @throws Exception |
449 | 449 | */ |
450 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
450 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
451 | 451 | if (!isset($base_time)) { |
452 | 452 | $base_time = '@'.time(); |
453 | 453 | } |
454 | 454 | $base_time = new DateTime($base_time); |
455 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
455 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
456 | 456 | |
457 | 457 | $diff = $base_time->diff($target_time); |
458 | 458 | |
@@ -479,12 +479,12 @@ discard block |
||
479 | 479 | * |
480 | 480 | * @return string[]|string |
481 | 481 | */ |
482 | - public static function realEscapeString(string|array $input): string|array { |
|
483 | - if(is_array($input)) { |
|
482 | + public static function realEscapeString(string | array $input): string | array { |
|
483 | + if (is_array($input)) { |
|
484 | 484 | return array_map(__METHOD__, $input); |
485 | 485 | } |
486 | 486 | |
487 | - if(!empty($input) && is_string($input)) { |
|
487 | + if (!empty($input) && is_string($input)) { |
|
488 | 488 | return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input); |
489 | 489 | } |
490 | 490 | |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return string[]|string |
504 | 504 | */ |
505 | - public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array { |
|
505 | + public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array { |
|
506 | 506 | $pos = strpos($subject, $search); |
507 | 507 | if ($pos !== false) { |
508 | 508 | return substr_replace($subject, $replace, $pos, strlen($search)); |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @return string see possible values in fileType class |
521 | 521 | */ |
522 | - public static function fileType (string $file_id): string { |
|
522 | + public static function fileType(string $file_id): string { |
|
523 | 523 | $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '=')); |
524 | 524 | $new = ''; |
525 | 525 | $last = ''; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $last = $char; |
534 | 534 | } |
535 | 535 | } |
536 | - $data = unpack('VtypeId/Vdc_id', $new . $last); |
|
536 | + $data = unpack('VtypeId/Vdc_id', $new.$last); |
|
537 | 537 | $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216; |
538 | 538 | return [ |
539 | 539 | fileTypes::THUMBNAIL, |
@@ -571,10 +571,10 @@ discard block |
||
571 | 571 | * |
572 | 572 | * @return string |
573 | 573 | */ |
574 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
574 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string { |
|
575 | 575 | $rand_string = ''; |
576 | 576 | $char_len = strlen($characters) - 1; |
577 | - for ($i = 0; $i < $length; $i ++) { |
|
577 | + for ($i = 0; $i < $length; $i++) { |
|
578 | 578 | $rand_string .= $characters[rand(0, $char_len)]; |
579 | 579 | } |
580 | 580 | return $rand_string; |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline |
604 | 604 | * @throws bptException |
605 | 605 | */ |
606 | - public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
|
606 | + public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup { |
|
607 | 607 | if (!empty($keyboard)) { |
608 | 608 | $keyboard_object = new replyKeyboardMarkup(); |
609 | 609 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | return $keyboard_object; |
668 | 668 | } |
669 | 669 | else { |
670 | - logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
|
670 | + logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR); |
|
671 | 671 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
672 | 672 | } |
673 | 673 | } |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | * |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
|
687 | + public static function inviteLink(int $user_id = null, string $bot_username = null): string { |
|
688 | 688 | if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
689 | 689 | if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
690 | - return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
|
690 | + return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -711,9 +711,9 @@ discard block |
||
711 | 711 | * @return string|bool|array{hash:string, key:string, iv:string} |
712 | 712 | * @throws bptException |
713 | 713 | */ |
714 | - public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
714 | + public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
715 | 715 | if (!extension_loaded('openssl')) { |
716 | - logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
716 | + logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
717 | 717 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
718 | 718 | } |
719 | 719 | if ($action === cryptoAction::ENCRYPT) { |
@@ -724,17 +724,17 @@ discard block |
||
724 | 724 | } |
725 | 725 | elseif ($action === cryptoAction::DECRYPT) { |
726 | 726 | if (empty($key)) { |
727 | - logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
|
727 | + logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR); |
|
728 | 728 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
729 | 729 | } |
730 | 730 | if (empty($iv)) { |
731 | - logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
|
731 | + logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR); |
|
732 | 732 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
733 | 733 | } |
734 | 734 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
735 | 735 | } |
736 | 736 | else { |
737 | - logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
737 | + logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
738 | 738 | return false; |
739 | 739 | } |
740 | 740 | } |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | public static function shortEncode(int $num): string { |
752 | 752 | $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
753 | 753 | $array = []; |
754 | - while ($num > 0){ |
|
754 | + while ($num > 0) { |
|
755 | 755 | $array[] = $num % 62; |
756 | 756 | $num = floor($num / 62); |
757 | 757 | } |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | foreach ($array as &$value) { |
760 | 760 | $value = $codes[$value]; |
761 | 761 | } |
762 | - return strrev(implode('',$array)); |
|
762 | + return strrev(implode('', $array)); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | $num = 0; |
777 | 777 | $text = str_split(strrev($text)); |
778 | 778 | foreach ($text as $key=>$value) { |
779 | - $num += strpos($codes,$value) * pow(62,$key); |
|
779 | + $num += strpos($codes, $value) * pow(62, $key); |
|
780 | 780 | } |
781 | 781 | return $num; |
782 | 782 | } |
@@ -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 | $size = file_exists($path) ? filesize($path) : false; |
265 | 265 | } |
266 | 266 | if (isset($size) && is_numeric($size)) { |
@@ -329,8 +329,7 @@ discard block |
||
329 | 329 | $zip->addFile($filePath, substr($filePath, $root_len)); |
330 | 330 | } |
331 | 331 | } |
332 | - } |
|
333 | - else { |
|
332 | + } else { |
|
334 | 333 | $zip->addFile($path, basename($path)); |
335 | 334 | } |
336 | 335 | return $zip->close(); |
@@ -349,9 +348,13 @@ discard block |
||
349 | 348 | */ |
350 | 349 | public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool { |
351 | 350 | $file = fopen($url, 'rb'); |
352 | - if (!$file) return false; |
|
351 | + if (!$file) { |
|
352 | + return false; |
|
353 | + } |
|
353 | 354 | $path = fopen($path, 'wb'); |
354 | - if (!$path) return false; |
|
355 | + if (!$path) { |
|
356 | + return false; |
|
357 | + } |
|
355 | 358 | |
356 | 359 | $length = $chunk_size * 1024; |
357 | 360 | while (!feof($file)){ |
@@ -460,8 +463,9 @@ discard block |
||
460 | 463 | foreach ($string as $k => &$v) { |
461 | 464 | if ($diff->$v) { |
462 | 465 | $v = $diff->$v; |
466 | + } else { |
|
467 | + unset($string[$k]); |
|
463 | 468 | } |
464 | - else unset($string[$k]); |
|
465 | 469 | } |
466 | 470 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
467 | 471 | |
@@ -527,8 +531,7 @@ discard block |
||
527 | 531 | if ($last === "\0") { |
528 | 532 | $new .= str_repeat($last, ord($char)); |
529 | 533 | $last = ''; |
530 | - } |
|
531 | - else { |
|
534 | + } else { |
|
532 | 535 | $new .= $last; |
533 | 536 | $last = $char; |
534 | 537 | } |
@@ -612,7 +615,9 @@ discard block |
||
612 | 615 | } |
613 | 616 | $rows = []; |
614 | 617 | foreach ($keyboard as $row) { |
615 | - if (!is_array($row)) continue; |
|
618 | + if (!is_array($row)) { |
|
619 | + continue; |
|
620 | + } |
|
616 | 621 | $buttons = []; |
617 | 622 | foreach ($row as $base_button) { |
618 | 623 | $button_info = explode('||', $base_button); |
@@ -621,15 +626,12 @@ discard block |
||
621 | 626 | if (count($button_info) > 1) { |
622 | 627 | if ($button_info[1] === 'con') { |
623 | 628 | $button->setRequest_contact(true); |
624 | - } |
|
625 | - elseif ($button_info[1] === 'loc') { |
|
629 | + } elseif ($button_info[1] === 'loc') { |
|
626 | 630 | $button->setRequest_location(true); |
627 | - } |
|
628 | - elseif ($button_info[1] === 'poll') { |
|
631 | + } elseif ($button_info[1] === 'poll') { |
|
629 | 632 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
630 | 633 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
631 | - } |
|
632 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
634 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
633 | 635 | $url = $button_info[2]; |
634 | 636 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
635 | 637 | } |
@@ -640,8 +642,7 @@ discard block |
||
640 | 642 | } |
641 | 643 | $keyboard_object->setKeyboard($rows); |
642 | 644 | return $keyboard_object; |
643 | - } |
|
644 | - elseif (!empty($inline)) { |
|
645 | + } elseif (!empty($inline)) { |
|
645 | 646 | $keyboard_object = new inlineKeyboardMarkup(); |
646 | 647 | $rows = []; |
647 | 648 | foreach ($inline as $row) { |
@@ -651,12 +652,10 @@ discard block |
||
651 | 652 | if (isset($button_info[1])) { |
652 | 653 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
653 | 654 | $button->setText($button_info[0])->setUrl($button_info[1]); |
654 | - } |
|
655 | - else { |
|
655 | + } else { |
|
656 | 656 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
657 | 657 | } |
658 | - } |
|
659 | - else { |
|
658 | + } else { |
|
660 | 659 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
661 | 660 | } |
662 | 661 | $buttons[] = $button; |
@@ -665,8 +664,7 @@ discard block |
||
665 | 664 | } |
666 | 665 | $keyboard_object->setInline_keyboard($rows); |
667 | 666 | return $keyboard_object; |
668 | - } |
|
669 | - else { |
|
667 | + } else { |
|
670 | 668 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
671 | 669 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
672 | 670 | } |
@@ -685,8 +683,12 @@ discard block |
||
685 | 683 | * @return string |
686 | 684 | */ |
687 | 685 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
688 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
689 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
686 | + if (empty($user_id)) { |
|
687 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
688 | + } |
|
689 | + if (empty($bot_username)) { |
|
690 | + $bot_username = telegram::getMe()->username; |
|
691 | + } |
|
690 | 692 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
691 | 693 | } |
692 | 694 | |
@@ -721,8 +723,7 @@ discard block |
||
721 | 723 | $iv = self::randomString(); |
722 | 724 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
723 | 725 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
724 | - } |
|
725 | - elseif ($action === cryptoAction::DECRYPT) { |
|
726 | + } elseif ($action === cryptoAction::DECRYPT) { |
|
726 | 727 | if (empty($key)) { |
727 | 728 | logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
728 | 729 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
@@ -732,8 +733,7 @@ discard block |
||
732 | 733 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
733 | 734 | } |
734 | 735 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
735 | - } |
|
736 | - else { |
|
736 | + } else { |
|
737 | 737 | logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
738 | 738 | return false; |
739 | 739 | } |
@@ -755,7 +755,9 @@ discard block |
||
755 | 755 | $array[] = $num % 62; |
756 | 756 | $num = floor($num / 62); |
757 | 757 | } |
758 | - if (count($array) < 1) $array = [0]; |
|
758 | + if (count($array) < 1) { |
|
759 | + $array = [0]; |
|
760 | + } |
|
759 | 761 | foreach ($array as &$value) { |
760 | 762 | $value = $codes[$value]; |
761 | 763 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @internal Only for BPT self usage , Don't use it in your source! |
27 | 27 | */ |
28 | - public static function init (): void { |
|
28 | + public static function init(): void { |
|
29 | 29 | $host = settings::$db['host'] ?? 'localhost'; |
30 | 30 | $port = settings::$db['port'] ?? 3306; |
31 | 31 | $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown'; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $dbname = settings::$db['dbname']; |
34 | 34 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
35 | 35 | if (self::$connection->connect_errno) { |
36 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
36 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
37 | 37 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
38 | 38 | } |
39 | 39 | if (!lock::exist('BPT-MYSQL')) { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - private static function install (): void { |
|
44 | + private static function install(): void { |
|
45 | 45 | self::pureQuery(" |
46 | 46 | CREATE TABLE `users` |
47 | 47 | ( |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @internal Only for BPT self usage , Don't use it in your source! |
64 | 64 | */ |
65 | - public static function process (): void { |
|
65 | + public static function process(): void { |
|
66 | 66 | if (isset(BPT::$update->message)) { |
67 | 67 | self::processMessage(BPT::$update->message); |
68 | 68 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - private static function processMessage (message $update): void { |
|
83 | + private static function processMessage(message $update): void { |
|
84 | 84 | $type = $update->chat->type; |
85 | 85 | if ($type === chatType::PRIVATE) { |
86 | 86 | $user_id = $update->from->id; |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
109 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
110 | 110 | $type = $update->message->chat->type; |
111 | 111 | if ($type === chatType::PRIVATE) { |
112 | 112 | $user_id = $update->from->id; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - private static function processInlineQuery (inlineQuery $update): void { |
|
119 | + private static function processInlineQuery(inlineQuery $update): void { |
|
120 | 120 | $type = $update->chat_type; |
121 | 121 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
122 | 122 | $user_id = $update->from->id; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
129 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
130 | 130 | $type = $update->chat->type; |
131 | 131 | if ($type === chatType::PRIVATE) { |
132 | 132 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return mysqli |
145 | 145 | */ |
146 | - public static function getMysqli (): mysqli { |
|
146 | + public static function getMysqli(): mysqli { |
|
147 | 147 | return self::$connection; |
148 | 148 | } |
149 | 149 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return int|string |
154 | 154 | */ |
155 | - public static function affected_rows (): int|string { |
|
155 | + public static function affected_rows(): int | string { |
|
156 | 156 | return self::$connection->affected_rows; |
157 | 157 | } |
158 | 158 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @return int|string |
163 | 163 | */ |
164 | - public static function insert_id (): int|string { |
|
164 | + public static function insert_id(): int | string { |
|
165 | 165 | return self::$connection->insert_id; |
166 | 166 | } |
167 | 167 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public static function escapeString (string $text): string { |
|
175 | + public static function escapeString(string $text): string { |
|
176 | 176 | return self::$connection->real_escape_string($text); |
177 | 177 | } |
178 | 178 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @return mysqli_result|bool |
189 | 189 | */ |
190 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
190 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
191 | 191 | return self::$connection->query($query); |
192 | 192 | } |
193 | 193 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @return mysqli_result|bool |
206 | 206 | */ |
207 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
207 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
208 | 208 | $prepare = self::$connection->prepare($query); |
209 | 209 | if (!$prepare->execute($vars)) { |
210 | 210 | logger::write(loggerTypes::WARNING, $prepare->error); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | return $need_result ? $prepare->get_result() : true; |
214 | 214 | } |
215 | 215 | |
216 | - private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array { |
|
216 | + private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array { |
|
217 | 217 | $first = true; |
218 | 218 | $values = []; |
219 | 219 | foreach ($array as $name => $value) { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | return $values; |
230 | 230 | } |
231 | 231 | |
232 | - private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
232 | + private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
233 | 233 | $values = []; |
234 | 234 | if (!empty($where)) { |
235 | 235 | $query .= " WHERE"; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return mysqli_result|bool |
258 | 258 | */ |
259 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
259 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
260 | 260 | $query = "DELETE FROM `$table`"; |
261 | 261 | $res = self::makeQueryReady($query, $where, $count, $offset); |
262 | 262 | return self::query($query, $res, false); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @return mysqli_result|bool |
277 | 277 | */ |
278 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
278 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
279 | 279 | $query = "UPDATE `$table` SET"; |
280 | 280 | $values = self::makeArrayReady($query, $modify, ', '); |
281 | 281 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -293,11 +293,11 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @return mysqli_result|bool |
295 | 295 | */ |
296 | - public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
|
296 | + public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool { |
|
297 | 297 | $query = "INSERT INTO `$table`("; |
298 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
|
298 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES ('; |
|
299 | 299 | if (is_string($values)) $values = [$values]; |
300 | - $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
|
300 | + $query .= '?'.str_repeat(',?', count($values) - 1).')'; |
|
301 | 301 | return self::query($query, $values, false); |
302 | 302 | } |
303 | 303 | |
@@ -315,13 +315,13 @@ discard block |
||
315 | 315 | * |
316 | 316 | * @return mysqli_result|bool |
317 | 317 | */ |
318 | - public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
318 | + public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
319 | 319 | $query = "SELECT "; |
320 | 320 | if ($columns == '*') { |
321 | 321 | $query .= "* "; |
322 | 322 | } |
323 | 323 | else { |
324 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
|
324 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` '; |
|
325 | 325 | } |
326 | 326 | $query .= "FROM `$table`"; |
327 | 327 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * |
340 | 340 | * @return null|bool|array |
341 | 341 | */ |
342 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null { |
|
342 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null { |
|
343 | 343 | $res = self::select($table, $columns, $where, 1); |
344 | 344 | if ($res) { |
345 | 345 | return $res->fetch_assoc(); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*' |
357 | 357 | * @param array|null $where Set your ifs default : null |
358 | 358 | */ |
359 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null) { |
|
359 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null) { |
|
360 | 360 | $res = self::select($table, $columns, $where, 1); |
361 | 361 | if ($res) { |
362 | 362 | return $res->fetch_object(); |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @return bool|Generator |
380 | 380 | */ |
381 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
|
381 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator { |
|
382 | 382 | $res = self::select($table, $columns, $where, $count, $offset); |
383 | 383 | if ($res) { |
384 | 384 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -65,17 +65,13 @@ discard block |
||
65 | 65 | public static function process (): void { |
66 | 66 | if (isset(BPT::$update->message)) { |
67 | 67 | self::processMessage(BPT::$update->message); |
68 | - } |
|
69 | - elseif (isset(BPT::$update->edited_message)) { |
|
68 | + } elseif (isset(BPT::$update->edited_message)) { |
|
70 | 69 | self::processMessage(BPT::$update->edited_message); |
71 | - } |
|
72 | - elseif (isset(BPT::$update->callback_query)) { |
|
70 | + } elseif (isset(BPT::$update->callback_query)) { |
|
73 | 71 | self::processCallbackQuery(BPT::$update->callback_query); |
74 | - } |
|
75 | - elseif (isset(BPT::$update->inline_query)) { |
|
72 | + } elseif (isset(BPT::$update->inline_query)) { |
|
76 | 73 | self::processInlineQuery(BPT::$update->inline_query); |
77 | - } |
|
78 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
74 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
79 | 75 | self::processMyChatMember(BPT::$update->my_chat_member); |
80 | 76 | } |
81 | 77 | } |
@@ -131,8 +127,7 @@ discard block |
||
131 | 127 | if ($type === chatType::PRIVATE) { |
132 | 128 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
133 | 129 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
134 | - } |
|
135 | - else { |
|
130 | + } else { |
|
136 | 131 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
137 | 132 | } |
138 | 133 | } |
@@ -219,8 +214,7 @@ discard block |
||
219 | 214 | foreach ($array as $name => $value) { |
220 | 215 | if ($first) { |
221 | 216 | $first = false; |
222 | - } |
|
223 | - else { |
|
217 | + } else { |
|
224 | 218 | $query .= $operator; |
225 | 219 | } |
226 | 220 | $query .= " `$name` = ?"; |
@@ -237,8 +231,7 @@ discard block |
||
237 | 231 | } |
238 | 232 | if (!empty($count)) { |
239 | 233 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
240 | - } |
|
241 | - elseif (!empty($offset)) { |
|
234 | + } elseif (!empty($offset)) { |
|
242 | 235 | $query .= " OFFSET $offset"; |
243 | 236 | } |
244 | 237 | return $values; |
@@ -296,7 +289,9 @@ discard block |
||
296 | 289 | public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
297 | 290 | $query = "INSERT INTO `$table`("; |
298 | 291 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
299 | - if (is_string($values)) $values = [$values]; |
|
292 | + if (is_string($values)) { |
|
293 | + $values = [$values]; |
|
294 | + } |
|
300 | 295 | $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
301 | 296 | return self::query($query, $values, false); |
302 | 297 | } |
@@ -319,8 +314,7 @@ discard block |
||
319 | 314 | $query = "SELECT "; |
320 | 315 | if ($columns == '*') { |
321 | 316 | $query .= "* "; |
322 | - } |
|
323 | - else { |
|
317 | + } else { |
|
324 | 318 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
325 | 319 | } |
326 | 320 | $query .= "FROM `$table`"; |
@@ -381,8 +375,11 @@ discard block |
||
381 | 375 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
382 | 376 | $res = self::select($table, $columns, $where, $count, $offset); |
383 | 377 | if ($res) { |
384 | - while ($row = $res->fetch_assoc()) yield $row; |
|
378 | + while ($row = $res->fetch_assoc()) { |
|
379 | + yield $row; |
|
380 | + } |
|
381 | + } else { |
|
382 | + return $res; |
|
385 | 383 | } |
386 | - else return $res; |
|
387 | 384 | } |
388 | 385 | } |
389 | 386 | \ 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(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(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(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(self::$folder . '/privates/' . $user_id . '.json')) { |
|
505 | + if (!file_exists(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(self::$folder . '/groups/' . $group_id . '.json')) { |
|
526 | + if (!file_exists(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(self::$folder . '/supergroups/' . $group_id . '.json')) { |
|
548 | + if (!file_exists(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(self::$folder . '/channels/' . $channel_id . '.json')) { |
|
570 | + if (!file_exists(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(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(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(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(self::$folder . '/channels/' . $channel_id . '.json')) { |
571 | 558 | return false; |
572 | 559 | } |
@@ -257,13 +257,13 @@ discard block |
||
257 | 257 | * @method bool|responseError unpinAllForumTopicMessages (int|string|array $chat_id, int $message_thread_id, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success. |
258 | 258 | * @method bool|responseError unpinTopicMessages (int|string|array $chat_id, int $message_thread_id, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success. |
259 | 259 | */ |
260 | -class BPT extends telegram{ |
|
260 | +class BPT extends telegram { |
|
261 | 261 | public static update $update; |
262 | 262 | |
263 | 263 | public static BPT $handler; |
264 | 264 | |
265 | 265 | |
266 | - public function __construct (array|stdClass $settings) { |
|
266 | + public function __construct(array | stdClass $settings) { |
|
267 | 267 | static::$handler = &$this; |
268 | 268 | settings::init($settings); |
269 | 269 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | #[NoReturn] |
276 | - public static function exit (string|null $message = null) { |
|
276 | + public static function exit (string | null $message = null) { |
|
277 | 277 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
278 | 278 | } |
279 | 279 | } |