@@ -17,8 +17,7 @@ discard block |
||
17 | 17 | if (file_exists(settings::$name.'BPT.log') && !(filesize(settings::$name.'BPT.log') > self::$log_size * 1024 * 1024)) { |
18 | 18 | $mode = 'a'; |
19 | 19 | $write = false; |
20 | - } |
|
21 | - else { |
|
20 | + } else { |
|
22 | 21 | $mode = 'w'; |
23 | 22 | $write = true; |
24 | 23 | } |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" ); |
40 | 39 | if (!is_null(self::$handler)) { |
41 | 40 | fwrite(self::$handler, $text); |
42 | - } |
|
43 | - else { |
|
41 | + } else { |
|
44 | 42 | self::$waited_logs[] = $text; |
45 | 43 | } |
46 | 44 | } |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | $curl_handler = curl_init(settings::$base_url."/bot$token/"); |
36 | 36 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
37 | 37 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
38 | - } |
|
39 | - else{ |
|
38 | + } else{ |
|
40 | 39 | $token = settings::$token; |
41 | 40 | if (!isset(self::$curl_handler)){ |
42 | 41 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
@@ -58,11 +57,9 @@ discard block |
||
58 | 57 | if (isset($data['forgot'])) { |
59 | 58 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
60 | 59 | unset($data['forgot']); |
61 | - } |
|
62 | - elseif ($method === 'getUpdates'){ |
|
60 | + } elseif ($method === 'getUpdates'){ |
|
63 | 61 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
64 | - } |
|
65 | - else{ |
|
62 | + } else{ |
|
66 | 63 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300); |
67 | 64 | } |
68 | 65 | } |
@@ -71,7 +71,9 @@ discard block |
||
71 | 71 | $keyboard_object->setOne_time_keyboard($keyboard['one_time']); |
72 | 72 | } |
73 | 73 | foreach ($keyboard as $row) { |
74 | - if (!is_array($row)) continue; |
|
74 | + if (!is_array($row)) { |
|
75 | + continue; |
|
76 | + } |
|
75 | 77 | $buttons = []; |
76 | 78 | foreach ($row as $base_button) { |
77 | 79 | $button_info = explode('||', $base_button); |
@@ -80,15 +82,12 @@ discard block |
||
80 | 82 | if (count($button_info) > 1) { |
81 | 83 | if ($button_info[1] === 'con') { |
82 | 84 | $button->setRequest_contact(true); |
83 | - } |
|
84 | - elseif ($button_info[1] === 'loc') { |
|
85 | + } elseif ($button_info[1] === 'loc') { |
|
85 | 86 | $button->setRequest_location(true); |
86 | - } |
|
87 | - elseif ($button_info[1] === 'poll') { |
|
87 | + } elseif ($button_info[1] === 'poll') { |
|
88 | 88 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
89 | 89 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
90 | - } |
|
91 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
90 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
92 | 91 | $url = $button_info[2]; |
93 | 92 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
94 | 93 | } |
@@ -98,8 +97,7 @@ discard block |
||
98 | 97 | $keyboard_object->setKeyboard([$buttons]); |
99 | 98 | } |
100 | 99 | return $keyboard_object; |
101 | - } |
|
102 | - elseif (!empty($inline)) { |
|
100 | + } elseif (!empty($inline)) { |
|
103 | 101 | $keyboard_object = new inlineKeyboardMarkup(); |
104 | 102 | foreach ($inline as $row) { |
105 | 103 | $buttons = []; |
@@ -108,20 +106,17 @@ discard block |
||
108 | 106 | if (isset($button_info[1])) { |
109 | 107 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
110 | 108 | $button->setText($button_info[0])->setUrl($button_info[1]); |
111 | - } |
|
112 | - else { |
|
109 | + } else { |
|
113 | 110 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
114 | 111 | } |
115 | - } |
|
116 | - else { |
|
112 | + } else { |
|
117 | 113 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
118 | 114 | } |
119 | 115 | } |
120 | 116 | $keyboard_object->setInline_keyboard([$buttons]); |
121 | 117 | } |
122 | 118 | return $keyboard_object; |
123 | - } |
|
124 | - else { |
|
119 | + } else { |
|
125 | 120 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
126 | 121 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
127 | 122 | } |
@@ -140,8 +135,12 @@ discard block |
||
140 | 135 | * @return string |
141 | 136 | */ |
142 | 137 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
143 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
144 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
138 | + if (empty($user_id)) { |
|
139 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
140 | + } |
|
141 | + if (empty($bot_username)) { |
|
142 | + $bot_username = telegram::getMe()->username; |
|
143 | + } |
|
145 | 144 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
146 | 145 | } |
147 | 146 | } |
148 | 147 | \ No newline at end of file |
@@ -16,15 +16,13 @@ discard block |
||
16 | 16 | public static function init () { |
17 | 17 | if (settings::$multi) { |
18 | 18 | multi::init(); |
19 | - } |
|
20 | - else { |
|
19 | + } else { |
|
21 | 20 | if (lock::exist('BPT-HOOK')) { |
22 | 21 | receiver::telegramVerify(); |
23 | 22 | self::checkSecret(); |
24 | 23 | logger::write('Update received , lets process it ;)'); |
25 | 24 | receiver::processUpdate(); |
26 | - } |
|
27 | - else { |
|
25 | + } else { |
|
28 | 26 | self::processSetWebhook(); |
29 | 27 | } |
30 | 28 | } |
@@ -46,8 +44,7 @@ discard block |
||
46 | 44 | $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); |
47 | 45 | if (telegram::$status) { |
48 | 46 | logger::write('Webhook was set successfully',loggerTypes::INFO); |
49 | - } |
|
50 | - else { |
|
47 | + } else { |
|
51 | 48 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
52 | 49 | BPT::exit(print_r($res,true)); |
53 | 50 | } |
@@ -69,8 +66,7 @@ discard block |
||
69 | 66 | if (is_string(settings::$certificate)) { |
70 | 67 | if (file_exists(settings::$certificate)) { |
71 | 68 | settings::$certificate = new CURLFile(settings::$certificate); |
72 | - } |
|
73 | - else { |
|
69 | + } else { |
|
74 | 70 | settings::$certificate = null; |
75 | 71 | } |
76 | 72 | } |
@@ -17,8 +17,7 @@ |
||
17 | 17 | public static function init (): string|null { |
18 | 18 | if (self::checkIP()) { |
19 | 19 | return self::getUpdate(); |
20 | - } |
|
21 | - else { |
|
20 | + } else { |
|
22 | 21 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
23 | 22 | BPT::exit(); |
24 | 23 | return null; |
@@ -30,8 +30,7 @@ |
||
30 | 30 | $update = file_get_contents($up); |
31 | 31 | unlink($up); |
32 | 32 | return $update; |
33 | - } |
|
34 | - else { |
|
33 | + } else { |
|
35 | 34 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
36 | 35 | BPT::exit(); |
37 | 36 | return null; |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) { |
36 | 36 | $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; |
37 | 37 | } |
38 | - } |
|
39 | - elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
|
38 | + } elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
|
40 | 39 | $ip = $_SERVER['HTTP_AR_REAL_IP']; |
41 | 40 | } |
42 | 41 | |
@@ -94,51 +93,41 @@ discard block |
||
94 | 93 | if (self::handlerExist('message')) { |
95 | 94 | BPT::$handler->message(BPT::$update->message); |
96 | 95 | } |
97 | - } |
|
98 | - elseif (isset(BPT::$update->edited_message)) { |
|
96 | + } elseif (isset(BPT::$update->edited_message)) { |
|
99 | 97 | if (self::handlerExist('edited_message')) { |
100 | 98 | BPT::$handler->edited_message(BPT::$update->edited_message); |
101 | 99 | } |
102 | - } |
|
103 | - elseif (isset(BPT::$update->channel_post)) { |
|
100 | + } elseif (isset(BPT::$update->channel_post)) { |
|
104 | 101 | if (self::handlerExist('channel_post')) { |
105 | 102 | BPT::$handler->channel_post(BPT::$update->channel_post); |
106 | 103 | } |
107 | - } |
|
108 | - elseif (isset(BPT::$update->edited_channel_post)) { |
|
104 | + } elseif (isset(BPT::$update->edited_channel_post)) { |
|
109 | 105 | if (self::handlerExist('edited_channel_post')) { |
110 | 106 | BPT::$handler->edited_channel_post(BPT::$update->edited_channel_post); |
111 | 107 | } |
112 | - } |
|
113 | - elseif (isset(BPT::$update->inline_query)) { |
|
108 | + } elseif (isset(BPT::$update->inline_query)) { |
|
114 | 109 | if (self::handlerExist('inline_query')) { |
115 | 110 | BPT::$handler->inline_query(BPT::$update->inline_query); |
116 | 111 | } |
117 | - } |
|
118 | - elseif (isset(BPT::$update->callback_query)) { |
|
112 | + } elseif (isset(BPT::$update->callback_query)) { |
|
119 | 113 | if (self::handlerExist('callback_query')) { |
120 | 114 | BPT::$handler->callback_query(BPT::$update->callback_query); |
121 | 115 | } |
122 | - } |
|
123 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
116 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
124 | 117 | if (self::handlerExist('my_chat_member')) { |
125 | 118 | BPT::$handler->my_chat_member(BPT::$update->my_chat_member); |
126 | 119 | } |
127 | - } |
|
128 | - elseif (isset(BPT::$update->chat_member)) { |
|
120 | + } elseif (isset(BPT::$update->chat_member)) { |
|
129 | 121 | if (self::handlerExist('chat_member')) { |
130 | 122 | BPT::$handler->chat_member(BPT::$update->chat_member); |
131 | 123 | } |
132 | - } |
|
133 | - elseif (isset(BPT::$update->chat_join_request)) { |
|
124 | + } elseif (isset(BPT::$update->chat_join_request)) { |
|
134 | 125 | if (self::handlerExist('chat_join_request')) { |
135 | 126 | BPT::$handler->chat_join_request(BPT::$update->chat_join_request); |
136 | 127 | } |
137 | - } |
|
138 | - elseif (self::handlerExist('something_else')) { |
|
128 | + } elseif (self::handlerExist('something_else')) { |
|
139 | 129 | BPT::$handler->something_else(BPT::$update); |
140 | - } |
|
141 | - else { |
|
130 | + } else { |
|
142 | 131 | logger::write('Update received but handlers does not set',loggerTypes::WARNING); |
143 | 132 | } |
144 | 133 | } |
@@ -78,11 +78,9 @@ discard block |
||
78 | 78 | $value = 'bots_files/'.$value.'/'; |
79 | 79 | } |
80 | 80 | self::$$setting = $value; |
81 | - } |
|
82 | - catch (TypeError){ |
|
81 | + } catch (TypeError){ |
|
83 | 82 | logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING); |
84 | - } |
|
85 | - catch (Error){ |
|
83 | + } catch (Error){ |
|
86 | 84 | logger::write("$setting setting is not one of library settings",loggerTypes::WARNING); |
87 | 85 | } |
88 | 86 | } |
@@ -99,13 +97,11 @@ discard block |
||
99 | 97 | if (!empty(self::$receiver)) { |
100 | 98 | self::$receiver !== receiver::GETUPDATES ? webhook::init() : self::getUpdates(); |
101 | 99 | } |
102 | - } |
|
103 | - else { |
|
100 | + } else { |
|
104 | 101 | logger::write('token format is not right, check it and try again',loggerTypes::ERROR); |
105 | 102 | throw new bptException('TOKEN_NOT_TRUE'); |
106 | 103 | } |
107 | - } |
|
108 | - else { |
|
104 | + } else { |
|
109 | 105 | logger::write('You must specify token parameter in settings',loggerTypes::ERROR); |
110 | 106 | throw new bptException('TOKEN_NOT_FOUND'); |
111 | 107 | } |
@@ -159,8 +155,7 @@ discard block |
||
159 | 155 | private static function getUpdates(): void { |
160 | 156 | if (self::$handler) { |
161 | 157 | getUpdates::init(); |
162 | - } |
|
163 | - else { |
|
158 | + } else { |
|
164 | 159 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR); |
165 | 160 | throw new bptException('GETUPDATE_NEED_HANDLER'); |
166 | 161 | } |