@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | public int $height; |
29 | 29 | |
30 | 30 | /** Optional. File size in bytes */ |
31 | - public null|int $file_size = null; |
|
31 | + public null | int $file_size = null; |
|
32 | 32 | |
33 | 33 | |
34 | - public function __construct(stdClass|null $object = null) { |
|
34 | + public function __construct(stdClass | null $object = null) { |
|
35 | 35 | if ($object != null) { |
36 | 36 | parent::__construct($object, self::subs); |
37 | 37 | } |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return bool|string string will be returned when destination doesn't set |
54 | 54 | */ |
55 | - public function download(string|null $destination = null): bool|string { |
|
56 | - return telegram::downloadFile($destination ?? 'unknown.jpg',$this->file_id); |
|
55 | + public function download(string | null $destination = null): bool | string { |
|
56 | + return telegram::downloadFile($destination ?? 'unknown.jpg', $this->file_id); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public string $big_file_unique_id; |
38 | 38 | |
39 | 39 | |
40 | - public function __construct(stdClass|null $object = null) { |
|
40 | + public function __construct(stdClass | null $object = null) { |
|
41 | 41 | if ($object != null) { |
42 | 42 | parent::__construct($object, self::subs); |
43 | 43 | } |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return bool|string string will be returned when destination doesn't set |
61 | 61 | */ |
62 | - public function download(string|null $destination = null,bool $big = true): bool|string { |
|
63 | - return telegram::downloadFile($destination ?? $this->file_name ?? 'unknown.mp4',$big ? $this->big_file_id : $this->small_file_id); |
|
62 | + public function download(string | null $destination = null, bool $big = true): bool | string { |
|
63 | + return telegram::downloadFile($destination ?? $this->file_name ?? 'unknown.mp4', $big ? $this->big_file_id : $this->small_file_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -31,22 +31,22 @@ discard block |
||
31 | 31 | public bool $is_revoked; |
32 | 32 | |
33 | 33 | /** Optional. Invite link name */ |
34 | - public null|string $name = null; |
|
34 | + public null | string $name = null; |
|
35 | 35 | |
36 | 36 | /** Optional. Point in time (Unix timestamp) when the link will expire or has been expired */ |
37 | - public null|int $expire_date = null; |
|
37 | + public null | int $expire_date = null; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat |
41 | 41 | * via this invite link; 1-99999 |
42 | 42 | */ |
43 | - public null|int $member_limit = null; |
|
43 | + public null | int $member_limit = null; |
|
44 | 44 | |
45 | 45 | /** Optional. Number of pending join requests created using this link */ |
46 | - public null|int $pending_join_request_count = null; |
|
46 | + public null | int $pending_join_request_count = null; |
|
47 | 47 | |
48 | 48 | |
49 | - public function __construct(stdClass|null $object = null) { |
|
49 | + public function __construct(stdClass | null $object = null) { |
|
50 | 50 | if ($object != null) { |
51 | 51 | parent::__construct($object, self::subs); |
52 | 52 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return responseError|bool|self |
59 | 59 | */ |
60 | - public function revoke(): self|responseError|bool { |
|
60 | + public function revoke(): self | responseError | bool { |
|
61 | 61 | return $this->is_revoked ?? telegram::revokeChatInviteLink($this->invite_link); |
62 | 62 | } |
63 | 63 | } |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @internal Only for BPT self usage , Don't use it in your source! |
18 | 18 | */ |
19 | - public static function init(): string|null { |
|
19 | + public static function init(): string | null { |
|
20 | 20 | return self::getUpdate(); |
21 | 21 | } |
22 | 22 | |
23 | - private static function getUpdate (): string|null { |
|
23 | + private static function getUpdate(): string | null { |
|
24 | 24 | $up = glob('*.update'); |
25 | 25 | if (!isset($up[0])) { |
26 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
26 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
27 | 27 | BPT::exit(); |
28 | 28 | } |
29 | 29 | $up = end($up); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | private static function create($file) { |
56 | - file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php ' . $file . ' > /dev/null &");'); |
|
56 | + file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php '.$file.' > /dev/null &");'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | #[ArrayShape(['url' => 'array|string|string[]', 'file' => 'string'])] |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * curl class , for multiprocessing with curl tricks |
14 | 14 | */ |
15 | 15 | class curl extends webhook { |
16 | - public static function init (): string|null { |
|
16 | + public static function init(): string | null { |
|
17 | 17 | if (!self::checkIP()) { |
18 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
18 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
19 | 19 | BPT::exit(); |
20 | 20 | } |
21 | 21 | return self::getUpdate(); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
26 | 26 | } |
27 | 27 | |
28 | - private static function getUpdate (): string { |
|
28 | + private static function getUpdate(): string { |
|
29 | 29 | $input = json_decode(file_get_contents('php://input'), true); |
30 | 30 | webhook::telegramVerify($input['ip']); |
31 | 31 | return $input['update']; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | lock::set('BPT-MULTI-CURL'); |
43 | 43 | } |
44 | 44 | |
45 | - private static function getTimeout($url): float|int { |
|
45 | + private static function getTimeout($url): float | int { |
|
46 | 46 | $times = []; |
47 | - for ($i = 0; $i < 10; $i ++) { |
|
47 | + for ($i = 0; $i < 10; $i++) { |
|
48 | 48 | $ch = curl_init($url); |
49 | 49 | curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([]), CURLOPT_TIMEOUT_MS => 100, CURLOPT_NOBODY => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => 100, CURLOPT_HTTPHEADER => ['accept: application/json', 'content-type: application/json']]); |
50 | 50 | $start = microtime(true); |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | return $timeout > 50 ? $timeout + 10 : 50; |
56 | 56 | } |
57 | 57 | |
58 | - private static function create($file,$timeout) { |
|
59 | - file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\'' . $file . '\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => ' . $timeout . ', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => ' . $timeout . ', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
58 | + private static function create($file, $timeout) { |
|
59 | + file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\''.$file.'\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => '.$timeout.', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => '.$timeout.', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | #[ArrayShape(['url' => 'array|string|string[]', 'file' => 'array|string|string[]'])] |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @internal Only for BPT self usage , Don't use it in your source! |
20 | 20 | */ |
21 | - public static function init () { |
|
21 | + public static function init() { |
|
22 | 22 | if (settings::$multi) { |
23 | 23 | multi::init(); |
24 | 24 | } |
@@ -38,28 +38,28 @@ discard block |
||
38 | 38 | lock::deleteIfExist(['BPT-MULTI-EXEC', 'BPT-MULTI-CURL', 'getUpdate', 'getUpdateHook']); |
39 | 39 | } |
40 | 40 | |
41 | - protected static function setWebhook(string $url,string $secret = '') { |
|
41 | + protected static function setWebhook(string $url, string $secret = '') { |
|
42 | 42 | $res = BPT::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret); |
43 | 43 | if (!BPT::$status) { |
44 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
|
45 | - BPT::exit(print_r($res,true)); |
|
44 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR); |
|
45 | + BPT::exit(print_r($res, true)); |
|
46 | 46 | } |
47 | - logger::write('Webhook was set successfully',loggerTypes::INFO); |
|
47 | + logger::write('Webhook was set successfully', loggerTypes::INFO); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | protected static function checkURL() { |
51 | 51 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
52 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR); |
|
52 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR); |
|
53 | 53 | throw new bptException('WEBHOOK_NEED_URL'); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | 57 | protected static function setURL(): string { |
58 | 58 | if (isset($_GET['token'])) { |
59 | - logger::write('You can not specify token in url',loggerTypes::ERROR); |
|
59 | + logger::write('You can not specify token in url', loggerTypes::ERROR); |
|
60 | 60 | BPT::exit('You can not specify token in url'); |
61 | 61 | } |
62 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
62 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | protected static function setCertificate() { |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | self::checkURL(); |
75 | 75 | self::setCertificate(); |
76 | 76 | $url = self::setURL(); |
77 | - $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':','---',settings::$token); |
|
78 | - self::setWebhook($url,$secret); |
|
77 | + $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':', '---', settings::$token); |
|
78 | + self::setWebhook($url, $secret); |
|
79 | 79 | lock::save('BPT-HOOK', md5($secret)); |
80 | 80 | BPT::exit('Done'); |
81 | 81 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | BPT::exit(); |
89 | 89 | } |
90 | 90 | if (settings::$telegram_verify) { |
91 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING); |
|
91 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING); |
|
92 | 92 | self::processSetWebhook(); |
93 | 93 | } |
94 | 94 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return bool |
112 | 112 | */ |
113 | - public static function fastClose (int $timeout = 86400): bool { |
|
113 | + public static function fastClose(int $timeout = 86400): bool { |
|
114 | 114 | if (settings::$multi || !lock::exist('BPT-HOOK') || settings::$receiver !== \BPT\constants\receiver::WEBHOOK) { |
115 | 115 | return false; |
116 | 116 | } |
@@ -9,18 +9,18 @@ discard block |
||
9 | 9 | use BPT\tools\tools; |
10 | 10 | |
11 | 11 | class callback { |
12 | - public static function encodeData (array $data): string { |
|
12 | + public static function encodeData(array $data): string { |
|
13 | 13 | return tools::codec(codecAction::ENCRYPT, json_encode($data), md5(settings::$token), 'SguQgUvvKRLvmCyq')['hash']; |
14 | 14 | } |
15 | 15 | |
16 | - public static function decodeData (string $data): array { |
|
16 | + public static function decodeData(string $data): array { |
|
17 | 17 | return json_decode(tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true); |
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @internal Only for BPT self usage , Don't use it in your source! |
22 | 22 | */ |
23 | - public static function process () { |
|
23 | + public static function process() { |
|
24 | 24 | if (!settings::$handler || settings::$receiver != \BPT\constants\receiver::WEBHOOK || settings::$multi || !(isset($_GET['data']) || isset($_POST['data']))) { |
25 | 25 | return false; |
26 | 26 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @internal Only for BPT self usage , Don't use it in your source! |
47 | 47 | */ |
48 | - public static function callHandler (string $handler_name, $input) { |
|
48 | + public static function callHandler(string $handler_name, $input) { |
|
49 | 49 | if (method_exists(BPT::$handler, $handler_name)) { |
50 | 50 | BPT::$handler->$handler_name($input); |
51 | 51 | } |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | * @method gameHighScore[]|responseError getGameHighScores (int|array|null $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects. |
300 | 300 | * @method gameHighScore[]|responseError getGameHigh (int|array|null $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects. |
301 | 301 | */ |
302 | -class BPT extends telegram{ |
|
303 | - public static stdClass|update $update; |
|
302 | +class BPT extends telegram { |
|
303 | + public static stdClass | update $update; |
|
304 | 304 | |
305 | 305 | public static BPT $handler; |
306 | 306 | |
307 | 307 | |
308 | - public function __construct (array|easySettings $settings) { |
|
308 | + public function __construct(array | easySettings $settings) { |
|
309 | 309 | static::$handler = &$this; |
310 | 310 | settings::init($settings); |
311 | 311 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | } |
316 | 316 | |
317 | 317 | #[NoReturn] |
318 | - public static function exit (string|null $message = null): void { |
|
318 | + public static function exit (string | null $message = null): void { |
|
319 | 319 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
320 | 320 | } |
321 | 321 | } |
@@ -16,32 +16,32 @@ |
||
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 | 21 | lock::set('getUpdateHook'); |
22 | - while(true) { |
|
22 | + while (true) { |
|
23 | 23 | if (!lock::exist('getUpdateHook')) { |
24 | - logger::write('getUpdateHook deleted, loop ended.',loggerTypes::INFO); |
|
24 | + logger::write('getUpdateHook deleted, loop ended.', loggerTypes::INFO); |
|
25 | 25 | break; |
26 | 26 | } |
27 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates); |
|
27 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates); |
|
28 | 28 | if (!telegram::$status) { |
29 | - logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR); |
|
30 | - BPT::exit(print_r($updates,true)); |
|
29 | + logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR); |
|
30 | + BPT::exit(print_r($updates, true)); |
|
31 | 31 | } |
32 | 32 | self::handleUpdates($updates); |
33 | - $last_update_id = BPT::$update->update_id+1; |
|
34 | - lock::save('getUpdate',$last_update_id); |
|
33 | + $last_update_id = BPT::$update->update_id + 1; |
|
34 | + lock::save('getUpdate', $last_update_id); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | - private static function loadData(): bool|int|string { |
|
38 | + private static function loadData(): bool | int | string { |
|
39 | 39 | if (lock::exist('getUpdate')) { |
40 | 40 | return lock::read('getUpdate'); |
41 | 41 | } |
42 | 42 | self::deleteOldLocks(); |
43 | 43 | telegram::deleteWebhook(); |
44 | - lock::save('getUpdate',0); |
|
44 | + lock::save('getUpdate', 0); |
|
45 | 45 | return 0; |
46 | 46 | } |
47 | 47 |