2017-03-12 04:15:51 +01:00
#!/usr/bin/env php
< ? php
/*
Copyright 2016 - 2017 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 />.
*/
require_once 'vendor/autoload.php' ;
if ( file_exists ( 'web_data.php' )) {
require_once 'web_data.php' ;
}
2017-03-12 13:57:23 +01:00
echo 'Deserializing MadelineProto from calls.madeline...' . PHP_EOL ;
2017-03-12 04:15:51 +01:00
$MadelineProto = false ;
try {
2017-03-12 13:57:23 +01:00
$MadelineProto = \danog\MadelineProto\Serialization :: deserialize ( 'calls.madeline' );
2017-03-12 04:15:51 +01:00
} catch ( \danog\MadelineProto\Exception $e ) {
}
if ( file_exists ( '.env' )) {
echo 'Loading .env...' . PHP_EOL ;
$dotenv = new Dotenv\Dotenv ( getcwd ());
$dotenv -> load ();
}
echo 'Loading settings...' . PHP_EOL ;
$settings = json_decode ( getenv ( 'MTPROTO_SETTINGS' ), true ) ? : [];
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' ));
\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 );
$authorization = $MadelineProto -> complete_phone_login ( $code );
\danog\MadelineProto\Logger :: log ([ $authorization ], \danog\MadelineProto\Logger :: NOTICE );
if ( $authorization [ '_' ] === 'account.noPassword' ) {
throw new \danog\MadelineProto\Exception ( '2FA is enabled but no password is set!' );
}
if ( $authorization [ '_' ] === 'account.password' ) {
\danog\MadelineProto\Logger :: log ([ '2FA is enabled' ], \danog\MadelineProto\Logger :: NOTICE );
$authorization = $MadelineProto -> complete_2fa_login ( readline ( 'Please enter your password (hint ' . $authorization [ 'hint' ] . '): ' ));
}
if ( $authorization [ '_' ] === 'account.needSignup' ) {
\danog\MadelineProto\Logger :: log ([ 'Registering new user' ], \danog\MadelineProto\Logger :: NOTICE );
$authorization = $MadelineProto -> complete_signup ( $code , readline ( 'Please enter your first name: ' ), readline ( 'Please enter your last name (can be empty): ' ));
}
2017-03-12 13:57:23 +01:00
echo 'Serializing MadelineProto to calls.madeline...' . PHP_EOL ;
echo 'Wrote ' . \danog\MadelineProto\Serialization :: serialize ( 'calls.madeline' , $MadelineProto ) . ' bytes' . PHP_EOL ;
2017-03-12 04:15:51 +01:00
} else {
$MadelineProto -> bot_login ( getenv ( 'BOT_TOKEN' ));
}
}
2017-03-12 13:57:23 +01:00
for ( $x = 0 ; $x < $argv [ 2 ]; $x ++ ) {
$MadelineProto -> request_call ( $argv [ 1 ]);
2017-03-12 04:15:51 +01:00
$MadelineProto -> get_updates_difference ();
2017-03-12 04:16:07 +01:00
echo 'Wrote ' . \danog\MadelineProto\Serialization :: serialize ( 'session.madeline' , $MadelineProto ) . ' bytes' . PHP_EOL ;
2017-03-12 04:15:51 +01:00
}
2017-03-24 21:01:08 +01:00
$MadelineProto -> messages -> sendMessage ([ 'peer' => $argv [ 1 ], 'message' => '<a href="https://github.com/danog/MadelineProto">Powered by MadelineProto</a>' , 'parse_mode' => 'markdown' ]);