mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 06:59:01 +01:00
Pappa pronta
This commit is contained in:
parent
8a0f04483d
commit
e1ca8b612c
@ -12,20 +12,48 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
$settings = [];
|
||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
|
||||
$Lua = false;
|
||||
|
||||
try {
|
||||
$Lua = \danog\MadelineProto\Serialization::deserialize('bot.madeline');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
}
|
||||
if (file_exists('token.php') && !is_object($Lua)) {
|
||||
include_once 'token.php';
|
||||
$MadelineProto = new \danog\MadelineProto\API($settings);
|
||||
$authorization = $MadelineProto->bot_login($token);
|
||||
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
|
||||
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
|
||||
if (!is_object($Lua)) {
|
||||
$MadelineProto = new \danog\MadelineProto\API($settings);
|
||||
while (!in_array(($res = readline('Do you want to login as a user or as a bot (u/b)? ')), ['u', 'b'])) {
|
||||
echo 'Please write either u or b'.PHP_EOL;
|
||||
}
|
||||
switch ($res) {
|
||||
case 'u':
|
||||
$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);
|
||||
$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(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
|
||||
}
|
||||
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
|
||||
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
|
||||
break;
|
||||
case 'b':
|
||||
$authorization = $MadelineProto->bot_login(readline('Please enter a bot token: '));
|
||||
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
|
||||
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
while (true) {
|
||||
$updates = $Lua->MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
||||
|
41
lua/td.php
41
lua/td.php
@ -13,18 +13,47 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
$settings = [];
|
||||
$Lua = false;
|
||||
|
||||
try {
|
||||
$Lua = \danog\MadelineProto\Serialization::deserialize('td.madeline');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
if (file_exists('token.php')) {
|
||||
include_once 'token.php';
|
||||
$MadelineProto = new \danog\MadelineProto\API($settings);
|
||||
$authorization = $MadelineProto->bot_login($token);
|
||||
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
|
||||
$Lua = new \danog\MadelineProto\Lua('td.lua', $MadelineProto);
|
||||
}
|
||||
if (!is_object($Lua)) {
|
||||
$MadelineProto = new \danog\MadelineProto\API($settings);
|
||||
while (!in_array(($res = readline('Do you want to login as a user or as a bot (u/b)? ')), ['u', 'b'])) {
|
||||
echo 'Please write either u or b'.PHP_EOL;
|
||||
}
|
||||
switch ($res) {
|
||||
case 'u':
|
||||
$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);
|
||||
$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(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
|
||||
}
|
||||
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
|
||||
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
|
||||
break;
|
||||
case 'b':
|
||||
$authorization = $MadelineProto->bot_login(readline('Please enter a bot token: '));
|
||||
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
|
||||
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
while (true) {
|
||||
$updates = $Lua->MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
||||
|
Loading…
Reference in New Issue
Block a user