Update fixes and get_self improvements
This commit is contained in:
parent
c7ed411070
commit
fa4cf14ab7
@ -1,11 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
|
||||
MadelineProto can now be proxied.
|
||||
## 4.0.0 Full async
|
||||
|
||||
Added `$no_updates` parameter to the deserialize method of `\danog\MadelineProto\Serialization`.
|
||||
Full async
|
||||
|
||||
Improved message splitting algorithm: performance improvements, and it will now notify you via the logs if there are too many entities in the logs, or if the entities are too long.
|
||||
|
||||
## 1.3.1 Release
|
||||
|
||||
Just check the release changelog :D
|
||||
Improved get_self method
|
||||
|
@ -184,7 +184,10 @@ class API extends APIFactory
|
||||
|
||||
return implode('_', $ret);
|
||||
}
|
||||
|
||||
public function my_get_self()
|
||||
{
|
||||
return $this->API->authorization['user'];
|
||||
}
|
||||
public function APIFactory()
|
||||
{
|
||||
if ($this->API) {
|
||||
@ -216,12 +219,12 @@ class API extends APIFactory
|
||||
$method = str_ireplace('async', '', $method);
|
||||
}
|
||||
}
|
||||
|
||||
$this->methods[strtolower($method)] = [$this->API, $actual_method];
|
||||
$actual_method = $actual_method === 'get_self_async' ? [$this, 'my_get_self'] : [$this->API, $actual_method];
|
||||
$this->methods[strtolower($method)] = $actual_method;
|
||||
if (strpos($method, '_') !== false) {
|
||||
$this->methods[strtolower(str_replace('_', '', $method))] = [$this->API, $actual_method];
|
||||
$this->methods[strtolower(str_replace('_', '', $method))] = $actual_method;
|
||||
} else {
|
||||
$this->methods[strtolower($this->from_camel_case($method))] = [$this->API, $actual_method];
|
||||
$this->methods[strtolower($this->from_camel_case($method))] = $actual_method;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ namespace danog\MadelineProto\Loop\Update;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Loop\Impl\ResumableSignalLoop;
|
||||
use Amp\Loop;
|
||||
use danog\MadelineProto\RPCErrorException;
|
||||
|
||||
/**
|
||||
* Update loop.
|
||||
@ -83,7 +84,17 @@ class UpdateLoop extends ResumableSignalLoop
|
||||
$limit = 100;
|
||||
}
|
||||
$request_pts = $state->pts();
|
||||
$difference = yield $this->API->method_call_async_read('updates.getChannelDifference', ['channel' => 'channel#'.$this->channelId, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['datacenter' => $this->API->datacenter->curdc]);
|
||||
try {
|
||||
$difference = yield $this->API->method_call_async_read('updates.getChannelDifference', ['channel' => 'channel#'.$this->channelId, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['datacenter' => $this->API->datacenter->curdc]);
|
||||
} catch (RPCErrorException $e) {
|
||||
if (in_array($e->rpc, ['CHANNEL_PRIVATE', 'CHAT_FORBIDDEN'])) {
|
||||
$feeder->signal(true);
|
||||
$API->logger->logger("Exiting $this");
|
||||
$this->exitedLoop();
|
||||
return true;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
if (isset($difference['timeout'])) {
|
||||
$timeout = $difference['timeout'];
|
||||
}
|
||||
@ -156,6 +167,10 @@ class UpdateLoop extends ResumableSignalLoop
|
||||
}
|
||||
unset($difference);
|
||||
break;
|
||||
case 'updates.differenceTooLong':
|
||||
$state->update($difference);
|
||||
unset($difference);
|
||||
break;
|
||||
default:
|
||||
throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true));
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
namespace danog\MadelineProto\TL\Conversion;
|
||||
|
||||
use danog\MadelineProto\Logger;
|
||||
|
||||
trait BotAPI
|
||||
{
|
||||
public function html_entity_decode($stuff)
|
||||
@ -531,10 +533,10 @@ trait BotAPI
|
||||
$args['entities'] = [];
|
||||
}
|
||||
|
||||
$multiple_args_base = array_merge($args, ['entities' => [], 'parse_mode' => 'text', 'message' => '']);
|
||||
$multiple_args = [$multiple_args_base];
|
||||
|
||||
$max_length = isset($args['media']) ? $this->config['caption_length_max'] : $this->config['message_length_max'];
|
||||
$max_entity_length = 100;
|
||||
$max_entity_size = 8110;
|
||||
|
||||
$text_arr = [];
|
||||
foreach ($this->multipleExplodeKeepDelimiters(["\n"], $args['message']) as $word) {
|
||||
if (mb_strlen($word, 'UTF-8') > $max_length) {
|
||||
@ -545,6 +547,10 @@ trait BotAPI
|
||||
$text_arr[] = $word;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$multiple_args_base = array_merge($args, ['entities' => [], 'parse_mode' => 'text', 'message' => '']);
|
||||
$multiple_args = [$multiple_args_base];
|
||||
$i = 0;
|
||||
foreach ($text_arr as $word) {
|
||||
if ($this->mb_strlen($multiple_args[$i]['message'].$word) <= $max_length) {
|
||||
@ -610,7 +616,24 @@ trait BotAPI
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
foreach ($multiple_args as $args) {
|
||||
if (count($args['entities']) > 100) {
|
||||
$total += count($args['entities']) - 100;
|
||||
}
|
||||
$c = 0;
|
||||
foreach ($args['entities'] as $entity) {
|
||||
if (isset($entity['url'])) {
|
||||
$c += strlen($entity['url']);
|
||||
}
|
||||
}
|
||||
if ($c >= 8110) {
|
||||
$this->logger->logger("Entity size limit possibly exceeded, you may get an error indicating that the entities are too long. Reduce the number of entities and/or size of the URLs used.", Logger::FATAL_ERROR);
|
||||
}
|
||||
}
|
||||
if ($total) {
|
||||
$this->logger->logger("Too many entities, $total entities will be truncated", Logger::FATAL_ERROR);
|
||||
}
|
||||
return $multiple_args;
|
||||
}
|
||||
|
||||
@ -632,7 +655,7 @@ trait BotAPI
|
||||
|
||||
public function html_fixtags($text)
|
||||
{
|
||||
preg_match_all('#(.*?)(<(a|b|\bstrong\b|\bem\b|i|\bcode\b|\bpre\b)[^>]*>)(.*?)(<\s*/\s*\3>)#is', $text, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
|
||||
preg_match_all('#(.*?)(<(a|b|\bstrong\b|\bem\b|i|\bcode\b|\bpre\b)[^>]*>)(.*?)(<\s*/\s*\3>)#is', $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
|
||||
if ($matches) {
|
||||
foreach ($matches as $match) {
|
||||
if (trim($match[1][0]) != '') {
|
||||
@ -645,9 +668,6 @@ trait BotAPI
|
||||
$temp .= htmlentities($match[4][0]);
|
||||
$temp .= substr($text, $match[4][1] + strlen($match[4][0]));
|
||||
$text = $temp;
|
||||
/*if ($match == $matches[$last]) {
|
||||
$text = str_replace($match[6], $this->html_fixtags($match[6]), $text);
|
||||
}*/
|
||||
}
|
||||
preg_match_all('#<a\s*href=("|\')(.+?)("|\')\s*>#is', $text, $matches, PREG_OFFSET_CAPTURE);
|
||||
foreach ($matches[2] as $match) {
|
||||
|
Loading…
Reference in New Issue
Block a user