Apply fixes from StyleCI
This commit is contained in:
parent
1cb3c35ac8
commit
86d146c977
7
bot.php
7
bot.php
@ -12,7 +12,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
|
||||
|
||||
/**
|
||||
/*
|
||||
* Various ways to load MadelineProto
|
||||
*/
|
||||
if (!file_exists(__DIR__.'/vendor/autoload.php')) {
|
||||
@ -29,12 +29,14 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
{
|
||||
public function onAny($update)
|
||||
{
|
||||
\danog\MadelineProto\Logger::log("Received an update of type ".$update['_']);
|
||||
\danog\MadelineProto\Logger::log('Received an update of type '.$update['_']);
|
||||
}
|
||||
|
||||
public function onUpdateNewChannelMessage($update)
|
||||
{
|
||||
$this->onUpdateNewMessage($update);
|
||||
}
|
||||
|
||||
public function onUpdateNewMessage($update)
|
||||
{
|
||||
if (isset($update['message']['out']) && $update['message']['out']) {
|
||||
@ -63,7 +65,6 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]]; //, 'connection_settings' => ['all' => ['test_mode' => true]]];
|
||||
|
||||
try {
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
$index = '';
|
||||
$files = glob('docs/docs/*md');
|
||||
foreach ($files as $file) {
|
||||
@ -53,12 +54,12 @@ foreach ($files as $file) {
|
||||
ksort($orderedfiles);
|
||||
foreach ($orderedfiles as $key => $filename) {
|
||||
$lines = explode("\n", file_get_contents($filename));
|
||||
while (end($lines) === '' || strpos(end($lines), "Next")) {
|
||||
while (end($lines) === '' || strpos(end($lines), 'Next')) {
|
||||
unset($lines[count($lines) - 1]);
|
||||
}
|
||||
if (isset($orderedfiles[$key + 1])) {
|
||||
$nextfile = "https://docs.madelineproto.xyz/docs/".basename($orderedfiles[$key+1], '.md').".html";
|
||||
$prevfile = $key === 0 ? "https://docs.madelineproto.xyz" : "https://docs.madelineproto.xyz/docs/".basename($orderedfiles[$key-1], '.md').".html";
|
||||
$nextfile = 'https://docs.madelineproto.xyz/docs/'.basename($orderedfiles[$key + 1], '.md').'.html';
|
||||
$prevfile = $key === 0 ? 'https://docs.madelineproto.xyz' : 'https://docs.madelineproto.xyz/docs/'.basename($orderedfiles[$key - 1], '.md').'.html';
|
||||
$lines[count($lines)] = "\n<form action=\"$prevfile\"><input type=\"submit\" value=\"Previous section\" /></form><form action=\"$nextfile\"><input type=\"submit\" value=\"Next section\" /></form>";
|
||||
} else {
|
||||
$lines[count($lines)] = "\n<form action=\"https://docs.madelineproto.xyz/#very-complex-and-complete-examples\"><input type=\"submit\" value=\"Next section\" /></form>";
|
||||
@ -68,13 +69,13 @@ foreach ($orderedfiles as $key => $filename) {
|
||||
preg_match('|^# (.*)|', $file = file_get_contents($filename), $matches);
|
||||
$title = $matches[1];
|
||||
preg_match_all('|( *)\* \[(.*)\]\(#(.*)\)|', $file, $matches);
|
||||
$file = "https://docs.madelineproto.xyz/docs/".basename($filename, '.md').".html";
|
||||
$file = 'https://docs.madelineproto.xyz/docs/'.basename($filename, '.md').'.html';
|
||||
$index .= "* [$title]($file)\n";
|
||||
if (basename($filename) !== 'FEATURES.md') {
|
||||
foreach ($matches[1] as $key => $match) {
|
||||
$spaces = " $match";
|
||||
$name = $matches[2][$key];
|
||||
$url = $file."#".$matches[3][$key];
|
||||
$url = $file.'#'.$matches[3][$key];
|
||||
$index .= "$spaces* [$name]($url)\n";
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,8 @@ namespace danog\MadelineProto;
|
||||
|
||||
class Lang
|
||||
{
|
||||
public static $lang = array (
|
||||
'it' =>
|
||||
array (
|
||||
public static $lang = [
|
||||
'it' => [
|
||||
'phpseclib_fork' => 'Per favore installa questo fork di phpseclib: https://github.com/danog/phpseclib',
|
||||
'inst_dc' => 'Istanziamento dei DataCenter...',
|
||||
'load_rsa' => 'Caricamento delle chiavi RSA...',
|
||||
@ -156,9 +155,8 @@ class Lang
|
||||
'done' => 'Fatto!',
|
||||
'cdn_reupload' => 'Il file non è disponibile sul nostro CDN, richiedo la copia!',
|
||||
'stored_on_cdn' => 'Il file è scaricabile tramite CDN!',
|
||||
),
|
||||
'en' =>
|
||||
array (
|
||||
],
|
||||
'en' => [
|
||||
'req_pq' => 'Requesting pq...',
|
||||
'done' => 'Done!',
|
||||
'cdn_reupload' => 'File is not stored on CDN, requesting reupload!',
|
||||
@ -328,11 +326,11 @@ class Lang
|
||||
'method_http_wait_param_max_delay' => '',
|
||||
'method_http_wait_param_wait_after' => '',
|
||||
'method_http_wait_param_max_wait' => '',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// THIS WILL BE OVERWRITTEN BY $lang["en"]
|
||||
public static $current_lang = array (
|
||||
public static $current_lang = [
|
||||
'req_pq' => 'Requesting pq...',
|
||||
'done' => 'Done!',
|
||||
'cdn_reupload' => 'File is not stored on CDN, requesting reupload!',
|
||||
@ -502,5 +500,5 @@ class Lang
|
||||
'method_http_wait_param_max_delay' => '',
|
||||
'method_http_wait_param_wait_after' => '',
|
||||
'method_http_wait_param_max_wait' => '',
|
||||
);
|
||||
];
|
||||
}
|
@ -5,7 +5,6 @@ require 'vendor/autoload.php';
|
||||
$MadelineProto = new \danog\MadelineProto\API('session.madeline'); //, ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']]);
|
||||
$me = $MadelineProto->start();
|
||||
|
||||
|
||||
$me = $MadelineProto->get_self();
|
||||
|
||||
\danog\MadelineProto\Logger::log($me);
|
||||
|
@ -12,7 +12,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
|
||||
|
||||
/**
|
||||
/*
|
||||
* Various ways to load MadelineProto
|
||||
*/
|
||||
if (!file_exists(__DIR__.'/vendor/autoload.php')) {
|
||||
@ -31,6 +31,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
{
|
||||
$this->onUpdateNewMessage($update);
|
||||
}
|
||||
|
||||
public function onUpdateNewMessage($update)
|
||||
{
|
||||
if (isset($update['message']['out']) && $update['message']['out']) {
|
||||
@ -59,7 +60,6 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]]; //, 'connection_settings' => ['all' => ['test_mode' => true]]];
|
||||
|
||||
try {
|
||||
|
@ -12,7 +12,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
|
||||
|
||||
/**
|
||||
/*
|
||||
* Various ways to load MadelineProto
|
||||
*/
|
||||
if (!file_exists(__DIR__.'/vendor/autoload.php')) {
|
||||
@ -25,13 +25,16 @@ if (!file_exists(__DIR__.'/vendor/autoload.php')) {
|
||||
require_once 'vendor/autoload.php';
|
||||
}
|
||||
|
||||
|
||||
class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
{
|
||||
private $sent = [-440592694 => true];
|
||||
public function onUpdateNewEncryptedMessage($update) {
|
||||
|
||||
public function onUpdateNewEncryptedMessage($update)
|
||||
{
|
||||
try {
|
||||
if (isset($update['message']['decrypted_message']['media'])) \danog\MadelineProto\Logger::log($this->download_to_dir($update, '.'));
|
||||
if (isset($update['message']['decrypted_message']['media'])) {
|
||||
\danog\MadelineProto\Logger::log($this->download_to_dir($update, '.'));
|
||||
}
|
||||
if (isset($this->sent[$update['message']['chat_id']])) {
|
||||
return;
|
||||
}
|
||||
@ -87,9 +90,6 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (file_exists('.env')) {
|
||||
echo 'Loading .env...'.PHP_EOL;
|
||||
$dotenv = new Dotenv\Dotenv(getcwd());
|
||||
@ -99,7 +99,6 @@ if (file_exists('.env')) {
|
||||
echo 'Loading settings...'.PHP_EOL;
|
||||
$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
|
||||
|
||||
|
||||
try {
|
||||
$MadelineProto = new \danog\MadelineProto\API('s.madeline', $settings);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
|
@ -10,7 +10,6 @@ You should have received a copy of the GNU General Public License along with Mad
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
class HttpProxy implements \danog\MadelineProto\Proxy
|
||||
{
|
||||
private $domain;
|
||||
@ -18,7 +17,9 @@ class HttpProxy implements \danog\MadelineProto\Proxy
|
||||
private $protocol;
|
||||
private $extra;
|
||||
private $sock;
|
||||
public function __construct($domain, $type, $protocol) {
|
||||
|
||||
public function __construct($domain, $type, $protocol)
|
||||
{
|
||||
if (!in_array($domain, [AF_INET, AF_INET6])) {
|
||||
throw new \danog\MadelineProto\Exception('Wrong protocol family provided');
|
||||
}
|
||||
@ -32,39 +33,51 @@ class HttpProxy implements \danog\MadelineProto\Proxy
|
||||
$this->type = $type;
|
||||
$this->protocol = $protocol;
|
||||
}
|
||||
public function setExtra(array $extra = []) {
|
||||
|
||||
public function setExtra(array $extra = [])
|
||||
{
|
||||
$this->extra = $extra;
|
||||
$name = $this->protocol === PHP_INT_MAX ? '\\FSocket' : '\\Socket';
|
||||
$this->sock = new $name(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, $this->protocol);
|
||||
}
|
||||
public function setOption($level, $name, $value) {
|
||||
|
||||
public function setOption($level, $name, $value)
|
||||
{
|
||||
return $this->sock->setOption($level, $name, $value);
|
||||
}
|
||||
|
||||
public function getOption($level, $name) {
|
||||
public function getOption($level, $name)
|
||||
{
|
||||
return $this->sock->getOption($level, $name);
|
||||
}
|
||||
|
||||
public function setBlocking($blocking) {
|
||||
public function setBlocking($blocking)
|
||||
{
|
||||
return $this->sock->setBlocking($blocking);
|
||||
}
|
||||
|
||||
public function bind($address, $port = 0) {
|
||||
public function bind($address, $port = 0)
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
|
||||
public function listen($backlog = 0) {
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
public function accept() {
|
||||
public function listen($backlog = 0)
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
|
||||
|
||||
public function select(array &$read, array &$write, array &$except, $tv_sec, $tv_usec = 0) {
|
||||
public function accept()
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
public function connect($address, $port = 0) {
|
||||
|
||||
public function select(array &$read, array &$write, array &$except, $tv_sec, $tv_usec = 0)
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
|
||||
public function connect($address, $port = 0)
|
||||
{
|
||||
$this->sock->connect($this->extra['address'], $this->extra['port']);
|
||||
|
||||
try {
|
||||
@ -77,12 +90,16 @@ class HttpProxy implements \danog\MadelineProto\Proxy
|
||||
$response = $this->read_http_payload();
|
||||
if ($response['code'] !== 200) {
|
||||
\danog\MadelineProto\Logger::log(trim($response['body']));
|
||||
|
||||
throw new \danog\MadelineProto\Exception($response['description'], $response['code']);
|
||||
}
|
||||
\danog\MadelineProto\Logger::log('Connected to '.$address.':'.$port.' via http');
|
||||
|
||||
return true;
|
||||
}
|
||||
private function http_read($length) {
|
||||
|
||||
private function http_read($length)
|
||||
{
|
||||
$packet = '';
|
||||
while (strlen($packet) < $length) {
|
||||
$packet .= $this->sock->read($length - strlen($packet));
|
||||
@ -90,8 +107,10 @@ class HttpProxy implements \danog\MadelineProto\Proxy
|
||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
||||
}
|
||||
}
|
||||
|
||||
return $packet;
|
||||
}
|
||||
|
||||
public function read_http_line()
|
||||
{
|
||||
$line = '';
|
||||
@ -128,34 +147,42 @@ class HttpProxy implements \danog\MadelineProto\Proxy
|
||||
return ['protocol' => $protocol, 'code' => $code, 'description' => $description, 'body' => $read, 'headers' => $headers];
|
||||
}
|
||||
|
||||
public function read($length, $flags = 0) {
|
||||
public function read($length, $flags = 0)
|
||||
{
|
||||
$read = $this->sock->read($length, $flags);
|
||||
if ($read === 0) {
|
||||
throw new \danog\MadelineProto\Exception('pls reconnect');
|
||||
}
|
||||
|
||||
return $read;
|
||||
}
|
||||
|
||||
public function write($buffer, $length = -1) {
|
||||
public function write($buffer, $length = -1)
|
||||
{
|
||||
return $this->sock->write($buffer, $length);
|
||||
}
|
||||
|
||||
public function send($data, $length, $flags) {
|
||||
public function send($data, $length, $flags)
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
|
||||
public function close() {
|
||||
public function close()
|
||||
{
|
||||
$this->sock->close();
|
||||
}
|
||||
|
||||
public function getPeerName($port = true) {
|
||||
public function getPeerName($port = true)
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
|
||||
public function getSockName($port = true) {
|
||||
public function getSockName($port = true)
|
||||
{
|
||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||
}
|
||||
public function getProxyHeaders() {
|
||||
|
||||
public function getProxyHeaders()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ class API extends APIFactory
|
||||
if (isset($unserialized->API)) {
|
||||
$this->API = $unserialized->API;
|
||||
$this->APIFactory();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -178,6 +179,7 @@ class API extends APIFactory
|
||||
if (is_null($this->session)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return Serialization::serialize($params, $this);
|
||||
}
|
||||
}
|
||||
|
@ -572,6 +572,7 @@ Any json-encodable data.
|
||||
');
|
||||
\danog\MadelineProto\Logger::log('Done!', \danog\MadelineProto\Logger::NOTICE);
|
||||
}
|
||||
|
||||
public $template = '<?php
|
||||
/*
|
||||
Copyright 2016-2018 Daniil Gentili
|
||||
@ -594,11 +595,11 @@ class Lang
|
||||
public static $current_lang = %s;
|
||||
}';
|
||||
|
||||
public function add_to_lang($key) {
|
||||
public function add_to_lang($key)
|
||||
{
|
||||
if (!isset(\danog\MadelineProto\Lang::$lang['en'][$key])) {
|
||||
\danog\MadelineProto\Lang::$lang['en'][$key] = '';
|
||||
file_put_contents(__DIR__.'/Lang.php', sprintf($this->template, var_export(\danog\MadelineProto\Lang::$lang, true), var_export(\danog\MadelineProto\Lang::$lang['en'], true)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,14 @@ namespace danog\MadelineProto;
|
||||
|
||||
class EventHandler extends APIFactory
|
||||
{
|
||||
public function __construct($MadelineProto) {
|
||||
public function __construct($MadelineProto)
|
||||
{
|
||||
$this->API = $MadelineProto;
|
||||
foreach ($this->API->get_method_namespaces() as $namespace) {
|
||||
$this->{$namespace} = new APIFactory($namespace, $this->API);
|
||||
}
|
||||
}
|
||||
|
||||
public function &__get($name)
|
||||
{
|
||||
if ($name === 'settings') {
|
||||
|
@ -17,14 +17,20 @@ class FileCallback implements FileCallbackInterface
|
||||
{
|
||||
private $file;
|
||||
private $callback;
|
||||
public function __construct($file, $callback) {
|
||||
|
||||
public function __construct($file, $callback)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
public function getFile() {
|
||||
|
||||
public function getFile()
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
public function __invoke($percent) {
|
||||
|
||||
public function __invoke($percent)
|
||||
{
|
||||
$this->callback($percent);
|
||||
}
|
||||
}
|
||||
|
@ -16,5 +16,6 @@ namespace danog\MadelineProto;
|
||||
interface FileCallbackInterface
|
||||
{
|
||||
public function getFile();
|
||||
|
||||
public function __invoke($percent);
|
||||
}
|
||||
|
@ -130,7 +130,11 @@ class Logger
|
||||
}
|
||||
if (!is_string($param)) {
|
||||
$parame = json_encode($param, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
if ($parame == '') $param = var_export($param, true); else $param = $parame;
|
||||
if ($parame == '') {
|
||||
$param = var_export($param, true);
|
||||
} else {
|
||||
$param = $parame;
|
||||
}
|
||||
}
|
||||
$param = str_pad(basename(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]['file'], '.php').$prefix.': ', 16 + strlen($prefix))."\t".$param;
|
||||
/*if (self::$isatty) {
|
||||
|
@ -108,6 +108,7 @@ class MTProto
|
||||
private $postpone_pwrchat = false;
|
||||
private $pending_pwrchat = [];
|
||||
private $altervista = false;
|
||||
|
||||
public function __magic_construct($settings = [])
|
||||
{
|
||||
// Parse settings
|
||||
@ -534,7 +535,7 @@ class MTProto
|
||||
// Should I use threading, if it is enabled?
|
||||
'handler_workers' => 10,
|
||||
], 'upload' => [
|
||||
'allow_automatic_upload' => true
|
||||
'allow_automatic_upload' => true,
|
||||
], 'pwr' => [
|
||||
'pwr' => false,
|
||||
// Need info ?
|
||||
@ -575,7 +576,9 @@ class MTProto
|
||||
break;
|
||||
}
|
||||
$this->settings = $settings;
|
||||
if (!$this->settings['updates']['handle_updates']) $this->updates = [];
|
||||
if (!$this->settings['updates']['handle_updates']) {
|
||||
$this->updates = [];
|
||||
}
|
||||
// Setup logger
|
||||
$this->setup_logger();
|
||||
}
|
||||
@ -713,6 +716,7 @@ class MTProto
|
||||
$this->authorization = ['user' => $this->method_call('users.getUsers', ['id' => [['_' => 'inputUserSelf']]], ['datacenter' => $this->datacenter->curdc])[0]];
|
||||
} catch (RPCErrorException $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,9 @@ trait CallHandler
|
||||
$only_updates = false;
|
||||
if ($last_recv === $this->datacenter->sockets[$aargs['datacenter']]->last_recv) { // the socket is dead, resend request
|
||||
$this->close_and_reopen($aargs['datacenter']);
|
||||
if ($this->altervista) continue 2;
|
||||
if ($this->altervista) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
//if ($this->datacenter->sockets[$aargs['datacenter']]->last_recv < time() - 1 && $this->is_http($aargs['datacenter'])) {
|
||||
// $this->close_and_reopen($aargs['datacenter']);
|
||||
|
@ -87,7 +87,9 @@ trait Files
|
||||
{
|
||||
return $this->upload($file, $file_name, $cb, true);
|
||||
}
|
||||
public function gen_all_file($media) {
|
||||
|
||||
public function gen_all_file($media)
|
||||
{
|
||||
$res = [$this->constructors->find_by_predicate($media['_'])['type'] => $media];
|
||||
switch ($media['_']) {
|
||||
case 'messageMediaPhoto':
|
||||
@ -131,10 +133,12 @@ trait Files
|
||||
default:
|
||||
throw new \danog\MadelineProto\Exception('Could not convert media object');
|
||||
}
|
||||
return $res;
|
||||
|
||||
return $res;
|
||||
}
|
||||
public function get_file_info($constructor) {
|
||||
|
||||
public function get_file_info($constructor)
|
||||
{
|
||||
if (is_string($constructor)) {
|
||||
$constructor = $this->unpack_file_id($constructor)['MessageMedia'];
|
||||
}
|
||||
@ -146,8 +150,10 @@ trait Files
|
||||
case 'message':
|
||||
$constructor = $constructor['media'];
|
||||
}
|
||||
|
||||
return $this->gen_all_file($constructor);
|
||||
}
|
||||
|
||||
public function get_download_info($message_media)
|
||||
{
|
||||
if (is_string($message_media)) {
|
||||
|
@ -267,6 +267,7 @@ trait PeerHandler
|
||||
if (!isset($this->secret_chats[$id])) {
|
||||
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['sec_peer_not_in_db']);
|
||||
}
|
||||
|
||||
return $this->secret_chats[$id];
|
||||
case 'updateNewMessage':
|
||||
case 'updateNewChannelMessage':
|
||||
@ -753,6 +754,7 @@ trait PeerHandler
|
||||
if (strpos($e->rpc, 'FLOOD_WAIT_') === 0 || $e->rpc === 'AUTH_KEY_UNREGISTERED' || $e->rpc === 'USERNAME_INVALID') {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($res['_'] === 'contacts.resolvedPeer') {
|
||||
|
@ -13,35 +13,37 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
/**
|
||||
* Wrapper for my.telegram.org
|
||||
* Wrapper for my.telegram.org.
|
||||
*/
|
||||
class MyTelegramOrgWrapper
|
||||
{
|
||||
private $logged = false;
|
||||
public function __construct($number) {
|
||||
|
||||
public function __construct($number)
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new Exception(['extension', 'curl']);
|
||||
}
|
||||
$this->number = $number;
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, "https://my.telegram.org/auth/send_password");
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://my.telegram.org/auth/send_password');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(["phone" => $number]));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['phone' => $number]));
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||
|
||||
$headers = array();
|
||||
$headers[] = "Origin: https://my.telegram.org";
|
||||
$headers[] = "Accept-Encoding: gzip, deflate, br";
|
||||
$headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
|
||||
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
|
||||
$headers[] = "Content-Type: application/x-www-form-urlencoded; charset=UTF-8";
|
||||
$headers[] = "Accept: application/json, text/javascript, */*; q=0.01";
|
||||
$headers[] = "Referer: https://my.telegram.org/auth";
|
||||
$headers[] = "X-Requested-With: XMLHttpRequest";
|
||||
$headers[] = "Connection: keep-alive";
|
||||
$headers[] = "Dnt: 1";
|
||||
$headers = [];
|
||||
$headers[] = 'Origin: https://my.telegram.org';
|
||||
$headers[] = 'Accept-Encoding: gzip, deflate, br';
|
||||
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
||||
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
|
||||
$headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
|
||||
$headers[] = 'Referer: https://my.telegram.org/auth';
|
||||
$headers[] = 'X-Requested-With: XMLHttpRequest';
|
||||
$headers[] = 'Connection: keep-alive';
|
||||
$headers[] = 'Dnt: 1';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
@ -50,30 +52,36 @@ class MyTelegramOrgWrapper
|
||||
}
|
||||
curl_close($ch);
|
||||
$resulta = json_decode($result, true);
|
||||
if (!isset($resulta['random_hash'])) throw new Exception($result);
|
||||
$this->hash = $resulta["random_hash"];
|
||||
if (!isset($resulta['random_hash'])) {
|
||||
throw new Exception($result);
|
||||
}
|
||||
$this->hash = $resulta['random_hash'];
|
||||
}
|
||||
|
||||
public function complete_login($password)
|
||||
{
|
||||
if ($this->logged) {
|
||||
throw new Exception('Already logged in!');
|
||||
}
|
||||
public function complete_login($password) {
|
||||
if ($this->logged) throw new Exception('Already logged in!');
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, "https://my.telegram.org/auth/login");
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://my.telegram.org/auth/login');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(["phone" => $this->number, "random_hash" => $this->hash, "password" => $password]));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['phone' => $this->number, 'random_hash' => $this->hash, 'password' => $password]));
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||
|
||||
$headers = array();
|
||||
$headers[] = "Origin: https://my.telegram.org";
|
||||
$headers[] = "Accept-Encoding: gzip, deflate, br";
|
||||
$headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
|
||||
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
|
||||
$headers[] = "Content-Type: application/x-www-form-urlencoded; charset=UTF-8";
|
||||
$headers[] = "Accept: application/json, text/javascript, */*; q=0.01";
|
||||
$headers[] = "Referer: https://my.telegram.org/auth";
|
||||
$headers[] = "X-Requested-With: XMLHttpRequest";
|
||||
$headers[] = "Connection: keep-alive";
|
||||
$headers[] = "Dnt: 1";
|
||||
$headers = [];
|
||||
$headers[] = 'Origin: https://my.telegram.org';
|
||||
$headers[] = 'Accept-Encoding: gzip, deflate, br';
|
||||
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
||||
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
|
||||
$headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
|
||||
$headers[] = 'Referer: https://my.telegram.org/auth';
|
||||
$headers[] = 'X-Requested-With: XMLHttpRequest';
|
||||
$headers[] = 'Connection: keep-alive';
|
||||
$headers[] = 'Dnt: 1';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
|
||||
@ -93,28 +101,37 @@ class MyTelegramOrgWrapper
|
||||
default:
|
||||
throw new Exception($response_content);
|
||||
}
|
||||
$this->token = explode(";", explode("stel_token=", $response_headers)[1])[0];
|
||||
$this->token = explode(';', explode('stel_token=', $response_headers)[1])[0];
|
||||
|
||||
return $this->logged = true;
|
||||
}
|
||||
public function logged_in() { return $this->logged; }
|
||||
public function has_app() {
|
||||
if (!$this->logged) throw new Exception('Not logged in!');
|
||||
|
||||
public function logged_in()
|
||||
{
|
||||
return $this->logged;
|
||||
}
|
||||
|
||||
public function has_app()
|
||||
{
|
||||
if (!$this->logged) {
|
||||
throw new Exception('Not logged in!');
|
||||
}
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, "https://my.telegram.org/apps");
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://my.telegram.org/apps');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||
$headers = array();
|
||||
$headers[] = "Dnt: 1";
|
||||
$headers[] = "Accept-Encoding: gzip, deflate, sdch, br";
|
||||
$headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
|
||||
$headers[] = "Upgrade-Insecure-Requests: 1";
|
||||
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
|
||||
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
|
||||
$headers[] = "Referer: https://my.telegram.org/";
|
||||
$headers[] = "Cookie: stel_token=".$this->token;
|
||||
$headers[] = "Connection: keep-alive";
|
||||
$headers[] = "Cache-Control: max-age=0";
|
||||
$headers = [];
|
||||
$headers[] = 'Dnt: 1';
|
||||
$headers[] = 'Accept-Encoding: gzip, deflate, sdch, br';
|
||||
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
||||
$headers[] = 'Upgrade-Insecure-Requests: 1';
|
||||
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
||||
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
|
||||
$headers[] = 'Referer: https://my.telegram.org/';
|
||||
$headers[] = 'Cookie: stel_token='.$this->token;
|
||||
$headers[] = 'Connection: keep-alive';
|
||||
$headers[] = 'Cache-Control: max-age=0';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
@ -124,28 +141,35 @@ class MyTelegramOrgWrapper
|
||||
$title = explode('</title>', explode('<title>', $result)[1])[0];
|
||||
switch ($title) {
|
||||
case 'App configuration': return true;
|
||||
case 'Create new application': $this->creation_hash = explode('"/>', explode('<input type="hidden" name="hash" value="', $result)[1])[0]; return false;
|
||||
case 'Create new application': $this->creation_hash = explode('"/>', explode('<input type="hidden" name="hash" value="', $result)[1])[0];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new Exception($title);
|
||||
}
|
||||
public function get_app() {
|
||||
if (!$this->logged) throw new Exception('Not logged in!');
|
||||
|
||||
public function get_app()
|
||||
{
|
||||
if (!$this->logged) {
|
||||
throw new Exception('Not logged in!');
|
||||
}
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, "https://my.telegram.org/apps");
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://my.telegram.org/apps');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||
$headers = array();
|
||||
$headers[] = "Dnt: 1";
|
||||
$headers[] = "Accept-Encoding: gzip, deflate, sdch, br";
|
||||
$headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
|
||||
$headers[] = "Upgrade-Insecure-Requests: 1";
|
||||
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
|
||||
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
|
||||
$headers[] = "Referer: https://my.telegram.org/";
|
||||
$headers[] = "Cookie: stel_token=".$this->token;
|
||||
$headers[] = "Connection: keep-alive";
|
||||
$headers[] = "Cache-Control: max-age=0";
|
||||
$headers = [];
|
||||
$headers[] = 'Dnt: 1';
|
||||
$headers[] = 'Accept-Encoding: gzip, deflate, sdch, br';
|
||||
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
||||
$headers[] = 'Upgrade-Insecure-Requests: 1';
|
||||
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
||||
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
|
||||
$headers[] = 'Referer: https://my.telegram.org/';
|
||||
$headers[] = 'Cookie: stel_token='.$this->token;
|
||||
$headers[] = 'Connection: keep-alive';
|
||||
$headers[] = 'Cache-Control: max-age=0';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
@ -156,38 +180,45 @@ class MyTelegramOrgWrapper
|
||||
$cose = explode('<label for="app_id" class="col-md-4 text-right control-label">App api_id:</label>
|
||||
<div class="col-md-7">
|
||||
<span class="form-control input-xlarge uneditable-input" onclick="this.select();"><strong>', $result);
|
||||
$asd = explode("</strong></span>", $cose["1"]);
|
||||
$api_id = $asd["0"];
|
||||
$asd = explode('</strong></span>', $cose['1']);
|
||||
$api_id = $asd['0'];
|
||||
$cose = explode('<label for="app_hash" class="col-md-4 text-right control-label">App api_hash:</label>
|
||||
<div class="col-md-7">
|
||||
<span class="form-control input-xlarge uneditable-input" onclick="this.select();">', $result);
|
||||
$asd = explode("</span>", $cose["1"]);
|
||||
$api_hash = $asd["0"];
|
||||
$asd = explode('</span>', $cose['1']);
|
||||
$api_hash = $asd['0'];
|
||||
|
||||
return ['api_id' => (int) $api_id, 'api_hash' => $api_hash];
|
||||
}
|
||||
public function create_app($settings) {
|
||||
if (!$this->logged) throw new Exception('Not logged in!');
|
||||
if ($this->has_app()) throw new Exception('The app was already created!');
|
||||
|
||||
public function create_app($settings)
|
||||
{
|
||||
if (!$this->logged) {
|
||||
throw new Exception('Not logged in!');
|
||||
}
|
||||
if ($this->has_app()) {
|
||||
throw new Exception('The app was already created!');
|
||||
}
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, "https://my.telegram.org/apps/create");
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://my.telegram.org/apps/create');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(["hash" => $this->creation_hash, "app_title" => $settings['app_title'], "app_shortname" => $settings['app_shortname'], "app_url" => $settings['app_url'], 'app_platform' => $settings['app_platform'], 'app_desc' => $settings['app_desc']]));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['hash' => $this->creation_hash, 'app_title' => $settings['app_title'], 'app_shortname' => $settings['app_shortname'], 'app_url' => $settings['app_url'], 'app_platform' => $settings['app_platform'], 'app_desc' => $settings['app_desc']]));
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||
|
||||
$headers = array();
|
||||
$headers = [];
|
||||
$headers[] = "Cookie: stel_token=$token";
|
||||
$headers[] = "Origin: https://my.telegram.org";
|
||||
$headers[] = "Accept-Encoding: gzip, deflate, br";
|
||||
$headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
|
||||
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
|
||||
$headers[] = "Content-Type: application/x-www-form-urlencoded; charset=UTF-8";
|
||||
$headers[] = "Accept: */*";
|
||||
$headers[] = "Referer: https://my.telegram.org/apps";
|
||||
$headers[] = "X-Requested-With: XMLHttpRequest";
|
||||
$headers[] = "Connection: keep-alive";
|
||||
$headers[] = "Dnt: 1";
|
||||
$headers[] = 'Origin: https://my.telegram.org';
|
||||
$headers[] = 'Accept-Encoding: gzip, deflate, br';
|
||||
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
||||
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
|
||||
$headers[] = 'Accept: */*';
|
||||
$headers[] = 'Referer: https://my.telegram.org/apps';
|
||||
$headers[] = 'X-Requested-With: XMLHttpRequest';
|
||||
$headers[] = 'Connection: keep-alive';
|
||||
$headers[] = 'Dnt: 1';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
@ -198,23 +229,23 @@ class MyTelegramOrgWrapper
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, "https://my.telegram.org/apps");
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://my.telegram.org/apps');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||
|
||||
$headers = array();
|
||||
$headers[] = "Dnt: 1";
|
||||
$headers[] = "Accept-Encoding: gzip, deflate, sdch, br";
|
||||
$headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
|
||||
$headers[] = "Upgrade-Insecure-Requests: 1";
|
||||
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
|
||||
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
|
||||
$headers[] = "Referer: https://my.telegram.org/";
|
||||
$headers = [];
|
||||
$headers[] = 'Dnt: 1';
|
||||
$headers[] = 'Accept-Encoding: gzip, deflate, sdch, br';
|
||||
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
||||
$headers[] = 'Upgrade-Insecure-Requests: 1';
|
||||
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
||||
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
|
||||
$headers[] = 'Referer: https://my.telegram.org/';
|
||||
$headers[] = "Cookie: stel_token=$token";
|
||||
$headers[] = "Connection: keep-alive";
|
||||
$headers[] = "Cache-Control: max-age=0";
|
||||
$headers[] = 'Connection: keep-alive';
|
||||
$headers[] = 'Cache-Control: max-age=0';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
@ -226,13 +257,12 @@ class MyTelegramOrgWrapper
|
||||
$cose = explode('<label for="app_id" class="col-md-4 text-right control-label">App api_id:</label>
|
||||
<div class="col-md-7">
|
||||
<span class="form-control input-xlarge uneditable-input" onclick="this.select();"><strong>', $result);
|
||||
$asd = explode("</strong></span>", $cose["1"]);
|
||||
$api_id = $asd["0"];
|
||||
$asd = explode('</strong></span>', $cose['1']);
|
||||
$api_id = $asd['0'];
|
||||
$cose = explode('<label for="app_hash" class="col-md-4 text-right control-label">App api_hash:</label>
|
||||
<div class="col-md-7">
|
||||
<span class="form-control input-xlarge uneditable-input" onclick="this.select();">', $result);
|
||||
$asd = explode("</span>", $cose["1"]);
|
||||
$api_hash = $asd["0"];
|
||||
$asd = explode('</span>', $cose['1']);
|
||||
$api_hash = $asd['0'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class Serialization
|
||||
return $wrote;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Deserialize API class.
|
||||
*
|
||||
* @param string $filename
|
||||
|
@ -17,7 +17,8 @@ namespace danog\MadelineProto;
|
||||
*/
|
||||
trait Tools
|
||||
{
|
||||
public function gen_vector_hash($ints) {
|
||||
public function gen_vector_hash($ints)
|
||||
{
|
||||
if (\danog\MadelineProto\Logger::$bigint) {
|
||||
$hash = new \phpseclib\Math\BigInteger(0);
|
||||
foreach ($ints as $int) {
|
||||
@ -30,8 +31,10 @@ trait Tools
|
||||
$hash = (($hash * 20261) + 0x80000000 + $int) % 0x80000000;
|
||||
}
|
||||
}
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
public function random($length)
|
||||
{
|
||||
return $length === 0 ? '' : \phpseclib\Crypt\Random::string($length);
|
||||
|
@ -44,6 +44,7 @@ trait ApiStart
|
||||
4) Click on create application'.PHP_EOL;
|
||||
$app['api_id'] = readline('5) Enter your API ID: ');
|
||||
$app['api_hash'] = readline('6) Enter your API hash: ');
|
||||
|
||||
return $app;
|
||||
} else {
|
||||
$this->my_telegram_org_wrapper = new \danog\MadelineProto\MyTelegramOrgWrapper(readline('Enter a phone number that is already registered on Telegram: '));
|
||||
@ -53,6 +54,7 @@ trait ApiStart
|
||||
} else {
|
||||
$app = $this->my_telegram_org_wrapper->get_app();
|
||||
}
|
||||
|
||||
return $app;
|
||||
}
|
||||
} else {
|
||||
@ -62,6 +64,7 @@ trait ApiStart
|
||||
$app['api_id'] = (int) $_POST['api_id'];
|
||||
$app['api_hash'] = $_POST['api_hash'];
|
||||
$this->getting_api_id = false;
|
||||
|
||||
return $app;
|
||||
} elseif (isset($_POST['phone_number'])) {
|
||||
$this->web_api_phone_login();
|
||||
@ -72,6 +75,7 @@ trait ApiStart
|
||||
if (isset($_POST['code'])) {
|
||||
$app = $this->web_api_complete_login();
|
||||
$this->getting_api_id = false;
|
||||
|
||||
return $app;
|
||||
} else {
|
||||
$this->web_api_echo("You didn't provide a phone code!");
|
||||
@ -80,6 +84,7 @@ trait ApiStart
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function web_api_phone_login()
|
||||
{
|
||||
try {
|
||||
@ -101,6 +106,7 @@ trait ApiStart
|
||||
} else {
|
||||
$app = $this->my_telegram_org_wrapper->get_app();
|
||||
}
|
||||
|
||||
return $app;
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
$this->web_api_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||
|
@ -34,14 +34,17 @@ trait ApiTemplates
|
||||
{
|
||||
return sprintf($this->web_api_template, $form, $message);
|
||||
}
|
||||
public function get_web_api_template() {
|
||||
|
||||
public function get_web_api_template()
|
||||
{
|
||||
return $this->web_template;
|
||||
}
|
||||
public function set_web_api_template($template) {
|
||||
|
||||
public function set_web_api_template($template)
|
||||
{
|
||||
$this->web_template = $template;
|
||||
}
|
||||
|
||||
|
||||
public function web_api_echo($message = '')
|
||||
{
|
||||
if (!isset($this->my_telegram_org_wrapper)) {
|
||||
@ -58,5 +61,4 @@ trait ApiTemplates
|
||||
echo $this->web_api_echo_template('Enter your code<br><b>'.$message.'</b>', '<input type="text" name="code" placeholder="Code" required/>');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ namespace danog\MadelineProto\Wrappers;
|
||||
*/
|
||||
trait Callback
|
||||
{
|
||||
public function setCallback($callback) {
|
||||
public function setCallback($callback)
|
||||
{
|
||||
$this->settings['updates']['callback'] = $callback;
|
||||
$this->settings['updates']['handle_updates'] = true;
|
||||
}
|
||||
|
@ -21,13 +21,15 @@ trait Events
|
||||
public $event_handler;
|
||||
private $event_handler_instance;
|
||||
|
||||
public function setEventHandler($event_handler) {
|
||||
public function setEventHandler($event_handler)
|
||||
{
|
||||
$this->event_handler = $event_handler;
|
||||
$this->settings['updates']['callback'] = [$this, 'event_update_handler'];
|
||||
$this->settings['updates']['handle_updates'] = true;
|
||||
}
|
||||
|
||||
public function event_update_handler($update) {
|
||||
public function event_update_handler($update)
|
||||
{
|
||||
if (!class_exists($this->event_handler) || !is_subclass_of($this->event_handler, '\danog\MadelineProto\EventHandler')) {
|
||||
throw new \danog\MadelineProto\Exception('Wrong event handler was defined');
|
||||
}
|
||||
|
@ -23,18 +23,18 @@ trait Loop
|
||||
if (in_array($this->settings['updates']['callback'], [['danog\\MadelineProto\\API', 'get_updates_update_handler'], 'get_updates_update_handler'])) {
|
||||
return true;
|
||||
}
|
||||
if (php_sapi_name() !== "cli") {
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
try {
|
||||
set_time_limit(-1);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
register_shutdown_function(function () {
|
||||
\danog\MadelineProto\Logger::log(['Restarting script...']);
|
||||
$a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
|
||||
fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n"."Host: ".$_SERVER['SERVER_NAME']."\r\n\r\n");
|
||||
fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n");
|
||||
});
|
||||
}
|
||||
}
|
||||
\danog\MadelineProto\Logger::log("Started update loop", \danog\MadelineProto\Logger::NOTICE);
|
||||
\danog\MadelineProto\Logger::log('Started update loop', \danog\MadelineProto\Logger::NOTICE);
|
||||
$offset = 0;
|
||||
if ($max_forks === -1) {
|
||||
while (true) {
|
||||
|
@ -88,7 +88,6 @@ trait Start
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function web_phone_login()
|
||||
{
|
||||
try {
|
||||
@ -148,5 +147,4 @@ trait Start
|
||||
$this->web_echo('ERROR: '.$e->getMessage().'. Try again.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ trait Templates
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private $web_template = '<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -62,10 +63,14 @@ trait Templates
|
||||
{
|
||||
return sprintf($this->web_template, $form, $message);
|
||||
}
|
||||
public function get_web_template() {
|
||||
|
||||
public function get_web_template()
|
||||
{
|
||||
return $this->web_template;
|
||||
}
|
||||
public function set_web_template($template) {
|
||||
|
||||
public function set_web_template($template)
|
||||
{
|
||||
$this->web_template = $template;
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ namespace danog\MadelineProto\Wrappers;
|
||||
*/
|
||||
trait Webhook
|
||||
{
|
||||
|
||||
public function setWebhook($hook_url, $pem_path = null) {
|
||||
public function setWebhook($hook_url, $pem_path = null)
|
||||
{
|
||||
$this->pem_path = $pem_path;
|
||||
$this->hook_url = $hook_url;
|
||||
$this->settings['updates']['callback'] = [$this, 'pwr_webhook'];
|
||||
|
@ -12,7 +12,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Various ways to load MadelineProto
|
||||
* Various ways to load MadelineProto.
|
||||
*/
|
||||
if (!file_exists(__DIR__.'/../vendor/autoload.php')) {
|
||||
echo 'You did not run composer update, using madeline.php'.PHP_EOL;
|
||||
@ -24,7 +24,7 @@ if (!file_exists(__DIR__.'/../vendor/autoload.php')) {
|
||||
require_once 'vendor/autoload.php';
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Load .env for settings
|
||||
*/
|
||||
if (file_exists('.env')) {
|
||||
@ -38,10 +38,11 @@ if (getenv('TEST_SECRET_CHAT') == '') {
|
||||
echo 'Loading settings...'.PHP_EOL;
|
||||
$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
|
||||
|
||||
/**
|
||||
/*
|
||||
* Load MadelineProto
|
||||
*/
|
||||
echo 'Loading MadelineProto...'.PHP_EOL;
|
||||
|
||||
try {
|
||||
$MadelineProto = new \danog\MadelineProto\API(getcwd().'/testing.madeline', $settings);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
@ -50,11 +51,11 @@ try {
|
||||
$MadelineProto = new \danog\MadelineProto\API(getcwd().'/testing.madeline', $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* If this session is not logged in, login
|
||||
*/
|
||||
if ($MadelineProto->get_self() === false) {
|
||||
/**
|
||||
/*
|
||||
* If a BOT_TOKEN is defined in .env, use it to login, else prompt for login info
|
||||
*/
|
||||
if (getenv('BOT_TOKEN') == '') {
|
||||
@ -64,7 +65,7 @@ if ($MadelineProto->get_self() === false) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Test logging
|
||||
*/
|
||||
\danog\MadelineProto\Logger::log('hey', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
@ -75,11 +76,11 @@ if ($MadelineProto->get_self() === false) {
|
||||
\danog\MadelineProto\Logger::log('hey', \danog\MadelineProto\Logger::FATAL_ERROR);
|
||||
|
||||
/**
|
||||
* A small example message to use for tests
|
||||
* A small example message to use for tests.
|
||||
*/
|
||||
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
|
||||
|
||||
/**
|
||||
/*
|
||||
* Try making a phone call
|
||||
*/
|
||||
if (stripos(readline('Do you want to make a call? (y/n): '), 'y') !== false) {
|
||||
@ -93,7 +94,7 @@ if (stripos(readline('Do you want to make a call? (y/n): '), 'y') !== false) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Try receiving a phone call
|
||||
*/
|
||||
if (stripos(readline('Do you want to handle incoming calls? (y/n): '), 'y') !== false) {
|
||||
@ -115,17 +116,17 @@ if (stripos(readline('Do you want to handle incoming calls? (y/n): '), 'y') !==
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Secret chat usage
|
||||
*/
|
||||
if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y') !== false) {
|
||||
/**
|
||||
* Request a secret chat
|
||||
* Request a secret chat.
|
||||
*/
|
||||
$secret_chat_id = $MadelineProto->API->request_secret_chat(getenv('TEST_SECRET_CHAT'));
|
||||
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' (secret chat id '.$secret_chat_id.') to accept the secret chat...'.PHP_EOL;
|
||||
|
||||
/**
|
||||
/*
|
||||
* Wait until the other party accepts it
|
||||
*/
|
||||
while ($MadelineProto->secret_chat_status($secret_chat_id) !== 2) {
|
||||
@ -133,7 +134,7 @@ if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y')
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a markdown-formatted text message with expiration after 10 seconds
|
||||
* Send a markdown-formatted text message with expiration after 10 seconds.
|
||||
*/
|
||||
$sentMessage = $MadelineProto->messages->sendEncrypted([
|
||||
'peer' => $secret_chat_id,
|
||||
@ -142,13 +143,13 @@ if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y')
|
||||
'media' => ['_' => 'decryptedMessageMediaEmpty'], // No media
|
||||
'ttl' => 10, // This message self-destructs 10 seconds after reception
|
||||
'message' => '```'.$message.'```', // Code Markdown
|
||||
'parse_mode' => 'Markdown'
|
||||
]
|
||||
'parse_mode' => 'Markdown',
|
||||
],
|
||||
]);
|
||||
\danog\MadelineProto\Logger::log($sentMessage, \danog\MadelineProto\Logger::NOTICE);
|
||||
|
||||
/**
|
||||
* Send secret media
|
||||
* Send secret media.
|
||||
*/
|
||||
$secret_media = [];
|
||||
|
||||
@ -170,10 +171,10 @@ if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y')
|
||||
'file_name' => 'faust.jpg', // The file's name
|
||||
'size' => filesize('tests/faust.jpg'), // The file's size
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeImageSize', 'w' => 1280, 'h' => 914] // Image's resolution
|
||||
]
|
||||
]
|
||||
]
|
||||
['_' => 'documentAttributeImageSize', 'w' => 1280, 'h' => 914], // Image's resolution
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Photo, secret chat
|
||||
@ -192,9 +193,9 @@ if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y')
|
||||
'caption' => 'This file was uploaded using @MadelineProto',
|
||||
'size' => filesize('tests/faust.jpg'),
|
||||
'w' => 1280,
|
||||
'h' => 914
|
||||
]
|
||||
]
|
||||
'h' => 914,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// GIF, secret chat
|
||||
|
Loading…
Reference in New Issue
Block a user