2016-08-09 22:28:50 +02:00
|
|
|
#!/usr/bin/env php
|
2016-06-23 23:51:08 +02:00
|
|
|
<?php
|
2016-11-16 15:18:35 +01:00
|
|
|
/*
|
|
|
|
Copyright 2016 Daniil Gentili
|
|
|
|
(https://daniil.it)
|
|
|
|
This file is part of MadelineProto.
|
|
|
|
MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with MadelineProto.
|
|
|
|
If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-07-14 15:15:50 +02:00
|
|
|
|
2016-08-07 23:23:10 +02:00
|
|
|
require_once 'vendor/autoload.php';
|
2016-12-26 18:23:46 +01:00
|
|
|
$settings = [];
|
|
|
|
if (file_exists('web_data.php')) {
|
2016-12-26 20:24:24 +01:00
|
|
|
require_once 'web_data.php';
|
2016-12-26 18:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
2016-09-12 22:28:27 +02:00
|
|
|
|
2016-12-26 18:23:46 +01:00
|
|
|
if (file_exists('number.php') && $MadelineProto === false) {
|
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
|
|
|
include_once 'number.php';
|
2016-12-26 18:23:46 +01:00
|
|
|
$MadelineProto = new \danog\MadelineProto\API($settings);
|
2016-11-25 00:15:53 +01:00
|
|
|
|
|
|
|
$checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone
|
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
|
|
|
[
|
2016-11-25 00:15:53 +01:00
|
|
|
'phone_number' => $number,
|
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
|
|
|
]
|
|
|
|
);
|
2016-12-24 17:20:45 +01:00
|
|
|
\danog\MadelineProto\Logger::log($checkedPhone);
|
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
|
|
|
$sentCode = $MadelineProto->phone_login($number);
|
2016-12-24 17:20:45 +01:00
|
|
|
\danog\MadelineProto\Logger::log($sentCode);
|
2016-11-23 21:04:29 +01:00
|
|
|
echo 'Enter the code you received: ';
|
|
|
|
$code = '';
|
|
|
|
for ($x = 0; $x < $sentCode['type']['length']; $x++) {
|
|
|
|
$code .= fgetc(STDIN);
|
|
|
|
}
|
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
|
|
|
$authorization = $MadelineProto->complete_phone_login($code);
|
2016-12-24 17:20:45 +01:00
|
|
|
\danog\MadelineProto\Logger::log($authorization);
|
2016-11-29 01:47:59 +01:00
|
|
|
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
2016-12-26 18:23:46 +01:00
|
|
|
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
|
|
|
}
|
2016-11-29 01:47:59 +01:00
|
|
|
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
|
2016-12-26 18:23:46 +01:00
|
|
|
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
2016-11-25 21:52:56 +01:00
|
|
|
|
2016-12-26 18:23:46 +01:00
|
|
|
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
|
2016-12-23 21:06:38 +01:00
|
|
|
|
|
|
|
$flutter = 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4';
|
|
|
|
|
2016-12-26 18:23:46 +01:00
|
|
|
$mention = $MadelineProto->get_info('@giuseppe_la_gaipa_2'); // Returns the following array: ['constructor' => $constructor, 'inputPeer' => $inputPeer, 'inputType' => $inputType, 'Peer' => $Peer, 'id' => $id, 'botApiId' => $bot_api_id]
|
|
|
|
$mention = $mention['inputType']; // Selects only the inputType object
|
2016-12-23 21:06:38 +01:00
|
|
|
|
|
|
|
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
|
2016-12-26 18:23:46 +01:00
|
|
|
$peer = $MadelineProto->get_info($peer)['inputPeer']; // Select the inputPeerType (alias inputPeer) object
|
|
|
|
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
|
2016-12-24 17:20:45 +01:00
|
|
|
\danog\MadelineProto\Logger::log($sentMessage);
|
2016-11-29 01:47:59 +01:00
|
|
|
}
|
|
|
|
|
2016-12-26 18:23:46 +01:00
|
|
|
sleep(5);
|
|
|
|
$MadelineProto->API->get_updates_difference();
|
|
|
|
|
2016-11-29 01:47:59 +01:00
|
|
|
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
|
2016-11-24 13:16:06 +01:00
|
|
|
if (file_exists('token.php')) {
|
|
|
|
include_once 'token.php';
|
2016-12-26 18:23:46 +01:00
|
|
|
$MadelineProto = new \danog\MadelineProto\API($settings);
|
2016-11-29 01:47:59 +01:00
|
|
|
$authorization = $MadelineProto->bot_login($token);
|
2016-12-24 17:20:45 +01:00
|
|
|
\danog\MadelineProto\Logger::log($authorization);
|
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
|
|
|
}
|
2016-12-23 21:06:38 +01:00
|
|
|
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
|
2016-12-26 18:23:46 +01:00
|
|
|
$peer = $MadelineProto->get_info($peer)['inputPeer']; // Select the inputPeerType (alias inputPeer) object
|
|
|
|
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
|
2016-12-24 17:20:45 +01:00
|
|
|
\danog\MadelineProto\Logger::log($sentMessage);
|
2016-11-29 01:47:59 +01:00
|
|
|
}
|