MadelineProto/testing.php

84 lines
4.3 KiB
PHP
Raw Normal View History

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';
$settings = [];
if (file_exists('web_data.php')) {
2016-12-26 20:24:24 +01:00
require_once 'web_data.php';
}
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
2016-09-12 22:28:27 +02:00
if (file_exists('number.php') && $MadelineProto === false) {
include_once 'number.php';
$MadelineProto = new \danog\MadelineProto\API($settings);
2016-11-25 00:15:53 +01:00
$checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone
[
2016-11-25 00:15:53 +01:00
'phone_number' => $number,
]
);
2016-12-24 17:20:45 +01:00
\danog\MadelineProto\Logger::log($checkedPhone);
$sentCode = $MadelineProto->phone_login($number);
2016-12-24 17:20:45 +01:00
\danog\MadelineProto\Logger::log($sentCode);
echo 'Enter the code you received: ';
$code = '';
for ($x = 0; $x < $sentCode['type']['length']; $x++) {
$code .= fgetc(STDIN);
}
$authorization = $MadelineProto->complete_phone_login($code);
2016-12-24 17:20:45 +01:00
\danog\MadelineProto\Logger::log($authorization);
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
}
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
$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'));
$flutter = 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4';
$mention = $MadelineProto->get_info('@danogentili'); // Returns an array with all of the constructors that can be extracted from a username or an id
$mention = $mention['user_id']; // Selects only the numeric user id
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$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);
}
sleep(5);
var_dump($MadelineProto->API->get_updates());
2016-12-30 21:21:36 +01:00
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
if (file_exists('token.php')) {
include_once 'token.php';
$MadelineProto = new \danog\MadelineProto\API($settings);
$authorization = $MadelineProto->bot_login($token);
2016-12-24 17:20:45 +01:00
\danog\MadelineProto\Logger::log($authorization);
}
$message = 'yay';
$mention = $MadelineProto->get_info('@danogentili'); // Returns an array with all of the constructors that can be extracted from a username or an id
$mention = $mention['user_id']; // Selects only the numeric user id
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$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);
}
sleep(5);
var_dump($MadelineProto->API->get_updates());
while (true) {
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => '@pwrtelegramgroupita', 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
}