@@ -69,17 +69,13 @@ discard block |
||
69 | 69 | if (self::$auto_process) { |
70 | 70 | if (isset(BPT::$update->message)) { |
71 | 71 | self::processMessage(BPT::$update->message); |
72 | - } |
|
73 | - elseif (isset(BPT::$update->edited_message)) { |
|
72 | + } elseif (isset(BPT::$update->edited_message)) { |
|
74 | 73 | self::processMessage(BPT::$update->edited_message); |
75 | - } |
|
76 | - elseif (isset(BPT::$update->callback_query)) { |
|
74 | + } elseif (isset(BPT::$update->callback_query)) { |
|
77 | 75 | self::processCallbackQuery(BPT::$update->callback_query); |
78 | - } |
|
79 | - elseif (isset(BPT::$update->inline_query)) { |
|
76 | + } elseif (isset(BPT::$update->inline_query)) { |
|
80 | 77 | self::processInlineQuery(BPT::$update->inline_query); |
81 | - } |
|
82 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
78 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
83 | 79 | self::processMyChatMember(BPT::$update->my_chat_member); |
84 | 80 | } |
85 | 81 | } |
@@ -136,8 +132,7 @@ discard block |
||
136 | 132 | if ($type === chatType::PRIVATE) { |
137 | 133 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
138 | 134 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
139 | - } |
|
140 | - else { |
|
135 | + } else { |
|
141 | 136 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
142 | 137 | } |
143 | 138 | } |
@@ -217,11 +212,9 @@ discard block |
||
217 | 212 | foreach ($vars as $var) { |
218 | 213 | if (is_int($var)) { |
219 | 214 | $types .= 'i'; |
220 | - } |
|
221 | - elseif (is_double($var)) { |
|
215 | + } elseif (is_double($var)) { |
|
222 | 216 | $types .= 'd'; |
223 | - } |
|
224 | - else { |
|
217 | + } else { |
|
225 | 218 | $types .= 's'; |
226 | 219 | } |
227 | 220 | } |
@@ -239,8 +232,7 @@ discard block |
||
239 | 232 | foreach ($array as $name => $value) { |
240 | 233 | if ($first) { |
241 | 234 | $first = false; |
242 | - } |
|
243 | - else { |
|
235 | + } else { |
|
244 | 236 | $query .= $operator; |
245 | 237 | } |
246 | 238 | $query .= " `$name` = ?"; |
@@ -257,8 +249,7 @@ discard block |
||
257 | 249 | } |
258 | 250 | if (!empty($count)) { |
259 | 251 | $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count"; |
260 | - } |
|
261 | - elseif (!empty($offset)) { |
|
252 | + } elseif (!empty($offset)) { |
|
262 | 253 | $query .= " OFFSET $offset"; |
263 | 254 | } |
264 | 255 | return $values; |
@@ -316,7 +307,9 @@ discard block |
||
316 | 307 | public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool { |
317 | 308 | $query = "INSERT INTO `$table`("; |
318 | 309 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES ('; |
319 | - if (is_string($values)) $values = [$values]; |
|
310 | + if (is_string($values)) { |
|
311 | + $values = [$values]; |
|
312 | + } |
|
320 | 313 | $query .= '?' . str_repeat(',?', count($values) - 1) . ')'; |
321 | 314 | return self::query($query, $values, false); |
322 | 315 | } |
@@ -340,8 +333,7 @@ discard block |
||
340 | 333 | $query = "SELECT "; |
341 | 334 | if ($columns == '*') { |
342 | 335 | $query .= "* "; |
343 | - } |
|
344 | - else { |
|
336 | + } else { |
|
345 | 337 | $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` '; |
346 | 338 | } |
347 | 339 | $query .= "FROM `$table`"; |
@@ -402,8 +394,11 @@ discard block |
||
402 | 394 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator { |
403 | 395 | $res = self::select($table, $columns, $where, $count, $offset); |
404 | 396 | if ($res) { |
405 | - while ($row = $res->fetch_assoc()) yield $row; |
|
397 | + while ($row = $res->fetch_assoc()) { |
|
398 | + yield $row; |
|
399 | + } |
|
400 | + } else { |
|
401 | + return $res; |
|
406 | 402 | } |
407 | - else return $res; |
|
408 | 403 | } |
409 | 404 | } |
410 | 405 | \ No newline at end of file |
@@ -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'] ?? 'root'; |
@@ -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) && !empty($vars)) { |
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; |
@@ -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); |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | if (file_exists('vendor/autoload.php')){ |
9 | 9 | require 'vendor/autoload.php'; |
10 | -} |
|
11 | -else{ |
|
10 | +} else{ |
|
12 | 11 | if(!file_exists('BPT.phar')) { |
13 | 12 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
14 | 13 | } |
@@ -45,8 +44,7 @@ discard block |
||
45 | 44 | |
46 | 45 | if ($text === '/start') { |
47 | 46 | $this->sendMessage(self::START_TEXT,answer: true); |
48 | - } |
|
49 | - else { |
|
47 | + } else { |
|
50 | 48 | /** You could use both style */ |
51 | 49 | $message_id = $update->message_id; |
52 | 50 | #$message_id = $update->id; |
@@ -54,16 +52,13 @@ discard block |
||
54 | 52 | if (self::ADMIN === $user_id) { |
55 | 53 | if ($text === '/help') { |
56 | 54 | $this->sendMessage(self::HELP, answer: true); |
57 | - } |
|
58 | - elseif ($text === '/reply_on') { |
|
55 | + } elseif ($text === '/reply_on') { |
|
59 | 56 | mysql::update('users',['value'=>'reply_on'],['id'=>$user_id],1); |
60 | 57 | $this->sendMessage(self::REPLY_ON, answer: true); |
61 | - } |
|
62 | - elseif ($text === '/reply_off') { |
|
58 | + } elseif ($text === '/reply_off') { |
|
63 | 59 | mysql::update('users',['value'=>'reply_off'],['id'=>$user_id],1); |
64 | 60 | $this->sendMessage(self::REPLY_OFF, answer: true); |
65 | - } |
|
66 | - elseif (isset($update->reply_to_message)) { |
|
61 | + } elseif (isset($update->reply_to_message)) { |
|
67 | 62 | $reply_message_id = $update->reply_to_message->message_id; |
68 | 63 | |
69 | 64 | if ($update->reply_to_message->from->id === $user_id) { |
@@ -76,13 +71,11 @@ discard block |
||
76 | 71 | $data = $check_message->fetch_object(); |
77 | 72 | $receiver_id = $data->receiver_id; |
78 | 73 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id); |
79 | - } |
|
80 | - else { |
|
74 | + } else { |
|
81 | 75 | $this->sendMessage(self::NOT_FOUND, answer: true); |
82 | 76 | return; |
83 | 77 | } |
84 | - } |
|
85 | - else { |
|
78 | + } else { |
|
86 | 79 | $data = mysql::select('messages', ['sender_message_id','sender_id'], [ |
87 | 80 | 'receiver_message_id' => $reply_message_id, |
88 | 81 | 'receiver_id' => $user_id |
@@ -93,8 +86,7 @@ discard block |
||
93 | 86 | if ($value === 'reply_on') { |
94 | 87 | mysql::update('users',['value'=>''],['id'=>$user_id]); |
95 | 88 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id); |
96 | - } |
|
97 | - else { |
|
89 | + } else { |
|
98 | 90 | $result = $this->copyMessage($receiver_id); |
99 | 91 | } |
100 | 92 | } |
@@ -107,13 +99,11 @@ discard block |
||
107 | 99 | if (self::SHOW_STATUS) { |
108 | 100 | $this->sendMessage(self::SEND_SUCCESSFUL, answer: true); |
109 | 101 | } |
110 | - } |
|
111 | - else { |
|
102 | + } else { |
|
112 | 103 | $this->sendMessage(self::SEND_FAILED, answer: true); |
113 | 104 | } |
114 | 105 | } |
115 | - } |
|
116 | - else { |
|
106 | + } else { |
|
117 | 107 | $username = $update->from->username; |
118 | 108 | if (empty($username)) { |
119 | 109 | $name = $update->from->first_name . (!empty($update->from->last_name) ? (' ' . $update->from->last_name) : ''); |
@@ -137,8 +127,7 @@ discard block |
||
137 | 127 | ] |
138 | 128 | ] |
139 | 129 | ]; |
140 | - } |
|
141 | - else { |
|
130 | + } else { |
|
142 | 131 | $keyboard = [ |
143 | 132 | 'inline_keyboard' => [ |
144 | 133 | [ |
@@ -161,25 +150,21 @@ discard block |
||
161 | 150 | ],1); |
162 | 151 | if ($check_message->num_rows > 0) { |
163 | 152 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard); |
164 | - } |
|
165 | - else { |
|
153 | + } else { |
|
166 | 154 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
167 | 155 | } |
168 | - } |
|
169 | - else { |
|
156 | + } else { |
|
170 | 157 | $check_message = mysql::select('messages', 'sender_message_id', [ |
171 | 158 | 'receiver_message_id' => $reply_message_id, |
172 | 159 | 'receiver_id' => $user_id |
173 | 160 | ],1); |
174 | 161 | if ($check_message->num_rows > 0) { |
175 | 162 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard); |
176 | - } |
|
177 | - else { |
|
163 | + } else { |
|
178 | 164 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
179 | 165 | } |
180 | 166 | } |
181 | - } |
|
182 | - else { |
|
167 | + } else { |
|
183 | 168 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
184 | 169 | } |
185 | 170 | |
@@ -195,8 +180,7 @@ discard block |
||
195 | 180 | if (self::SHOW_STATUS) { |
196 | 181 | $this->sendMessage(self::SEND_SUCCESSFUL, answer: true); |
197 | 182 | } |
198 | - } |
|
199 | - else { |
|
183 | + } else { |
|
200 | 184 | $this->sendMessage(self::SEND_FAILED, answer: true); |
201 | 185 | } |
202 | 186 | } |
@@ -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 | } |
@@ -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 | } |
@@ -26,23 +26,23 @@ |
||
26 | 26 | public int $date; |
27 | 27 | |
28 | 28 | /** Optional. Bio of the user. */ |
29 | - public null|string $bio = null; |
|
29 | + public null | string $bio = null; |
|
30 | 30 | |
31 | 31 | /** Optional. Chat invite link that was used by the user to send the join request */ |
32 | - public null|chatInviteLink $invite_link = null; |
|
32 | + public null | chatInviteLink $invite_link = null; |
|
33 | 33 | |
34 | 34 | |
35 | - public function __construct(stdClass|null $object = null) { |
|
35 | + public function __construct(stdClass | null $object = null) { |
|
36 | 36 | if ($object != null) { |
37 | 37 | parent::__construct($object, self::subs); |
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | - public function accept(): responseError|bool { |
|
42 | - return telegram::approveChatJoinRequest($this->chat->id,$this->from->id); |
|
41 | + public function accept(): responseError | bool { |
|
42 | + return telegram::approveChatJoinRequest($this->chat->id, $this->from->id); |
|
43 | 43 | } |
44 | 44 | |
45 | - public function deny(): responseError|bool { |
|
46 | - return telegram::declineChatJoinRequest($this->chat->id,$this->from->id); |
|
45 | + public function deny(): responseError | bool { |
|
46 | + return telegram::declineChatJoinRequest($this->chat->id, $this->from->id); |
|
47 | 47 | } |
48 | 48 | } |
@@ -18,31 +18,31 @@ |
||
18 | 18 | public float $latitude; |
19 | 19 | |
20 | 20 | /** Optional. The radius of uncertainty for the location, measured in meters; 0-1500 */ |
21 | - public null|float $horizontal_accuracy = null; |
|
21 | + public null | float $horizontal_accuracy = null; |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Optional. Time relative to the message sending date, during which the location can be updated; in seconds. For |
25 | 25 | * active live locations only. |
26 | 26 | */ |
27 | - public null|int $live_period = null; |
|
27 | + public null | int $live_period = null; |
|
28 | 28 | |
29 | 29 | /** Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. */ |
30 | - public null|int $heading = null; |
|
30 | + public null | int $heading = null; |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Optional. The maximum distance for proximity alerts about approaching another chat member, in meters. For sent |
34 | 34 | * live locations only. |
35 | 35 | */ |
36 | - public null|int $proximity_alert_radius = null; |
|
36 | + public null | int $proximity_alert_radius = null; |
|
37 | 37 | |
38 | 38 | |
39 | - public function __construct(stdClass|null $object = null) { |
|
39 | + public function __construct(stdClass | null $object = null) { |
|
40 | 40 | if ($object != null) { |
41 | 41 | parent::__construct($object, self::subs); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - public function mapLink (): string { |
|
45 | + public function mapLink(): string { |
|
46 | 46 | return "https://www.google.com/maps/search/$this->latitude,$this->longitude"; |
47 | 47 | } |
48 | 48 | } |