@@ -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(realpath(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(realpath(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(realpath(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(realpath(self::$folder . '/privates/' . $user_id . '.json'))) { |
|
| 505 | + if (!file_exists(realpath(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(realpath(self::$folder . '/groups/' . $group_id . '.json'))) { |
|
| 526 | + if (!file_exists(realpath(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(realpath(self::$folder . '/supergroups/' . $group_id . '.json'))) { |
|
| 548 | + if (!file_exists(realpath(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(realpath(self::$folder . '/channels/' . $channel_id . '.json'))) { |
|
| 570 | + if (!file_exists(realpath(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 | } |
@@ -5,11 +5,11 @@ discard block |
||
| 5 | 5 | use BPT\database\mysql; |
| 6 | 6 | use BPT\types\message; |
| 7 | 7 | |
| 8 | -if (file_exists('vendor/autoload.php')){ |
|
| 8 | +if (file_exists('vendor/autoload.php')) { |
|
| 9 | 9 | require 'vendor/autoload.php'; |
| 10 | 10 | } |
| 11 | -else{ |
|
| 12 | - if(!file_exists('BPT.phar')) { |
|
| 11 | +else { |
|
| 12 | + if (!file_exists('BPT.phar')) { |
|
| 13 | 13 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
| 14 | 14 | } |
| 15 | 15 | require 'BPT.phar'; |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | const SEND_FAILED = 'Failed!'; |
| 36 | 36 | const SEND_SUCCESSFUL = 'Done!'; |
| 37 | 37 | |
| 38 | - public function __construct(array $settings){ |
|
| 38 | + public function __construct(array $settings) { |
|
| 39 | 39 | parent::__construct($settings); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function message(message $update){ |
|
| 42 | + public function message(message $update) { |
|
| 43 | 43 | $text = $update->text ?? ''; |
| 44 | 44 | $user_id = $update->from->id; |
| 45 | 45 | |
| 46 | 46 | if ($text === '/start') { |
| 47 | - $this->sendMessage(self::START_TEXT,answer: true); |
|
| 47 | + $this->sendMessage(self::START_TEXT, answer: true); |
|
| 48 | 48 | } |
| 49 | 49 | else { |
| 50 | 50 | /** You could use both style */ |
@@ -56,21 +56,21 @@ discard block |
||
| 56 | 56 | $this->sendMessage(self::HELP, answer: true); |
| 57 | 57 | } |
| 58 | 58 | elseif ($text === '/reply_on') { |
| 59 | - mysql::update('users',['value'=>'reply_on'],['id'=>$user_id],1); |
|
| 59 | + mysql::update('users', ['value'=>'reply_on'], ['id'=>$user_id], 1); |
|
| 60 | 60 | $this->sendMessage(self::REPLY_ON, answer: true); |
| 61 | 61 | } |
| 62 | 62 | elseif ($text === '/reply_off') { |
| 63 | - mysql::update('users',['value'=>'reply_off'],['id'=>$user_id],1); |
|
| 63 | + mysql::update('users', ['value'=>'reply_off'], ['id'=>$user_id], 1); |
|
| 64 | 64 | $this->sendMessage(self::REPLY_OFF, answer: true); |
| 65 | 65 | } |
| 66 | 66 | elseif (isset($update->reply_to_message)) { |
| 67 | 67 | $reply_message_id = $update->reply_to_message->message_id; |
| 68 | 68 | |
| 69 | 69 | if ($update->reply_to_message->from->id === $user_id) { |
| 70 | - $check_message = mysql::select('messages', ['receiver_message_id','receiver_id'], [ |
|
| 70 | + $check_message = mysql::select('messages', ['receiver_message_id', 'receiver_id'], [ |
|
| 71 | 71 | 'sender_message_id' => $reply_message_id, |
| 72 | 72 | 'sender_id' => $user_id |
| 73 | - ],1); |
|
| 73 | + ], 1); |
|
| 74 | 74 | |
| 75 | 75 | if ($check_message->num_rows > 0) { |
| 76 | 76 | $data = $check_message->fetch_object(); |
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | else { |
| 86 | - $data = mysql::select('messages', ['sender_message_id','sender_id'], [ |
|
| 86 | + $data = mysql::select('messages', ['sender_message_id', 'sender_id'], [ |
|
| 87 | 87 | 'receiver_message_id' => $reply_message_id, |
| 88 | 88 | 'receiver_id' => $user_id |
| 89 | - ],1)->fetch_object(); |
|
| 89 | + ], 1)->fetch_object(); |
|
| 90 | 90 | |
| 91 | - $value = mysql::select('users','value',['id'=>$user_id])->fetch_object()->value; |
|
| 91 | + $value = mysql::select('users', 'value', ['id'=>$user_id])->fetch_object()->value; |
|
| 92 | 92 | $receiver_id = $data->sender_id; |
| 93 | 93 | if ($value === 'reply_on') { |
| 94 | - mysql::update('users',['value'=>''],['id'=>$user_id]); |
|
| 94 | + mysql::update('users', ['value'=>''], ['id'=>$user_id]); |
|
| 95 | 95 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id); |
| 96 | 96 | } |
| 97 | 97 | else { |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | if (self::$status) { |
| 103 | 103 | mysql::insert('messages', |
| 104 | - ['sender_message_id','sender_id','receiver_message_id','receiver_id'], |
|
| 105 | - [$message_id,$user_id,$result->message_id,$receiver_id] |
|
| 104 | + ['sender_message_id', 'sender_id', 'receiver_message_id', 'receiver_id'], |
|
| 105 | + [$message_id, $user_id, $result->message_id, $receiver_id] |
|
| 106 | 106 | ); |
| 107 | 107 | if (self::SHOW_STATUS) { |
| 108 | 108 | $this->sendMessage(self::SEND_SUCCESSFUL, answer: true); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | else { |
| 117 | 117 | $username = $update->from->username; |
| 118 | 118 | if (empty($username)) { |
| 119 | - $name = $update->from->first_name . (!empty($update->from->last_name) ? (' ' . $update->from->last_name) : ''); |
|
| 119 | + $name = $update->from->first_name.(!empty($update->from->last_name) ? (' '.$update->from->last_name) : ''); |
|
| 120 | 120 | $keyboard = [ |
| 121 | 121 | 'inline_keyboard' => [ |
| 122 | 122 | [ |
@@ -154,33 +154,33 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | if (isset($update->reply_to_message)) { |
| 156 | 156 | $reply_message_id = $update->reply_to_message->message_id; |
| 157 | - if ($update->reply_to_message->from->id === $user_id){ |
|
| 157 | + if ($update->reply_to_message->from->id === $user_id) { |
|
| 158 | 158 | $check_message = mysql::select('messages', 'receiver_message_id', [ |
| 159 | 159 | 'sender_message_id' => $reply_message_id, |
| 160 | 160 | 'sender_id' => $user_id |
| 161 | - ],1); |
|
| 161 | + ], 1); |
|
| 162 | 162 | if ($check_message->num_rows > 0) { |
| 163 | - $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard); |
|
| 163 | + $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id, reply_markup: $keyboard); |
|
| 164 | 164 | } |
| 165 | 165 | else { |
| 166 | - $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
|
| 166 | + $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | else { |
| 170 | 170 | $check_message = mysql::select('messages', 'sender_message_id', [ |
| 171 | 171 | 'receiver_message_id' => $reply_message_id, |
| 172 | 172 | 'receiver_id' => $user_id |
| 173 | - ],1); |
|
| 173 | + ], 1); |
|
| 174 | 174 | if ($check_message->num_rows > 0) { |
| 175 | - $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard); |
|
| 175 | + $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id, reply_markup: $keyboard); |
|
| 176 | 176 | } |
| 177 | 177 | else { |
| 178 | - $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
|
| 178 | + $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard); |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | else { |
| 183 | - $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
|
| 183 | + $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | if (self::$status) { |
| 191 | 191 | mysql::insert('messages', |
| 192 | - ['sender_message_id','sender_id','receiver_message_id','receiver_id'], |
|
| 193 | - [$message_id,$user_id,$result->message_id,self::ADMIN] |
|
| 192 | + ['sender_message_id', 'sender_id', 'receiver_message_id', 'receiver_id'], |
|
| 193 | + [$message_id, $user_id, $result->message_id, self::ADMIN] |
|
| 194 | 194 | ); |
| 195 | 195 | if (self::SHOW_STATUS) { |
| 196 | 196 | $this->sendMessage(self::SEND_SUCCESSFUL, answer: true); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @internal Only for BPT self usage , Don't use it in your source! |
| 29 | 29 | */ |
| 30 | - public static function init (): void { |
|
| 30 | + public static function init(): void { |
|
| 31 | 31 | $host = settings::$db['host'] ?? 'localhost'; |
| 32 | 32 | $port = settings::$db['port'] ?? 3306; |
| 33 | 33 | $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown'; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $dbname = settings::$db['dbname']; |
| 37 | 37 | self::$connection = new mysqli($host, $user, $pass, $dbname, $port); |
| 38 | 38 | if (self::$connection->connect_errno) { |
| 39 | - logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR); |
|
| 39 | + logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR); |
|
| 40 | 40 | throw new bptException('SQL_CONNECTION_PROBLEM'); |
| 41 | 41 | } |
| 42 | 42 | if (self::$auto_process && !lock::exist('BPT-MYSQL')) { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private static function install (): void { |
|
| 47 | + private static function install(): void { |
|
| 48 | 48 | self::pureQuery(" |
| 49 | 49 | CREATE TABLE `users` |
| 50 | 50 | ( |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @internal Only for BPT self usage , Don't use it in your source! |
| 67 | 67 | */ |
| 68 | - public static function process (): void { |
|
| 68 | + public static function process(): void { |
|
| 69 | 69 | if (self::$auto_process) { |
| 70 | 70 | if (isset(BPT::$update->message)) { |
| 71 | 71 | self::processMessage(BPT::$update->message); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - private static function processMessage (message $update): void { |
|
| 88 | + private static function processMessage(message $update): void { |
|
| 89 | 89 | $type = $update->chat->type; |
| 90 | 90 | if ($type === chatType::PRIVATE) { |
| 91 | 91 | $user_id = $update->from->id; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - private static function processCallbackQuery (callbackQuery $update): void { |
|
| 114 | + private static function processCallbackQuery(callbackQuery $update): void { |
|
| 115 | 115 | $type = $update->message->chat->type; |
| 116 | 116 | if ($type === chatType::PRIVATE) { |
| 117 | 117 | $user_id = $update->from->id; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private static function processInlineQuery (inlineQuery $update): void { |
|
| 124 | + private static function processInlineQuery(inlineQuery $update): void { |
|
| 125 | 125 | $type = $update->chat_type; |
| 126 | 126 | if ($type === chatType::PRIVATE || $type === chatType::SENDER) { |
| 127 | 127 | $user_id = $update->from->id; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - private static function processMyChatMember (chatMemberUpdated $update): void { |
|
| 134 | + private static function processMyChatMember(chatMemberUpdated $update): void { |
|
| 135 | 135 | $type = $update->chat->type; |
| 136 | 136 | if ($type === chatType::PRIVATE) { |
| 137 | 137 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return mysqli |
| 150 | 150 | */ |
| 151 | - public static function getMysqli (): mysqli { |
|
| 151 | + public static function getMysqli(): mysqli { |
|
| 152 | 152 | return self::$connection; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return int|string |
| 159 | 159 | */ |
| 160 | - public static function affected_rows (): int|string { |
|
| 160 | + public static function affected_rows(): int | string { |
|
| 161 | 161 | return self::$connection->affected_rows; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return int|string |
| 168 | 168 | */ |
| 169 | - public static function insert_id (): int|string { |
|
| 169 | + public static function insert_id(): int | string { |
|
| 170 | 170 | return self::$connection->insert_id; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public static function escapeString (string $text): string { |
|
| 180 | + public static function escapeString(string $text): string { |
|
| 181 | 181 | return self::$connection->real_escape_string($text); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return mysqli_result|bool |
| 194 | 194 | */ |
| 195 | - public static function pureQuery (string $query): mysqli_result|bool { |
|
| 195 | + public static function pureQuery(string $query): mysqli_result | bool { |
|
| 196 | 196 | return self::$connection->query($query); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return mysqli_result|bool |
| 213 | 213 | */ |
| 214 | - public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool { |
|
| 214 | + public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool { |
|
| 215 | 215 | $prepare = self::$connection->prepare($query); |
| 216 | 216 | $types = ''; |
| 217 | 217 | foreach ($vars as $var) { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | if (!empty($types)) { |
| 229 | - $prepare->bind_param($types,...$vars); |
|
| 229 | + $prepare->bind_param($types, ...$vars); |
|
| 230 | 230 | } |
| 231 | 231 | if (!$prepare->execute()) { |
| 232 | 232 | logger::write(loggerTypes::WARNING, $prepare->error); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | return $need_result ? $prepare->get_result() : true; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array { |
|
| 238 | + private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array { |
|
| 239 | 239 | $first = true; |
| 240 | 240 | $values = []; |
| 241 | 241 | foreach ($array as $name => $value) { |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | return $values; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 254 | + private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array { |
|
| 255 | 255 | $values = []; |
| 256 | 256 | if (!empty($where)) { |
| 257 | 257 | $query .= " WHERE"; |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return mysqli_result|bool |
| 280 | 280 | */ |
| 281 | - public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 281 | + public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 282 | 282 | $query = "DELETE FROM `$table`"; |
| 283 | 283 | $res = self::makeQueryReady($query, $where, $count, $offset); |
| 284 | 284 | return self::query($query, $res, false); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * |
| 298 | 298 | * @return mysqli_result|bool |
| 299 | 299 | */ |
| 300 | - public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 300 | + public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 301 | 301 | $query = "UPDATE `$table` SET"; |
| 302 | 302 | $values = self::makeArrayReady($query, $modify, ', '); |
| 303 | 303 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | * |
| 316 | 316 | * @return mysqli_result|bool |
| 317 | 317 | */ |
| 318 | - public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
|
| 318 | + public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool { |
|
| 319 | 319 | $query = "INSERT INTO `$table`("; |
| 320 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
|
| 320 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES ('; |
|
| 321 | 321 | if (is_string($values)) $values = [$values]; |
| 322 | - $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
|
| 322 | + $query .= '?'.str_repeat(',?', count($values) - 1).')'; |
|
| 323 | 323 | return self::query($query, $values, false); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -338,13 +338,13 @@ discard block |
||
| 338 | 338 | * |
| 339 | 339 | * @return mysqli_result|bool |
| 340 | 340 | */ |
| 341 | - public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool { |
|
| 341 | + public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool { |
|
| 342 | 342 | $query = "SELECT "; |
| 343 | 343 | if ($columns == '*') { |
| 344 | 344 | $query .= "* "; |
| 345 | 345 | } |
| 346 | 346 | else { |
| 347 | - $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
|
| 347 | + $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` '; |
|
| 348 | 348 | } |
| 349 | 349 | $query .= "FROM `$table`"; |
| 350 | 350 | $res = self::makeQueryReady($query, $where, $count, $offset); |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * |
| 363 | 363 | * @return null|bool|array |
| 364 | 364 | */ |
| 365 | - public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null { |
|
| 365 | + public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null { |
|
| 366 | 366 | $res = self::select($table, $columns, $where, 1); |
| 367 | 367 | if ($res) { |
| 368 | 368 | return $res->fetch_assoc(); |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*' |
| 380 | 380 | * @param array|null $where Set your ifs default : null |
| 381 | 381 | */ |
| 382 | - public static function selectObject (string $table, array|string $columns = '*', array $where = null) { |
|
| 382 | + public static function selectObject(string $table, array | string $columns = '*', array $where = null) { |
|
| 383 | 383 | $res = self::select($table, $columns, $where, 1); |
| 384 | 384 | if ($res) { |
| 385 | 385 | return $res->fetch_object(); |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | * |
| 402 | 402 | * @return bool|Generator |
| 403 | 403 | */ |
| 404 | - public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
|
| 404 | + public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator { |
|
| 405 | 405 | $res = self::select($table, $columns, $where, $count, $offset); |
| 406 | 406 | if ($res) { |
| 407 | 407 | while ($row = $res->fetch_assoc()) yield $row; |
@@ -21,37 +21,37 @@ discard block |
||
| 21 | 21 | public int $id; |
| 22 | 22 | |
| 23 | 23 | /** True, if this user is a bot */ |
| 24 | - public null|bool $is_bot = null; |
|
| 24 | + public null | bool $is_bot = null; |
|
| 25 | 25 | |
| 26 | 26 | /** User's or bot's first name */ |
| 27 | - public null|string $first_name = null; |
|
| 27 | + public null | string $first_name = null; |
|
| 28 | 28 | |
| 29 | 29 | /** Optional. User's or bot's last name */ |
| 30 | - public null|string $last_name = null; |
|
| 30 | + public null | string $last_name = null; |
|
| 31 | 31 | |
| 32 | 32 | /** Optional. User's or bot's username */ |
| 33 | - public null|string $username = null; |
|
| 33 | + public null | string $username = null; |
|
| 34 | 34 | |
| 35 | 35 | /** Optional. IETF language tag of the user's language */ |
| 36 | - public null|string $language_code = null; |
|
| 36 | + public null | string $language_code = null; |
|
| 37 | 37 | |
| 38 | 38 | /** Optional. True, if this user is a Telegram Premium user */ |
| 39 | - public null|bool $is_premium = null; |
|
| 39 | + public null | bool $is_premium = null; |
|
| 40 | 40 | |
| 41 | 41 | /** Optional. True, if this user added the bot to the attachment menu */ |
| 42 | - public null|bool $added_to_attachment_menu = null; |
|
| 42 | + public null | bool $added_to_attachment_menu = null; |
|
| 43 | 43 | |
| 44 | 44 | /** Optional. True, if the bot can be invited to groups. Returned only in getMe. */ |
| 45 | - public null|bool $can_join_groups = null; |
|
| 45 | + public null | bool $can_join_groups = null; |
|
| 46 | 46 | |
| 47 | 47 | /** Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. */ |
| 48 | - public null|bool $can_read_all_group_messages = null; |
|
| 48 | + public null | bool $can_read_all_group_messages = null; |
|
| 49 | 49 | |
| 50 | 50 | /** Optional. True, if the bot supports inline queries. Returned only in getMe. */ |
| 51 | - public null|bool $supports_inline_queries = null; |
|
| 51 | + public null | bool $supports_inline_queries = null; |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - public function __construct(stdClass|null $object = null) { |
|
| 54 | + public function __construct(stdClass | null $object = null) { |
|
| 55 | 55 | if ($object != null) { |
| 56 | 56 | parent::__construct($object, self::subs); |
| 57 | 57 | } |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function fullName(bool $nameFirst = true): string { |
| 65 | - return trim($nameFirst ? $this->first_name . ' ' . $this->last_name : $this->last_name . ' ' . $this->first_name); |
|
| 65 | + return trim($nameFirst ? $this->first_name.' '.$this->last_name : $this->last_name.' '.$this->first_name); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function getProfiles(int|null $offset = null, int|null $limit = null): userProfilePhotos|responseError { |
|
| 69 | - return telegram::getUserProfilePhotos($this->id,$offset,$limit); |
|
| 68 | + public function getProfiles(int | null $offset = null, int | null $limit = null): userProfilePhotos | responseError { |
|
| 69 | + return telegram::getUserProfilePhotos($this->id, $offset, $limit); |
|
| 70 | 70 | } |
| 71 | 71 | } |
@@ -30,85 +30,85 @@ discard block |
||
| 30 | 30 | public string $type; |
| 31 | 31 | |
| 32 | 32 | /** Optional. Title, for supergroups, channels and group chats */ |
| 33 | - public null|string $title = null; |
|
| 33 | + public null | string $title = null; |
|
| 34 | 34 | |
| 35 | 35 | /** Optional. Username, for private chats, supergroups and channels if available */ |
| 36 | - public null|string $username = null; |
|
| 36 | + public null | string $username = null; |
|
| 37 | 37 | |
| 38 | 38 | /** Optional. First name of the other party in a private chat */ |
| 39 | - public null|string $first_name = null; |
|
| 39 | + public null | string $first_name = null; |
|
| 40 | 40 | |
| 41 | 41 | /** Optional. Last name of the other party in a private chat */ |
| 42 | - public null|string $last_name = null; |
|
| 42 | + public null | string $last_name = null; |
|
| 43 | 43 | |
| 44 | 44 | /** Optional. True, if the supergroup chat is a forum (has topics enabled) */ |
| 45 | - public null|bool $is_forum = null; |
|
| 45 | + public null | bool $is_forum = null; |
|
| 46 | 46 | |
| 47 | 47 | /** Optional. Chat photo. Returned only in getChat. */ |
| 48 | - public null|chatPhoto $photo = null; |
|
| 48 | + public null | chatPhoto $photo = null; |
|
| 49 | 49 | |
| 50 | 50 | /** Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in getChat. */ |
| 51 | - public null|array $active_usernames = null; |
|
| 51 | + public null | array $active_usernames = null; |
|
| 52 | 52 | |
| 53 | 53 | /** Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat. */ |
| 54 | - public null|string $emoji_status_custom_emoji_id = null; |
|
| 54 | + public null | string $emoji_status_custom_emoji_id = null; |
|
| 55 | 55 | |
| 56 | 56 | /** Optional. Bio of the other party in a private chat. Returned only in getChat. */ |
| 57 | - public null|string $bio = null; |
|
| 57 | + public null | string $bio = null; |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Optional. True, if privacy settings of the other party in the private chat allows to use |
| 61 | 61 | * tg://user?id=<user_id> links only in chats with the user. Returned only in getChat. |
| 62 | 62 | */ |
| 63 | - public null|bool $has_private_forwards = null; |
|
| 63 | + public null | bool $has_private_forwards = null; |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in |
| 67 | 67 | * the private chat. Returned only in getChat. |
| 68 | 68 | */ |
| 69 | - public null|bool $has_restricted_voice_and_video_messages = null; |
|
| 69 | + public null | bool $has_restricted_voice_and_video_messages = null; |
|
| 70 | 70 | |
| 71 | 71 | /** Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. */ |
| 72 | - public null|bool $join_to_send_messages = null; |
|
| 72 | + public null | bool $join_to_send_messages = null; |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. |
| 76 | 76 | * Returned only in getChat. |
| 77 | 77 | */ |
| 78 | - public null|bool $join_by_request = null; |
|
| 78 | + public null | bool $join_by_request = null; |
|
| 79 | 79 | |
| 80 | 80 | /** Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. */ |
| 81 | - public null|string $description = null; |
|
| 81 | + public null | string $description = null; |
|
| 82 | 82 | |
| 83 | 83 | /** Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. */ |
| 84 | - public null|string $invite_link = null; |
|
| 84 | + public null | string $invite_link = null; |
|
| 85 | 85 | |
| 86 | 86 | /** Optional. The most recent pinned message (by sending date). Returned only in getChat. */ |
| 87 | - public null|message $pinned_message = null; |
|
| 87 | + public null | message $pinned_message = null; |
|
| 88 | 88 | |
| 89 | 89 | /** Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. */ |
| 90 | - public null|chatPermissions $permissions = null; |
|
| 90 | + public null | chatPermissions $permissions = null; |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged |
| 94 | 94 | * user; in seconds. Returned only in getChat. |
| 95 | 95 | */ |
| 96 | - public null|int $slow_mode_delay = null; |
|
| 96 | + public null | int $slow_mode_delay = null; |
|
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. |
| 100 | 100 | * Returned only in getChat. |
| 101 | 101 | */ |
| 102 | - public null|int $message_auto_delete_time = null; |
|
| 102 | + public null | int $message_auto_delete_time = null; |
|
| 103 | 103 | |
| 104 | 104 | /** Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. */ |
| 105 | - public null|bool $has_protected_content = null; |
|
| 105 | + public null | bool $has_protected_content = null; |
|
| 106 | 106 | |
| 107 | 107 | /** Optional. For supergroups, name of group sticker set. Returned only in getChat. */ |
| 108 | - public null|string $sticker_set_name = null; |
|
| 108 | + public null | string $sticker_set_name = null; |
|
| 109 | 109 | |
| 110 | 110 | /** Optional. True, if the bot can change the group sticker set. Returned only in getChat. */ |
| 111 | - public null|bool $can_set_sticker_set = null; |
|
| 111 | + public null | bool $can_set_sticker_set = null; |
|
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice |
@@ -116,87 +116,87 @@ discard block |
||
| 116 | 116 | * languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed |
| 117 | 117 | * 64 bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat. |
| 118 | 118 | */ |
| 119 | - public null|int $linked_chat_id = null; |
|
| 119 | + public null | int $linked_chat_id = null; |
|
| 120 | 120 | |
| 121 | 121 | /** Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. */ |
| 122 | - public null|chatLocation $location = null; |
|
| 122 | + public null | chatLocation $location = null; |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | - public function __construct(stdClass|null $object = null) { |
|
| 125 | + public function __construct(stdClass | null $object = null) { |
|
| 126 | 126 | if ($object != null) { |
| 127 | 127 | parent::__construct($object, self::subs); |
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function isPrivate (): bool { |
|
| 131 | + public function isPrivate(): bool { |
|
| 132 | 132 | return $this->type === chatType::PRIVATE; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function isGroup (): bool { |
|
| 135 | + public function isGroup(): bool { |
|
| 136 | 136 | return $this->type === chatType::GROUP; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function isSuperGroup (): bool { |
|
| 139 | + public function isSuperGroup(): bool { |
|
| 140 | 140 | return $this->type === chatType::SUPERGROUP; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - public function isChannel (): bool { |
|
| 143 | + public function isChannel(): bool { |
|
| 144 | 144 | return $this->type === chatType::CHANNEL; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - public function leave(): responseError|bool { |
|
| 147 | + public function leave(): responseError | bool { |
|
| 148 | 148 | if ($this->isPrivate()) { |
| 149 | 149 | return false; |
| 150 | 150 | } |
| 151 | 151 | return telegram::leave($this->id); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - public function setPhoto(CURLFile|array $photo): responseError|bool { |
|
| 154 | + public function setPhoto(CURLFile | array $photo): responseError | bool { |
|
| 155 | 155 | if ($this->isPrivate()) { |
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | - return telegram::setChatPhoto($photo,$this->id); |
|
| 158 | + return telegram::setChatPhoto($photo, $this->id); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public function delPhoto(): responseError|bool { |
|
| 161 | + public function delPhoto(): responseError | bool { |
|
| 162 | 162 | if ($this->isPrivate()) { |
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | return telegram::deleteChatPhoto($this->id); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - public function setTitle(string|array $title): responseError|bool { |
|
| 168 | + public function setTitle(string | array $title): responseError | bool { |
|
| 169 | 169 | if ($this->isPrivate()) { |
| 170 | 170 | return false; |
| 171 | 171 | } |
| 172 | - return telegram::setChatTitle($title,$this->id); |
|
| 172 | + return telegram::setChatTitle($title, $this->id); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - public function setDescription(string|null $description = null): responseError|bool { |
|
| 175 | + public function setDescription(string | null $description = null): responseError | bool { |
|
| 176 | 176 | if ($this->isPrivate()) { |
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | - return telegram::setChatDescription($this->id,$description); |
|
| 179 | + return telegram::setChatDescription($this->id, $description); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - public function getAdmins(): bool|responseError|array { |
|
| 182 | + public function getAdmins(): bool | responseError | array { |
|
| 183 | 183 | if ($this->isPrivate()) { |
| 184 | 184 | return false; |
| 185 | 185 | } |
| 186 | 186 | return telegram::getChatAdministrators($this->id); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - public function getMembersCount(): bool|responseError|int { |
|
| 189 | + public function getMembersCount(): bool | responseError | int { |
|
| 190 | 190 | if ($this->isPrivate()) { |
| 191 | 191 | return false; |
| 192 | 192 | } |
| 193 | 193 | return telegram::getChatMemberCount($this->id); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - public function getMember(int|null $user_id = null): chatMember|bool|responseError { |
|
| 196 | + public function getMember(int | null $user_id = null): chatMember | bool | responseError { |
|
| 197 | 197 | if ($this->isPrivate()) { |
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | - return telegram::getChatMember($this->id,$user_id); |
|
| 200 | + return telegram::getChatMember($this->id, $user_id); |
|
| 201 | 201 | } |
| 202 | 202 | } |
@@ -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 | public function link(): string { |
@@ -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 | public function link(bool $big = true): string { |
@@ -25,29 +25,29 @@ discard block |
||
| 25 | 25 | public int $duration; |
| 26 | 26 | |
| 27 | 27 | /** Optional. Performer of the audio as defined by sender or by audio tags */ |
| 28 | - public null|string $performer = null; |
|
| 28 | + public null | string $performer = null; |
|
| 29 | 29 | |
| 30 | 30 | /** Optional. Title of the audio as defined by sender or by audio tags */ |
| 31 | - public null|string $title = null; |
|
| 31 | + public null | string $title = null; |
|
| 32 | 32 | |
| 33 | 33 | /** Optional. Original filename as defined by sender */ |
| 34 | - public null|string $file_name = null; |
|
| 34 | + public null | string $file_name = null; |
|
| 35 | 35 | |
| 36 | 36 | /** Optional. MIME type of the file as defined by sender */ |
| 37 | - public null|string $mime_type = null; |
|
| 37 | + public null | string $mime_type = null; |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have |
| 41 | 41 | * difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit |
| 42 | 42 | * integer or double-precision float type are safe for storing this value. |
| 43 | 43 | */ |
| 44 | - public null|int $file_size = null; |
|
| 44 | + public null | int $file_size = null; |
|
| 45 | 45 | |
| 46 | 46 | /** Optional. Thumbnail of the album cover to which the music file belongs */ |
| 47 | - public null|photoSize $thumb = null; |
|
| 47 | + public null | photoSize $thumb = null; |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public function __construct(stdClass|null $object = null) { |
|
| 50 | + public function __construct(stdClass | null $object = null) { |
|
| 51 | 51 | if ($object != null) { |
| 52 | 52 | parent::__construct($object, self::subs); |
| 53 | 53 | } |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return bool|string string will be returned when destination doesn't set |
| 70 | 70 | */ |
| 71 | - public function download(string|null $destination = null): bool|string { |
|
| 72 | - return telegram::downloadFile($destination ?? $this->file_name ?? 'unknown.mp3',$this->file_id); |
|
| 71 | + public function download(string | null $destination = null): bool | string { |
|
| 72 | + return telegram::downloadFile($destination ?? $this->file_name ?? 'unknown.mp3', $this->file_id); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function link(): string { |
@@ -31,28 +31,28 @@ |
||
| 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 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function revoke(): self|responseError|bool { |
|
| 55 | + public function revoke(): self | responseError | bool { |
|
| 56 | 56 | return $this->is_revoked ?? telegram::revokeChatInviteLink($this->invite_link); |
| 57 | 57 | } |
| 58 | 58 | } |