From eafc2464a9969c1857873e3a7a3d2aed3403d1c1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 20 Sep 2017 19:51:04 +0200 Subject: [PATCH 1/4] Fixes to lua module --- src/danog/MadelineProto/Lua.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/danog/MadelineProto/Lua.php b/src/danog/MadelineProto/Lua.php index 5c95da05..168a6fff 100644 --- a/src/danog/MadelineProto/Lua.php +++ b/src/danog/MadelineProto/Lua.php @@ -42,7 +42,7 @@ class Lua $this->Lua->registerCallback('tdcli_function', [$this, 'tdcli_function']); $this->Lua->registerCallback('madeline_function', [$this, 'madeline_function']); foreach (get_class_methods($this->MadelineProto->API) as $method) { - $this->Lua->registerCallback($method, [$this->MadelineProto->API, $method]); + $this->Lua->registerCallback($method, [$this->MadelineProto, $method]); } $methods = []; foreach ($this->MadelineProto->get_methods_namespaced() as $pair) { From 4bc345f6f95e9694ad15cc57714bf2fcac7e74e0 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 20 Sep 2017 19:55:24 +0200 Subject: [PATCH 2/4] Fixes to logger --- src/danog/MadelineProto/MTProto.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index c12d4e64..0537176a 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -362,6 +362,7 @@ class MTProto if ($this->authorized === self::LOGGED_IN) { $this->get_self(); $this->get_cdn_config($this->datacenter->curdc); + $this->setup_logger(); } if ($this->authorized === self::LOGGED_IN && !$this->authorization['user']['bot']) { $this->get_dialogs($force); From 9e241def533deef9e1af40846cef2b837d597373 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 20 Sep 2017 20:52:54 +0200 Subject: [PATCH 3/4] Bugfixes to update handling peer management --- .env.example | 1 - magna.php | 9 +----- secret_bot.php | 9 +----- .../MTProtoTools/PeerHandler.php | 30 +++++++++---------- .../MTProtoTools/UpdateHandler.php | 7 ++++- 5 files changed, 23 insertions(+), 33 deletions(-) diff --git a/.env.example b/.env.example index 2af7d453..43453030 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ -MTPROTO_NUMBER=+39394838932 MTPROTO_SETTINGS={"app_info":{"api_id":6,"api_hash":"eb06d4abfb49dc3eeb1aeb98ae0f581e"}} TEST_USERNAME=@danogentili TEST_DESTINATION_GROUPS=["@pwrtelegramgroup","@pwrtelegramgroupita"] diff --git a/magna.php b/magna.php index f89c7886..2675346d 100755 --- a/magna.php +++ b/magna.php @@ -41,14 +41,7 @@ if ($MadelineProto === false) { echo 'Loading MadelineProto...'.PHP_EOL; $MadelineProto = new \danog\MadelineProto\API($settings); if (getenv('TRAVIS_COMMIT') == '') { - $checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone - [ - 'phone_number' => getenv('MTPROTO_NUMBER'), - ] - ); - - \danog\MadelineProto\Logger::log([$checkedPhone], \danog\MadelineProto\Logger::NOTICE); - $sentCode = $MadelineProto->phone_login(getenv('MTPROTO_NUMBER')); + $sentCode = $MadelineProto->phone_login(readline('Enter your phone number: ')); \danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE); echo 'Enter the code you received: '; $code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1); diff --git a/secret_bot.php b/secret_bot.php index 8c86f865..038e4aab 100755 --- a/secret_bot.php +++ b/secret_bot.php @@ -37,14 +37,7 @@ if ($MadelineProto === false) { echo 'Loading MadelineProto...'.PHP_EOL; $MadelineProto = new \danog\MadelineProto\API($settings); if (getenv('TRAVIS_COMMIT') == '') { - $checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone - [ - 'phone_number' => getenv('MTPROTO_NUMBER'), - ] - ); - - \danog\MadelineProto\Logger::log([$checkedPhone], \danog\MadelineProto\Logger::NOTICE); - $sentCode = $MadelineProto->phone_login(getenv('MTPROTO_NUMBER')); + $sentCode = $MadelineProto->phone_login(readline('Enter your phone number: ')); \danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE); echo 'Enter the code you received: '; $code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1); diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index b75fed0d..cbf8a4ee 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -21,6 +21,9 @@ trait PeerHandler { foreach ($users as $key => $user) { if (!isset($user['access_hash'])) { + if (isset($user['username']) && !isset($this->chats[$user['id']])) { + $this->get_pwr_chat($user['username'], false, true); + } continue; } switch ($user['_']) { @@ -71,10 +74,13 @@ trait PeerHandler break; case 'channel': case 'channelForbidden': + $bot_api_id = $this->to_supergroup($chat['id']); if (!isset($chat['access_hash'])) { + if (isset($chat['username']) && !isset($this->chats[$bot_api_id])) { + $this->get_pwr_chat($chat['username'], true, true); + } continue; } - $bot_api_id = $this->to_supergroup($chat['id']); if (!isset($this->chats[$bot_api_id]) || $this->chats[$bot_api_id] !== $chat) { $this->chats[$bot_api_id] = $chat; @@ -130,7 +136,7 @@ trait PeerHandler if (isset($fwd['user_id']) && !$this->peer_isset($fwd['user_id'])) { return false; } - if (isset($fwd['channel_id']) && !$this->peer_isset('channel#'.$fwd['channel_id'])) { + if (isset($fwd['channel_id']) && !$this->peer_isset($this->to_supergroup($fwd['channel_id']))) { return false; } } catch (\danog\MadelineProto\Exception $e) { @@ -161,19 +167,16 @@ trait PeerHandler break; case 'chat': - $id = -$id['id']; - break; case 'chatFull': $id = -$id['id']; break; - case 'inputPeerChat': + + case 'inputPeerChat': case 'peerChat': $id = -$id['chat_id']; break; case 'channel': - $id = $this->to_supergroup($id['id']); - break; case 'channelFull': $id = $this->to_supergroup($id['id']); break; @@ -204,15 +207,12 @@ trait PeerHandler if (is_string($id)) { $id = \danog\MadelineProto\Logger::$bigint ? ((float) $id) : ((int) $id); } + if (!isset($this->chats[$id]) && $id < 0 && !preg_match('/^-100/', $id)) { + $this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]); + } if (isset($this->chats[$id])) { return $this->gen_all($this->chats[$id]); } - if ($id < 0 && !preg_match('/^-100/', $id)) { - $this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]); - if (isset($this->chats[$id])) { - return $this->gen_all($this->chats[$id]); - } - } if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) { $dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http'=> [ 'timeout' => 2, @@ -225,9 +225,9 @@ trait PeerHandler throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database'); } - $id = str_replace('@', '', $id); + $id = strtolower(str_replace('@', '', $id)); foreach ($this->chats as $chat) { - if (isset($chat['username']) && strtolower($chat['username']) === strtolower($id)) { + if (isset($chat['username']) && strtolower($chat['username']) === $id) { return $this->gen_all($chat); } } diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index b9373b24..c5e26278 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -79,7 +79,12 @@ trait UpdateHandler }); $time = microtime(true); - $this->get_updates_difference(); + try { + $this->get_updates_difference(); + } catch (\danog\MadelineProto\RPCErrorException $e) { + if ($e->rpc !== 'RPC_CALL_FAIL') throw $e; + } + $default_params = ['offset' => 0, 'limit' => null, 'timeout' => 0]; foreach ($default_params as $key => $default) { if (!isset($params[$key])) { From aec908c17393d354ce32d27e9b1a9b3a69ebe6bd Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 20 Sep 2017 18:53:09 +0000 Subject: [PATCH 4/4] Apply fixes from StyleCI --- src/danog/MadelineProto/MTProtoTools/UpdateHandler.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index c5e26278..a47e1863 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -79,10 +79,13 @@ trait UpdateHandler }); $time = microtime(true); + try { $this->get_updates_difference(); } catch (\danog\MadelineProto\RPCErrorException $e) { - if ($e->rpc !== 'RPC_CALL_FAIL') throw $e; + if ($e->rpc !== 'RPC_CALL_FAIL') { + throw $e; + } } $default_params = ['offset' => 0, 'limit' => null, 'timeout' => 0];