Added userbot examples, improved performance of gzip compression
This commit is contained in:
parent
6e368f42be
commit
71f392e2b9
10
README.md
10
README.md
@ -103,7 +103,7 @@ git submodule add https://github.com/danog/MadelineProto
|
||||
cd MadelineProto
|
||||
composer update
|
||||
cp .env.example .env
|
||||
cp -a *php tests bots .env* ..
|
||||
cp -a *php tests userbots .env* ..
|
||||
```
|
||||
|
||||
Now open `.env` and edit its values as needed.
|
||||
@ -115,9 +115,9 @@ You can find examples for nearly every MadelineProto function in
|
||||
* [`tests/testing.php`](https://github.com/danog/MadelineProto/blob/master/tests/testing.php) - examples for making/receiving calls, making secret chats, sending secret chat messages, videos, audios, voice recordings, gifs, stickers, photos, sending normal messages, videos, audios, voice recordings, gifs, stickers, photos.
|
||||
* [`bot.php`](https://github.com/danog/MadelineProto/blob/master/bot.php) - examples for sending normal messages, downloading any media
|
||||
* [`magna.php`](https://github.com/danog/MadelineProto/blob/master/magna.php) - examples for receiving calls
|
||||
* [`bots/pipesbot.php`](https://github.com/danog/MadelineProto/blob/master/bots/pipesbot.php) - examples for creating inline bots and using other inline bots via a userbot
|
||||
* [`bots/MadelineProto_bot.php`](https://github.com/danog/MadelineProto/blob/master/bots/MadelineProto_bot.php) - More fun shiz
|
||||
* [`bots/pwrtelegram_debug_bot`](https://github.com/danog/MadelineProto/blob/master/bots/pwrtelegram_debug_bot.php) - More fun shiz
|
||||
* [`userbots/pipesbot.php`](https://github.com/danog/MadelineProto/blob/master/userbots/pipesbot.php) - examples for creating inline bots and using other inline bots via a userbot
|
||||
* [`userbots/MadelineProto_bot.php`](https://github.com/danog/MadelineProto/blob/master/userbots/MadelineProto_bot.php) - More fun shiz
|
||||
* [`userbots/pwrtelegram_debug_bot`](https://github.com/danog/MadelineProto/blob/master/userbots/pwrtelegram_debug_bot.php) - More fun shiz
|
||||
|
||||
## Methods
|
||||
|
||||
@ -217,7 +217,7 @@ $MadelineProto = new \danog\MadelineProto\API();
|
||||
|
||||
If you have some questions about the usage of the methods of this library, you can join the [support group](https://telegram.me/pwrtelegramgroup) or contact [@danogentili](https://telegram.me/danogentili).
|
||||
|
||||
But first, please read this WHOLE page very carefully, follow all links to external documentation, and read all examples in the repo (bot.php, bots/, tests/testing.php).
|
||||
But first, please read this WHOLE page very carefully, follow all links to external documentation, and read all examples in the repo (bot.php, userbots/, tests/testing.php).
|
||||
|
||||
If you don't understand something, read everything again.
|
||||
|
||||
|
@ -74,11 +74,9 @@ trait CallHandler
|
||||
if (isset($queue)) {
|
||||
$serialized = $this->serialize_method('invokeAfterMsgs', ['msg_ids' => $this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue], 'query' => $serialized]);
|
||||
}
|
||||
$l = strlen($serialized);
|
||||
$g = strlen($gzipped = gzencode($serialized));
|
||||
if ($l > 500 && $g < $l) {
|
||||
\danog\MadelineProto\Logger::log(['Using GZIP compression for '.$method.', saved '.($l - $g).' bytes of data, reduced call size by '.($g * 100 / $l).'%'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
if (($l = strlen($serialized)) > 500 && ($g = strlen($gzipped = gzencode($serialized))) < $l) {
|
||||
$serialized = $this->serialize_object(['type' => 'gzip_packed'], ['packed_data' => $gzipped], 'gzipped data');
|
||||
\danog\MadelineProto\Logger::log(['Using GZIP compression for '.$method.', saved '.($l - $g).' bytes of data, reduced call size by '.($g * 100 / $l).'%'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
}
|
||||
$last_recv = $this->last_recv;
|
||||
if ($canunset = !$this->updates_state['sync_loading'] && !$this->threads && !$this->run_workers) {
|
||||
@ -282,12 +280,14 @@ trait CallHandler
|
||||
if (!isset($aargs['datacenter'])) {
|
||||
throw new \danog\MadelineProto\Exception('No datacenter provided');
|
||||
}
|
||||
$serialized = $this->serialize_object(['type' => $object], $args, $object);
|
||||
|
||||
for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) {
|
||||
try {
|
||||
if ($object !== 'msgs_ack') {
|
||||
\danog\MadelineProto\Logger::log(['Sending object (try number '.$count.' for '.$object.')...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
}
|
||||
$message_id = $this->send_message($this->serialize_object(['type' => $object], $args, $object), $this->content_related($object), $aargs);
|
||||
$message_id = $this->send_message($serialized, $this->content_related($object), $aargs);
|
||||
if ($object !== 'msgs_ack') {
|
||||
$this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]['content'] = ['method' => $object, 'args' => $args];
|
||||
}
|
||||
|
@ -119,7 +119,6 @@ trait MessageHandler
|
||||
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['response'] = -1;
|
||||
$this->datacenter->sockets[$datacenter]->new_incoming[$message_id] = $message_id;
|
||||
$this->last_recv = time();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user