This commit is contained in:
Daniil Gentili 2017-09-21 08:35:23 +00:00
commit c552b6d66b
7 changed files with 28 additions and 34 deletions

View File

@ -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"]

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);
}
}

View File

@ -79,7 +79,15 @@ 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])) {