@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * curl class , for multiprocessing with curl tricks |
15 | 15 | */ |
16 | 16 | class curl extends webhook { |
17 | - public static function init (): string|null { |
|
17 | + public static function init(): string | null { |
|
18 | 18 | if (!self::checkIP()) { |
19 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
19 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING); |
|
20 | 20 | BPT::exit(); |
21 | 21 | } |
22 | 22 | return self::getUpdate(); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
27 | 27 | } |
28 | 28 | |
29 | - private static function getUpdate (): string { |
|
29 | + private static function getUpdate(): string { |
|
30 | 30 | $input = json_decode(file_get_contents("php://input"), true); |
31 | 31 | webhook::telegramVerify($input['ip']); |
32 | 32 | return $input['update']; |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | lock::set('BPT-MULTI-CURL'); |
44 | 44 | } |
45 | 45 | |
46 | - private static function getTimeout($url): float|int { |
|
46 | + private static function getTimeout($url): float | int { |
|
47 | 47 | $times = []; |
48 | - for ($i = 0; $i < 10; $i ++) { |
|
48 | + for ($i = 0; $i < 10; $i++) { |
|
49 | 49 | $ch = curl_init($url); |
50 | 50 | 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']]); |
51 | 51 | $start = microtime(true); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | return $timeout > 50 ? $timeout + 10 : 50; |
57 | 57 | } |
58 | 58 | |
59 | - private static function create($file,$timeout) { |
|
60 | - 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);?>'); |
|
59 | + private static function create($file, $timeout) { |
|
60 | + 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);?>'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | #[ArrayShape(['url' => "array|string|string[]", 'file' => "array|string|string[]"])] |
@@ -862,20 +862,17 @@ discard block |
||
862 | 862 | foreach ($arguments['media'] as $key => $media) { |
863 | 863 | if ($media['media'] instanceof CURLFile) { |
864 | 864 | $remove_answer = true; |
865 | - } |
|
866 | - elseif (is_string($media['media']) && file_exists(realpath($media['media']))) { |
|
865 | + } elseif (is_string($media['media']) && file_exists(realpath($media['media']))) { |
|
867 | 866 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
868 | 867 | $remove_answer = true; |
869 | 868 | } |
870 | 869 | } |
871 | - } |
|
872 | - elseif ($file_params = self::methodFile($name)) { |
|
870 | + } elseif ($file_params = self::methodFile($name)) { |
|
873 | 871 | foreach ($file_params as $param) { |
874 | 872 | if (isset($arguments[$param])) { |
875 | 873 | if ($arguments[$param] instanceof CURLFile) { |
876 | 874 | $remove_answer = true; |
877 | - } |
|
878 | - elseif (is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
|
875 | + } elseif (is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
|
879 | 876 | $arguments[$param] = new CURLFile($arguments[$param]); |
880 | 877 | $remove_answer = true; |
881 | 878 | } |
@@ -915,8 +912,7 @@ discard block |
||
915 | 912 | if (!isset($arguments[$default])){ |
916 | 913 | $arguments[$default] = self::catchFields($default); |
917 | 914 | } |
918 | - } |
|
919 | - elseif (isset(BPT::$update->$key) || $key === 'other') { |
|
915 | + } elseif (isset(BPT::$update->$key) || $key === 'other') { |
|
920 | 916 | foreach ($default as $def) { |
921 | 917 | if (!isset($arguments[$def])){ |
922 | 918 | $arguments[$def] = self::catchFields($def); |
@@ -987,9 +983,13 @@ discard block |
||
987 | 983 | default => false |
988 | 984 | }; |
989 | 985 | case fields::FILE_ID : |
990 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
991 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
992 | - else return false; |
|
986 | + if (isset(BPT::$update->message)) { |
|
987 | + $type = 'message'; |
|
988 | + } elseif (isset(BPT::$update->edited_message)) { |
|
989 | + $type = 'edited_message'; |
|
990 | + } else { |
|
991 | + return false; |
|
992 | + } |
|
993 | 993 | |
994 | 994 | return match(true) { |
995 | 995 | isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id, |
@@ -825,30 +825,30 @@ discard block |
||
825 | 825 | 'getGameHighScores' => ['BPT\types\gameHighScore'] |
826 | 826 | ]; |
827 | 827 | |
828 | - public static function __callStatic (string $name, array $arguments) { |
|
828 | + public static function __callStatic(string $name, array $arguments) { |
|
829 | 829 | if (!$action = self::methodAction($name)) { |
830 | - logger::write("$name method is not supported",loggerTypes::ERROR); |
|
830 | + logger::write("$name method is not supported", loggerTypes::ERROR); |
|
831 | 831 | throw new bptException('METHOD_NOT_FOUND'); |
832 | 832 | } |
833 | 833 | self::checkArguments($arguments); |
834 | - self::keysName($action,$arguments); |
|
835 | - self::readyFile($action,$arguments); |
|
834 | + self::keysName($action, $arguments); |
|
835 | + self::readyFile($action, $arguments); |
|
836 | 836 | self::cleanArguments($arguments); |
837 | - self::setDefaults($action,$arguments); |
|
837 | + self::setDefaults($action, $arguments); |
|
838 | 838 | |
839 | 839 | if (isset($arguments['answer']) && $arguments['answer'] === true) { |
840 | 840 | unset($arguments['answer']); |
841 | 841 | if (!answer::isAnswered()) { |
842 | - return answer::init($action,$arguments); |
|
842 | + return answer::init($action, $arguments); |
|
843 | 843 | } |
844 | - logger::write('you can use answer mode only once for each webhook update, Others will be called like normal',loggerTypes::WARNING); |
|
844 | + logger::write('you can use answer mode only once for each webhook update, Others will be called like normal', loggerTypes::WARNING); |
|
845 | 845 | } |
846 | - $result = curl::init($action,$arguments); |
|
846 | + $result = curl::init($action, $arguments); |
|
847 | 847 | if (!is_object($result)) { |
848 | - logger::write("Telegram $action method failed : " . $result, loggerTypes::WARNING); |
|
848 | + logger::write("Telegram $action method failed : ".$result, loggerTypes::WARNING); |
|
849 | 849 | return false; |
850 | 850 | } |
851 | - return self::processResponse($action,$result); |
|
851 | + return self::processResponse($action, $result); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | private static function checkArguments(array &$arguments): void { |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | } |
858 | 858 | } |
859 | 859 | |
860 | - private static function keysName (string $name, array &$arguments): void { |
|
860 | + private static function keysName(string $name, array &$arguments): void { |
|
861 | 861 | foreach ($arguments as $key => $argument) { |
862 | 862 | if (is_numeric($key) && isset(self::METHODS_KEYS[$name][$key])) { |
863 | 863 | $arguments[self::METHODS_KEYS[$name][$key]] = $argument; |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | } |
867 | 867 | } |
868 | 868 | |
869 | - private static function methodAction(string $name): string|false { |
|
869 | + private static function methodAction(string $name): string | false { |
|
870 | 870 | return self::METHODS_ACTION[str_replace('_', '', strtolower($name))] ?? false; |
871 | 871 | } |
872 | 872 | |
@@ -902,11 +902,11 @@ discard block |
||
902 | 902 | } |
903 | 903 | } |
904 | 904 | |
905 | - private static function methodFile(string $name): array|false { |
|
905 | + private static function methodFile(string $name): array | false { |
|
906 | 906 | return self::METHODS_WITH_FILE[$name] ?? false; |
907 | 907 | } |
908 | 908 | |
909 | - private static function methodReturn(string $name,stdClass $response) { |
|
909 | + private static function methodReturn(string $name, stdClass $response) { |
|
910 | 910 | if (!isset(self::METHODS_RETURN[$name])) { |
911 | 911 | return $response->result; |
912 | 912 | } |
@@ -925,13 +925,13 @@ discard block |
||
925 | 925 | $defaults = self::METHODS_EXTRA_DEFAULTS[$name] ?? []; |
926 | 926 | foreach ($defaults as $key => $default) { |
927 | 927 | if (is_numeric($key)) { |
928 | - if (!isset($arguments[$default])){ |
|
928 | + if (!isset($arguments[$default])) { |
|
929 | 929 | $arguments[$default] = self::catchFields($default); |
930 | 930 | } |
931 | 931 | } |
932 | 932 | elseif (isset(BPT::$update->$key) || $key === 'other') { |
933 | 933 | foreach ($default as $def) { |
934 | - if (!isset($arguments[$def])){ |
|
934 | + if (!isset($arguments[$def])) { |
|
935 | 935 | $arguments[$def] = self::catchFields($def); |
936 | 936 | } |
937 | 937 | } |
@@ -950,13 +950,13 @@ discard block |
||
950 | 950 | self::$status = $response->ok; |
951 | 951 | self::$pure_response = $response; |
952 | 952 | if (!$response->ok) { |
953 | - logger::write("Telegram $name method failed : " . json_encode($response), loggerTypes::WARNING); |
|
953 | + logger::write("Telegram $name method failed : ".json_encode($response), loggerTypes::WARNING); |
|
954 | 954 | return new responseError($response); |
955 | 955 | } |
956 | - return self::methodReturn($name,$response); |
|
956 | + return self::methodReturn($name, $response); |
|
957 | 957 | } |
958 | 958 | |
959 | - private static function cleanArguments (array &$arguments): void { |
|
959 | + private static function cleanArguments(array &$arguments): void { |
|
960 | 960 | foreach ($arguments as $key => $argument) { |
961 | 961 | if ($argument == [] || $argument === null) { |
962 | 962 | unset($arguments[$key]); |
@@ -971,7 +971,7 @@ discard block |
||
971 | 971 | * |
972 | 972 | * @return int|string|bool |
973 | 973 | */ |
974 | - public static function catchFields (string $field): int|string|bool { |
|
974 | + public static function catchFields(string $field): int | string | bool { |
|
975 | 975 | switch ($field) { |
976 | 976 | case fields::CHAT_ID : |
977 | 977 | case fields::FROM_CHAT_ID : |
@@ -1118,13 +1118,13 @@ discard block |
||
1118 | 1118 | default => false |
1119 | 1119 | }; |
1120 | 1120 | case fields::URL : |
1121 | - return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
1121 | + return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
1122 | 1122 | default: |
1123 | 1123 | return false; |
1124 | 1124 | } |
1125 | 1125 | } |
1126 | 1126 | |
1127 | - public static function fileLink (string|null $file_id = null): bool|string { |
|
1127 | + public static function fileLink(string | null $file_id = null): bool | string { |
|
1128 | 1128 | $file = request::getFile($file_id); |
1129 | 1129 | if (!isset($file->file_path)) { |
1130 | 1130 | return false; |
@@ -1146,7 +1146,7 @@ discard block |
||
1146 | 1146 | * |
1147 | 1147 | * @return bool |
1148 | 1148 | */ |
1149 | - public static function downloadFile (string|null $destination = null, string|null $file_id = null): bool { |
|
1149 | + public static function downloadFile(string | null $destination = null, string | null $file_id = null): bool { |
|
1150 | 1150 | return tools::downloadFile(self::fileLink($file_id), $destination); |
1151 | 1151 | } |
1152 | 1152 | |
@@ -1164,10 +1164,10 @@ discard block |
||
1164 | 1164 | * |
1165 | 1165 | * @return message|bool|responseError |
1166 | 1166 | */ |
1167 | - public static function sendFile (string $file_id, int|string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message|bool|responseError { |
|
1167 | + public static function sendFile(string $file_id, int | string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup | replyKeyboardMarkup | replyKeyboardRemove | forceReply | stdClass | array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message | bool | responseError { |
|
1168 | 1168 | $type = tools::fileType($file_id); |
1169 | 1169 | return match ($type) { |
1170 | - fileTypes::VIDEO => request::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false,null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
|
1170 | + fileTypes::VIDEO => request::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
|
1171 | 1171 | fileTypes::VIDEO_NOTE => request::sendVideoNote($file_id, $chat_id, $message_thread_id, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
1172 | 1172 | fileTypes::ANIMATION => request::sendAnimation($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
1173 | 1173 | fileTypes::AUDIO => request::sendAudio($file_id, $chat_id, $message_thread_id, $caption, $parse_mode, $caption_entities, null, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public bool $allow_channel_chats; |
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 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** Optional. Name of the Web App which was launched from a link */ |
16 | 16 | public string $web_app_name; |
17 | 17 | |
18 | - public function __construct(stdClass|null $object = null) { |
|
18 | + public function __construct(stdClass | null $object = null) { |
|
19 | 19 | if ($object != null) { |
20 | 20 | parent::__construct($object, self::subs); |
21 | 21 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * under <file_attach_name> name. Animated and video stickers can't be uploaded via HTTP URL. More information on |
20 | 20 | * Sending Files » |
21 | 21 | */ |
22 | - public string|CURLFile $sticker; |
|
22 | + public string | CURLFile $sticker; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * List of 1-20 emoji associated with the sticker |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public array $keywords; |
39 | 39 | |
40 | 40 | |
41 | - public function __construct(stdClass|null $object = null) { |
|
41 | + public function __construct(stdClass | null $object = null) { |
|
42 | 42 | if ($object != null) { |
43 | 43 | parent::__construct($object, self::subs); |
44 | 44 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public bool $via_chat_folder_invite_link; |
45 | 45 | |
46 | 46 | |
47 | - public function __construct(stdClass|null $object = null) { |
|
47 | + public function __construct(stdClass | null $object = null) { |
|
48 | 48 | if ($object != null) { |
49 | 49 | parent::__construct($object, self::subs); |
50 | 50 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | return $this->chat->isPrivate() && $this->isMe() && $this->isKicked(); |
59 | 59 | } |
60 | 60 | |
61 | - public function isMe (): bool { |
|
61 | + public function isMe(): bool { |
|
62 | 62 | return $this->new_chat_member->user->id == settings::$bot_id; |
63 | 63 | } |
64 | 64 | |
@@ -74,19 +74,19 @@ discard block |
||
74 | 74 | return $this->isJoined() && !empty($this->invite_link); |
75 | 75 | } |
76 | 76 | |
77 | - public function isLeaved (): bool { |
|
77 | + public function isLeaved(): bool { |
|
78 | 78 | return $this->new_chat_member->status === chatMemberStatus::LEFT; |
79 | 79 | } |
80 | 80 | |
81 | - public function isKicked (): bool { |
|
81 | + public function isKicked(): bool { |
|
82 | 82 | return $this->new_chat_member->status === chatMemberStatus::KICKED; |
83 | 83 | } |
84 | 84 | |
85 | - public function isOldAdmin (): bool { |
|
85 | + public function isOldAdmin(): bool { |
|
86 | 86 | return $this->old_chat_member->status === chatMemberStatus::ADMINISTRATOR && $this->isJoined(); |
87 | 87 | } |
88 | 88 | |
89 | - public function isNewAdmin (): bool { |
|
89 | + public function isNewAdmin(): bool { |
|
90 | 90 | return $this->new_chat_member->status === chatMemberStatus::ADMINISTRATOR; |
91 | 91 | } |
92 | 92 | } |
@@ -38,25 +38,25 @@ discard block |
||
38 | 38 | public int $height; |
39 | 39 | |
40 | 40 | /** True, if the sticker is animated */ |
41 | - public null|bool $is_animated = null; |
|
41 | + public null | bool $is_animated = null; |
|
42 | 42 | |
43 | 43 | /** True, if the sticker is a video sticker */ |
44 | - public null|bool $is_video = null; |
|
44 | + public null | bool $is_video = null; |
|
45 | 45 | |
46 | 46 | /** Optional. Sticker thumbnail in the .WEBP or .JPG format */ |
47 | - public null|photoSize $thumbnail = null; |
|
47 | + public null | photoSize $thumbnail = null; |
|
48 | 48 | |
49 | 49 | /** Optional. Emoji associated with the sticker */ |
50 | - public null|string $emoji = null; |
|
50 | + public null | string $emoji = null; |
|
51 | 51 | |
52 | 52 | /** Optional. Name of the sticker set to which the sticker belongs */ |
53 | - public null|string $set_name = null; |
|
53 | + public null | string $set_name = null; |
|
54 | 54 | |
55 | 55 | /** Optional. Premium animation for the sticker, if the sticker is premium */ |
56 | - public null|file $premium_animation = null; |
|
56 | + public null | file $premium_animation = null; |
|
57 | 57 | |
58 | 58 | /** Optional. For mask stickers, the position where the mask should be placed */ |
59 | - public null|maskPosition $mask_position = null; |
|
59 | + public null | maskPosition $mask_position = null; |
|
60 | 60 | |
61 | 61 | /** Optional. For custom emoji stickers, unique identifier of the custom emoji */ |
62 | 62 | public string $custom_emoji_id; |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | public bool $needs_repainting; |
69 | 69 | |
70 | 70 | /** Optional. File size in bytes */ |
71 | - public null|int $file_size = null; |
|
71 | + public null | int $file_size = null; |
|
72 | 72 | |
73 | 73 | |
74 | - public function __construct(stdClass|null $object = null) { |
|
74 | + public function __construct(stdClass | null $object = null) { |
|
75 | 75 | if ($object != null) { |
76 | 76 | parent::__construct($object, self::subs); |
77 | 77 | } |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return bool|string string will be returned when destination doesn't set |
94 | 94 | */ |
95 | - public function download(string|null $destination = null): bool|string { |
|
96 | - return telegram::downloadFile($destination ?? 'unknown.png',$this->file_id); |
|
95 | + public function download(string | null $destination = null): bool | string { |
|
96 | + return telegram::downloadFile($destination ?? 'unknown.png', $this->file_id); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function link(): string { |
@@ -33,7 +33,7 @@ |
||
33 | 33 | public string $start_parameter; |
34 | 34 | |
35 | 35 | |
36 | - public function __construct(stdClass|null $object = null) { |
|
36 | + public function __construct(stdClass | null $object = null) { |
|
37 | 37 | if ($object != null) { |
38 | 38 | parent::__construct($object, self::subs); |
39 | 39 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | public string $name; |
16 | 16 | |
17 | 17 | |
18 | - public function __construct(stdClass|null $object = null) { |
|
18 | + public function __construct(stdClass | null $object = null) { |
|
19 | 19 | if ($object != null) { |
20 | 20 | parent::__construct($object, self::subs); |
21 | 21 | } |