Some bugfixes

This commit is contained in:
Daniil Gentili 2019-07-06 17:45:03 +02:00
parent d5c58af013
commit 3dc3d6e5c8
3 changed files with 63 additions and 44 deletions

View File

@ -39,7 +39,6 @@ class EventHandler extends \danog\MadelineProto\EventHandler
if (isset($update['message']['_']) && $update['message']['_'] === 'messageEmpty') {
return;
}
$res = json_encode($update, JSON_PRETTY_PRINT);
try {

View File

@ -23,6 +23,7 @@ use danog\MadelineProto\Async\AsyncParameters;
use danog\MadelineProto\Exception;
use danog\MadelineProto\Logger;
use danog\MadelineProto\RPCErrorException;
use danog\MadelineProto\Tools;
use function Amp\Promise\all;
/**
@ -331,7 +332,7 @@ trait Files
$res['mime'] = $this->get_mime_from_extension($res['ext'], 'image/jpeg');
}
if (!isset($res['name'])) {
$res['name'] = $message_media['file']['access_hash'];
$res['name'] = Tools::unpack_signed_long_string($message_media['file']['access_hash']);
}
return $res;
@ -401,7 +402,7 @@ trait Files
$res['thumb_size'] = $message_media['type'];
if ($message_media['location']['_'] === 'fileLocationUnavailable') {
$res['name'] = $message_media['volume_id'].'_'.$message_media['local_id'];
$res['name'] = Tools::unpack_signed_long_string($message_media['volume_id']).'_'.$message_media['local_id'];
$res['mime'] = $this->get_mime_from_buffer($res['data']);
$res['ext'] = $this->get_extension_from_mime($res['mime']);
} else {
@ -423,7 +424,7 @@ trait Files
case 'fileLocationUnavailable':
throw new \danog\MadelineProto\Exception('File location unavailable');
case 'fileLocation':
$res['name'] = $message_media['volume_id'].'_'.$message_media['local_id'];
$res['name'] = Tools::unpack_signed_long_string($message_media['volume_id']).'_'.$message_media['local_id'];
$res['InputFileLocation'] = [
'_' => 'inputFileLocation',
'volume_id' => $message_media['volume_id'],
@ -440,7 +441,7 @@ trait Files
return $res;
case 'fileLocationToBeDeprecated':
$res['name'] = $message_media['volume_id'].'_'.$message_media['local_id'];
$res['name'] = Tools::unpack_signed_long_string($message_media['volume_id']).'_'.$message_media['local_id'];
$res['ext'] = '.jpg';
$res['mime'] = $this->get_mime_from_extension($res['ext'], 'image/jpeg');
$res['InputFileLocation'] = [
@ -495,7 +496,7 @@ trait Files
$res['ext'] = $this->get_extension_from_location($res['InputFileLocation'], $this->get_extension_from_mime($message_media['document']['mime_type']));
}
if (!isset($res['name'])) {
$res['name'] = $message_media['document']['access_hash'];
$res['name'] = Tools::unpack_signed_long_string($message_media['document']['access_hash']);
}
if (isset($message_media['document']['size'])) {
$res['size'] = $message_media['document']['size'];
@ -537,7 +538,7 @@ trait Files
$size = fstat($stream)['size'];
$this->logger->logger('Waiting for lock of file to download...');
do {
$res = flock($stream, LOCK_EX|LOCK_NB);
$res = flock($stream, LOCK_EX | LOCK_NB);
if (!$res) {
yield $this->sleep(0.1);
}
@ -606,35 +607,35 @@ trait Files
}
try {
$res = $cdn ?
yield $this->method_call_async_read(
'upload.getCdnFile',
[
'file_token' => $message_media['file_token'],
'offset' => $offset,
'limit' => $part_size
],
[
'heavy' => true,
'file' => true,
'FloodWaitLimit' => 0,
'datacenter' => $datacenter
]
) :
yield $this->method_call_async_read(
'upload.getFile',
[
'location' => $message_media['InputFileLocation'],
'offset' => $offset,
'limit' => $part_size
],
[
'heavy' => true,
'file' => true,
'FloodWaitLimit' => 0,
'datacenter' => &$datacenter
]
);
$res = $cdn ?
yield $this->method_call_async_read(
'upload.getCdnFile',
[
'file_token' => $message_media['file_token'],
'offset' => $offset,
'limit' => $part_size,
],
[
'heavy' => true,
'file' => true,
'FloodWaitLimit' => 0,
'datacenter' => $datacenter,
]
) :
yield $this->method_call_async_read(
'upload.getFile',
[
'location' => $message_media['InputFileLocation'],
'offset' => $offset,
'limit' => $part_size,
],
[
'heavy' => true,
'file' => true,
'FloodWaitLimit' => 0,
'datacenter' => &$datacenter,
]
);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if (strpos($e->rpc, 'FLOOD_WAIT_') === 0) {
if (isset($message_media['MessageMedia']) && !$this->authorization['user']['bot'] && $this->settings['download']['report_broken_media']) {

View File

@ -23,15 +23,16 @@ use Amp\Failure;
use Amp\Loop;
use Amp\Promise;
use Amp\Success;
use function Amp\ByteStream\getOutputBufferStream;
use function Amp\ByteStream\getStdin;
use function Amp\ByteStream\getStdout;
use function Amp\Promise\all;
use function Amp\Promise\any;
use function Amp\Promise\first;
use function Amp\Promise\some;
use function Amp\Promise\timeout;
use function Amp\Promise\wait;
use function Amp\ByteStream\getStdin;
use function Amp\ByteStream\getStdout;
use function Amp\ByteStream\getOutputBufferStream;
use phpseclib\Math\BigInteger;
/**
* Some tools.
@ -119,6 +120,16 @@ trait Tools
return unpack('q', \danog\MadelineProto\Magic::$BIG_ENDIAN ? strrev($value) : $value)[1];
}
public static function unpack_signed_long_string($value)
{
if (strlen($value) !== 8) {
throw new TL\Exception(\danog\MadelineProto\Lang::$current_lang['length_not_8']);
}
$big = new BigInteger($value, -256);
return (string) $big;
}
public static function pack_signed_int($value)
{
if ($value > 2147483647) {
@ -306,12 +317,21 @@ trait Tools
if ($file) {
$file = " started @ $file";
}
if ($logger) $logger->logger("Got the following exception within a forked strand$file, trying to rethrow");
if ($logger) {
$logger->logger("Got the following exception within a forked strand$file, trying to rethrow");
}
if ($e->getMessage() === "Cannot get return value of a generator that hasn't returned") {
$logger->logger("Well you know, this might actually not be the actual exception, scroll up in the logs to see the actual exception");
if (!$zis || !$zis->destructing) Promise\rethrow(new Failure($e));
if (!$zis || !$zis->destructing) {
Promise\rethrow(new Failure($e));
}
} else {
if ($logger) $logger->logger($e);
if ($logger) {
$logger->logger($e);
}
Promise\rethrow(new Failure($e));
}
}
@ -370,8 +390,7 @@ trait Tools
return array_shift($lines);
}
public static function echo($string)
{
public static function echo ($string) {
return getOutputBufferStream()->write($string);
}
public static function is_array_or_alike($var)