From 270463679a09042725f02113f22a11137d41203c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 10 Nov 2017 15:35:57 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/danog/MadelineProto/MTProto.php | 9 ++++---- .../MTProtoTools/CallHandler.php | 22 +++++++++---------- .../MTProtoTools/PeerHandler.php | 5 ++++- .../MTProtoTools/UpdateHandler.php | 1 + src/danog/MadelineProto/RPCErrorException.php | 6 ++++- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 8bcf1f92..7a7aa257 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -237,7 +237,6 @@ class MTProto $this->twoe2047 = new \phpseclib\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328'); $this->twoe2048 = new \phpseclib\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656'); - $this->connect_to_all_dcs(); $this->datacenter->curdc = 2; @@ -521,17 +520,17 @@ class MTProto 'call_queue' => 200, ], 'peer' => [ - 'full_info_cache_time' => 3600, // Full peer info cache validity - 'full_fetch' => false, // Should madeline fetch the full member list of every group it meets? + 'full_info_cache_time' => 3600, // Full peer info cache validity + 'full_fetch' => false, // Should madeline fetch the full member list of every group it meets? 'cache_all_peers_on_startup' => false, // Should madeline fetch the full chat list on startup? ], 'requests' => [ 'gzip_encode_if_gt' => 500, // Should I try using gzip encoding for requests bigger than N bytes? Set to -1 to disable. ], 'updates' => [ - 'handle_updates' => true, // Should I handle updates? + 'handle_updates' => true, // Should I handle updates? 'handle_old_updates' => true, // Should I handle old updates on startup? - 'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter + 'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter ], 'secret_chats' => [ 'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index 1bce0f9c..b4217093 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -125,20 +125,20 @@ trait CallHandler $this->datacenter->sockets[$aargs['datacenter']]->incoming_messages[$this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]['response']]['content'] = ''; break; } - if (($error = $this->recv_message($aargs['datacenter'])) !== true) { - if ($error === -404) { - if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) { - \danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING); - $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null; - $this->init_authorization(); + if (($error = $this->recv_message($aargs['datacenter'])) !== true) { + if ($error === -404) { + if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) { + \danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING); + $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null; + $this->init_authorization(); - throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key'); - } + throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key'); } - - throw new \danog\MadelineProto\RPCErrorException($error, $error); } - $only_updates = $this->handle_messages($aargs['datacenter']); // This method receives data from the socket, and parses stuff + + throw new \danog\MadelineProto\RPCErrorException($error, $error); + } + $only_updates = $this->handle_messages($aargs['datacenter']); // This method receives data from the socket, and parses stuff } catch (\danog\MadelineProto\Exception $e) { if ($e->getMessage() === 'I had to recreate the temporary authorization key') { continue 2; diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 9cac3695..d704103b 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -30,6 +30,7 @@ trait PeerHandler case 'user': if (!isset($this->chats[$user['id']]) || $this->chats[$user['id']] !== $user) { $this->chats[$user['id']] = $user; + try { $this->get_pwr_chat($user['id'], false, true); } catch (\danog\MadelineProto\Exception $e) { @@ -522,7 +523,9 @@ trait PeerHandler } $res['participants'] = array_values($res['participants']); } - if (!$fullfetch) unset($res['participants']); + if (!$fullfetch) { + unset($res['participants']); + } if ($fullfetch || $send) { $this->store_db($res); } diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index 704f3b8a..6b5d2ff8 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -115,6 +115,7 @@ trait UpdateHandler $updates[] = ['update_id' => $key, 'update' => $value]; } } + return $updates; } diff --git a/src/danog/MadelineProto/RPCErrorException.php b/src/danog/MadelineProto/RPCErrorException.php index 1c834c18..2782564c 100644 --- a/src/danog/MadelineProto/RPCErrorException.php +++ b/src/danog/MadelineProto/RPCErrorException.php @@ -16,15 +16,19 @@ class RPCErrorException extends \Exception { use TL\PrettyException; private $fetched = false; - public function getMess() { + + public function getMess() + { if ($this->fetched === false) { $res = json_decode(@file_get_contents('https://rpc.pwrtelegram.xyz/?method='.$additional[0].'&code='.$code.'&error='.$this->rpc), true); if (isset($res['ok']) && $res['ok']) { $this->message = $res['result']; } } + return $this->message; } + public function __toString() { return sprintf(\danog\MadelineProto\Lang::$current_lang['rpc_tg_error'], $this->getMess(), $this->rpc, $this->file, $this->line.PHP_EOL.PHP_EOL).PHP_EOL.$this->getTLTrace().PHP_EOL;