@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use CURLFile; |
| 13 | 13 | |
| 14 | 14 | class webhook {
|
| 15 | - public static function init () {
|
|
| 15 | + public static function init() {
|
|
| 16 | 16 | if (settings::$multi) {
|
| 17 | 17 | multi::init(); |
| 18 | 18 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | private static function telegramVerify() {
|
| 33 | 33 | if (settings::$telegram_verify) {
|
| 34 | 34 | if (!tools::isTelegram($_SERVER['REMOTE_ADDR'])) {
|
| 35 | - logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'],'error');
|
|
| 35 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'], 'error');
|
|
| 36 | 36 | BPT::exit(); |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -63,17 +63,17 @@ discard block |
||
| 63 | 63 | private static function setWebhook() {
|
| 64 | 64 | if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI'])) {
|
| 65 | 65 | self::setCertificate(); |
| 66 | - $url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 66 | + $url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 67 | 67 | |
| 68 | 68 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates); |
| 69 | 69 | if ($res->ok) {
|
| 70 | 70 | lock::set('BPT');
|
| 71 | - logger::write('Webhook was set successfully','info');
|
|
| 71 | + logger::write('Webhook was set successfully', 'info');
|
|
| 72 | 72 | BPT::exit('Done');
|
| 73 | 73 | } |
| 74 | 74 | else {
|
| 75 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),'error');
|
|
| 76 | - BPT::exit(print_r($res,true)); |
|
| 75 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), 'error');
|
|
| 76 | + BPT::exit(print_r($res, true)); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | else {
|
@@ -94,24 +94,24 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - private static function setMessageExtra(update &$update) {
|
|
| 98 | - if((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))){
|
|
| 97 | + private static function setMessageExtra(update & $update) {
|
|
| 98 | + if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) {
|
|
| 99 | 99 | if (isset($update->message)) $type = 'message'; |
| 100 | 100 | else $type = 'edited_message'; |
| 101 | 101 | |
| 102 | 102 | $text = &$update->$type->text; |
| 103 | - if (settings::$security){
|
|
| 103 | + if (settings::$security) {
|
|
| 104 | 104 | $text = tools::clearText($text); |
| 105 | 105 | } |
| 106 | - if (str_starts_with($text, '/')){
|
|
| 107 | - preg_match('/\/([a-zA-Z_0-9]{1,64})(@[a-zA-Z]\w{1,28}bot)?( [\S]{1,64})?/',$text,$result);
|
|
| 108 | - if (!empty($result[1])){
|
|
| 106 | + if (str_starts_with($text, '/')) {
|
|
| 107 | + preg_match('/\/([a-zA-Z_0-9]{1,64})(@[a-zA-Z]\w{1,28}bot)?( [\S]{1,64})?/', $text, $result);
|
|
| 108 | + if (!empty($result[1])) {
|
|
| 109 | 109 | $update->$type->commend = $result[1]; |
| 110 | 110 | } |
| 111 | - if (!empty($result[2])){
|
|
| 111 | + if (!empty($result[2])) {
|
|
| 112 | 112 | $update->$type->commend_username = $result[2]; |
| 113 | 113 | } |
| 114 | - if (!empty($result[3])){
|
|
| 114 | + if (!empty($result[3])) {
|
|
| 115 | 115 | $update->$type->commend_payload = $result[3]; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -15,14 +15,12 @@ discard block |
||
| 15 | 15 | public static function init () {
|
| 16 | 16 | if (settings::$multi) {
|
| 17 | 17 | multi::init(); |
| 18 | - } |
|
| 19 | - else {
|
|
| 18 | + } else {
|
|
| 20 | 19 | if (lock::exist('BPT-HOOK')) {
|
| 21 | 20 | self::telegramVerify(); |
| 22 | 21 | BPT::$update = self::processUpdate(); |
| 23 | 22 | logger::write('Update received , lets process it ;)');
|
| 24 | - } |
|
| 25 | - else {
|
|
| 23 | + } else {
|
|
| 26 | 24 | self::deleteOldLocks(); |
| 27 | 25 | self::setWebhook(); |
| 28 | 26 | } |
@@ -70,13 +68,11 @@ discard block |
||
| 70 | 68 | lock::set('BPT');
|
| 71 | 69 | logger::write('Webhook was set successfully','info');
|
| 72 | 70 | BPT::exit('Done');
|
| 73 | - } |
|
| 74 | - else {
|
|
| 71 | + } else {
|
|
| 75 | 72 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),'error');
|
| 76 | 73 | BPT::exit(print_r($res,true)); |
| 77 | 74 | } |
| 78 | - } |
|
| 79 | - else {
|
|
| 75 | + } else {
|
|
| 80 | 76 | logger::write('For using webhook receiver , you should open this file in your webserver(by domain)');
|
| 81 | 77 | } |
| 82 | 78 | } |
@@ -86,8 +82,7 @@ discard block |
||
| 86 | 82 | if (is_string(settings::$certificate)) {
|
| 87 | 83 | if (file_exists(settings::$certificate)) {
|
| 88 | 84 | settings::$certificate = new CURLFile(settings::$certificate); |
| 89 | - } |
|
| 90 | - else {
|
|
| 85 | + } else {
|
|
| 91 | 86 | settings::$certificate = null; |
| 92 | 87 | } |
| 93 | 88 | } |
@@ -96,8 +91,11 @@ discard block |
||
| 96 | 91 | |
| 97 | 92 | private static function setMessageExtra(update &$update) {
|
| 98 | 93 | if((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))){
|
| 99 | - if (isset($update->message)) $type = 'message'; |
|
| 100 | - else $type = 'edited_message'; |
|
| 94 | + if (isset($update->message)) { |
|
| 95 | + $type = 'message'; |
|
| 96 | + } else { |
|
| 97 | + $type = 'edited_message'; |
|
| 98 | + } |
|
| 101 | 99 | |
| 102 | 100 | $text = &$update->$type->text; |
| 103 | 101 | if (settings::$security){
|
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param string $username Your text to be check is username or not e.g. : 'BPT_CH' | '@BPT_CH' |
| 22 | 22 | * @return bool |
| 23 | 23 | */ |
| 24 | - public static function isUsername (string $username): bool {
|
|
| 24 | + public static function isUsername(string $username): bool {
|
|
| 25 | 25 | $length = strlen($username); |
| 26 | 26 | return strpos($username, '__') === false && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username);
|
| 27 | 27 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param string $range Your range ip for check , if you didn't specify the block , it will be 32 |
| 38 | 38 | * @return bool |
| 39 | 39 | */ |
| 40 | - public static function ipInRange (string $ip, string $range): bool {
|
|
| 40 | + public static function ipInRange(string $ip, string $range): bool {
|
|
| 41 | 41 | if (!str_contains($range, '/')) {
|
| 42 | 42 | $range .= '/32'; |
| 43 | 43 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $ip Your ip to be check is telegram or not e.g. '192.168.1.1' |
| 57 | 57 | * @return bool |
| 58 | 58 | */ |
| 59 | - public static function isTelegram (string $ip): bool {
|
|
| 59 | + public static function isTelegram(string $ip): bool {
|
|
| 60 | 60 | return self::ipInRange($ip, '149.154.160.0/20') || self::ipInRange($ip, '91.108.4.0/22'); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | * @param string $ip Your ip to be check is CloudFlare or not e.g. '192.168.1.1' |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | - public static function isCloudFlare (string $ip): bool {
|
|
| 73 | + public static function isCloudFlare(string $ip): bool {
|
|
| 74 | 74 | $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', '172.64.0.0/13', '131.0.72.0/22']; |
| 75 | 75 | foreach ($cf_ips as $cf_ip) {
|
| 76 | - if (self::ipInRange($ip,$cf_ip)) {
|
|
| 76 | + if (self::ipInRange($ip, $cf_ip)) {
|
|
| 77 | 77 | return true; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @param bool $verify check token with telegram or not |
| 95 | 95 | * @return bool|array return array when verify is active and token is true array of telegram getMe result |
| 96 | 96 | */ |
| 97 | - public static function isToken (string $token, bool $verify = false): bool|array {
|
|
| 97 | + public static function isToken(string $token, bool $verify = false): bool | array {
|
|
| 98 | 98 | if (preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) {
|
| 99 | - if ($verify){
|
|
| 99 | + if ($verify) {
|
|
| 100 | 100 | $res = telegram::me($token); |
| 101 | 101 | if ($res['ok']) {
|
| 102 | 102 | return $res['result']; |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @param int|null $user_id e.g. => '442109602' |
| 130 | 130 | * @return bool |
| 131 | 131 | */ |
| 132 | - public static function isJoined (array|string|int $ids , int|null $user_id = null): bool {
|
|
| 132 | + public static function isJoined(array | string | int $ids, int | null $user_id = null): bool {
|
|
| 133 | 133 | if (!is_array($ids)) {
|
| 134 | 134 | $ids = [$ids]; |
| 135 | 135 | } |
| 136 | 136 | //$user_id = $user_id ?? $this->catchFields(['field' => 'user_id']); |
| 137 | 137 | |
| 138 | 138 | foreach ($ids as $id) {
|
| 139 | - $check = telegram::getChatMember($id,$user_id); |
|
| 139 | + $check = telegram::getChatMember($id, $user_id); |
|
| 140 | 140 | if (isset($check['result'])) {
|
| 141 | 141 | $check = $check['result']['status']; |
| 142 | 142 | return !($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED); |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @param string $characters e.g. => 'abcdefg' |
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | - public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
|
|
| 167 | + public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
|
|
| 168 | 168 | $rand_string = ''; |
| 169 | 169 | $char_len = strlen($characters) - 1; |
| 170 | - for ($i = 0; $i < $length; $i ++) {
|
|
| 170 | + for ($i = 0; $i < $length; $i++) {
|
|
| 171 | 171 | $rand_string .= $characters[rand(0, $char_len)]; |
| 172 | 172 | } |
| 173 | 173 | return $rand_string; |
@@ -186,10 +186,10 @@ discard block |
||
| 186 | 186 | * @param string $mode Your selected mode e.g. => `parseMode::HTML` | `HTML` |
| 187 | 187 | * @return string|false return false when mode is incorrect |
| 188 | 188 | */ |
| 189 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false {
|
|
| 189 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false {
|
|
| 190 | 190 | return match ($mode) {
|
| 191 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
| 192 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
| 191 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
| 192 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
| 193 | 193 | parseMode::MARKDOWNV2 => str_replace( |
| 194 | 194 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'],
|
| 195 | 195 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'],
|
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | * @param int $precision e.g. => 2 |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public static function byteFormat (int $byte, int $precision = 2): string {
|
|
| 218 | + public static function byteFormat(int $byte, int $precision = 2): string {
|
|
| 219 | 219 | $rate_counter = 0; |
| 220 | 220 | |
| 221 | - while ($byte > 1024){
|
|
| 221 | + while ($byte > 1024) {
|
|
| 222 | 222 | $byte /= 1024; |
| 223 | 223 | $rate_counter++; |
| 224 | 224 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $byte = round($byte, $precision); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 230 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @param bool $format if you set this true , you will receive symbolic string like 2.76MB |
| 248 | 248 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
| 249 | 249 | */ |
| 250 | - public static function size (string $path, bool $format = true): string|int|false {
|
|
| 250 | + public static function size(string $path, bool $format = true): string | int | false {
|
|
| 251 | 251 | if (filter_var($path, FILTER_VALIDATE_URL)) {
|
| 252 | 252 | $ch = curl_init($path); |
| 253 | 253 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param array $array e.g. => ['path'=>'xfolder/yfolder','sub'=>true] |
| 283 | 283 | * @return bool |
| 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 | if (count(scandir($path)) > 2) {
|
| 288 | 288 | if ($sub) {
|
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | rmdir($path); |
| 295 | 295 | } |
| 296 | 296 | else {
|
| 297 | - logger::write("BPT delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",'error');
|
|
| 297 | + logger::write("BPT delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", 'error');
|
|
| 298 | 298 | return false; |
| 299 | 299 | } |
| 300 | 300 | } |
@@ -317,9 +317,9 @@ discard block |
||
| 317 | 317 | * @return array |
| 318 | 318 | * @throws Exception |
| 319 | 319 | */ |
| 320 | - public static function time2string (int $datetime): array {
|
|
| 320 | + public static function time2string(int $datetime): array {
|
|
| 321 | 321 | $now = new DateTime; |
| 322 | - $input = new DateTime('@' . $datetime);
|
|
| 322 | + $input = new DateTime('@'.$datetime);
|
|
| 323 | 323 | $status = $now < $input ? 'later' : 'ago'; |
| 324 | 324 | $diff = $now->diff($input); |
| 325 | 325 | $diff->w = floor($diff->d / 7); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @method static getGameHigh (int|null|array $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 $return_array = 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. On success, returns an Array of GameHighScore objects. |
| 215 | 215 | */ |
| 216 | 216 | class telegram {
|
| 217 | - public function __call (string $name, array $arguments) {
|
|
| 217 | + public function __call(string $name, array $arguments) {
|
|
| 218 | 218 | if (!isset($arguments[1]) && is_array($arguments[0])) {
|
| 219 | 219 | return request::$name(...$arguments[0]); |
| 220 | 220 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - public static function __callStatic (string $name, array $arguments) {
|
|
| 226 | + public static function __callStatic(string $name, array $arguments) {
|
|
| 227 | 227 | if (!isset($arguments[1]) && is_array($arguments[0])) {
|
| 228 | 228 | return request::$name(...$arguments[0]); |
| 229 | 229 | } |
@@ -20,7 +20,6 @@ |
||
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Class BPT |
| 23 | - |
|
| 24 | 23 | * @method getUpdates (int|null|array $offset = null, int|null $limit = null, int|null $timeout = null, array|null $allowed_updates = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. |
| 25 | 24 | * @method getUp (int|null|array $offset = null, int|null $limit = null, int|null $timeout = null, array|null $allowed_updates = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. |
| 26 | 25 | * @method updates (int|null|array $offset = null, int|null $limit = null, int|null $timeout = null, array|null $allowed_updates = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. |
@@ -217,18 +217,18 @@ discard block |
||
| 217 | 217 | * @method getGameHighScores (int|null|array $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 $return_array = 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. On success, returns an Array of GameHighScore objects. |
| 218 | 218 | * @method getGameHigh (int|null|array $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 $return_array = 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. On success, returns an Array of GameHighScore objects. |
| 219 | 219 | */ |
| 220 | -class BPT{
|
|
| 220 | +class BPT {
|
|
| 221 | 221 | public static update $update; |
| 222 | 222 | |
| 223 | 223 | public static BPT $handler; |
| 224 | 224 | |
| 225 | 225 | |
| 226 | - public function __construct (array|stdClass $settings) {
|
|
| 226 | + public function __construct(array | stdClass $settings) {
|
|
| 227 | 227 | settings::init($settings); |
| 228 | 228 | static::$handler = &$this; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - public function __call (string $name, array $arguments) {
|
|
| 231 | + public function __call(string $name, array $arguments) {
|
|
| 232 | 232 | if (!isset($arguments[1]) && is_array($arguments[0])) {
|
| 233 | 233 | return request::$name(...$arguments[0]); |
| 234 | 234 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - public static function exit (string|null $message = null) {
|
|
| 240 | + public static function exit (string | null $message = null) {
|
|
| 241 | 241 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -231,8 +231,7 @@ |
||
| 231 | 231 | public function __call (string $name, array $arguments) {
|
| 232 | 232 | if (!isset($arguments[1]) && is_array($arguments[0])) {
|
| 233 | 233 | return request::$name(...$arguments[0]); |
| 234 | - } |
|
| 235 | - else {
|
|
| 234 | + } else {
|
|
| 236 | 235 | return request::$name($arguments); |
| 237 | 236 | } |
| 238 | 237 | } |