Pretty much working

This commit is contained in:
Daniil Gentili 2019-05-30 15:17:26 +02:00
parent 81302f05fd
commit 32aff162e2
5 changed files with 24 additions and 10 deletions

View File

@ -33,13 +33,13 @@ class EventHandler extends \danog\MadelineProto\EventHandler
if (isset($update['message']['out']) && $update['message']['out']) {
return;
}
if ($update['_'] === 'updateReadChannelOutbox') return;
$res = json_encode($update, JSON_PRETTY_PRINT);
if ($res == '') {
$res = var_export($update, true);
}
//yield $this->sleep_async(3);
try {
yield $this->messages->sendMessage(['peer' => $update, 'message' => "<code>$res</code>", 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'parse_mode' => 'HTML']); //'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') {
@ -49,7 +49,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
if (stripos($e->getMessage(), 'invalid constructor given') === false) \danog\MadelineProto\Logger::log((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
//$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
}
}

View File

@ -97,7 +97,9 @@ class FeedLoop extends ResumableSignalLoop
}
$this->parsedUpdates = [];
if ($API->update_deferred) {
Loop::defer([$API->update_deferred, 'resolve']);
$API->logger->logger("Resuming deferred in $this", Logger::VERBOSE);
$API->update_deferred->resolve();
$API->logger->logger("Done resuming deferred in $this", Logger::VERBOSE);
}
}
@ -118,12 +120,13 @@ class FeedLoop extends ResumableSignalLoop
}
if (isset($update['pts'])) {
$logger = function ($msg) use ($update) {
$pts_count = isset($update['pts_count']) ? $update['pts_count'] : 0;
$pts_count = $update['pts_count'];
$this->API->logger->logger($update);
$double = isset($update['message']['id']) ? $update['message']['id'] * 2 : '-';
$mid = isset($update['message']['id']) ? $update['message']['id'] : '-';
$mypts = $this->state->pts();
$this->API->logger->logger("$msg. My pts: {$mypts}, remote pts: {$update['pts']}, remote pts count: {$pts_count}, msg id: {$mid} (*2=$double), channel id: {$this->channelId}", \danog\MadelineProto\Logger::ERROR);
$computed = $mypts + $pts_count;
$this->API->logger->logger("$msg. My pts: {$mypts}, remote pts: {$update['pts']}, computed pts: $computed, msg id: {$mid} (*2=$double), channel id: {$this->channelId}", \danog\MadelineProto\Logger::ERROR);
};
$result = $this->state->checkPts($update);
if ($result < 0) {
@ -149,6 +152,7 @@ class FeedLoop extends ResumableSignalLoop
$logger("PTS OK");
$this->state->pts($update['pts']);
}
$this->save($update);
@ -170,11 +174,11 @@ class FeedLoop extends ResumableSignalLoop
{
$channelId = false;
switch ($update['_']) {
case 'updateChannelWebPage':
case 'updateNewChannelMessage':
case 'updateEditChannelMessage':
$channelId = $update['message']['to_id']['channel_id'];
break;
case 'updateChannelWebPage':
case 'updateDeleteChannelMessages':
$channelId = $update['channel_id'];
break;

View File

@ -81,7 +81,8 @@ class UpdateLoop extends ResumableSignalLoop
} else {
$limit = 100;
}
$difference = yield $this->API->method_call_async_read('updates.getChannelDifference', ['channel' => 'channel#'.$this->channelId, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $state->pts(), 'limit' => $limit, 'force' => true], ['datacenter' => $this->API->datacenter->curdc]);
$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]);
if (isset($difference['timeout'])) {
$timeout = $difference['timeout'];
}
@ -93,9 +94,9 @@ class UpdateLoop extends ResumableSignalLoop
unset($difference);
break 2;
case 'updates.channelDifference':
if ($state->pts() >= $difference['pts'] && $state->pts() > 1) {
if ($request_pts >= $difference['pts'] && $request_pts > 1) {
$this->API->logger->logger("The PTS ({$difference['pts']}) I got with getDifference is smaller than the PTS I requested ".$state->pts().", using ".($state->pts() + 1), \danog\MadelineProto\Logger::VERBOSE);
$difference['pts'] = $state->pts() + 1;
$difference['pts'] = $request_pts + 1;
}
$state->update($difference);
$result += yield $feeder->feed($difference['other_updates']);
@ -162,6 +163,12 @@ class UpdateLoop extends ResumableSignalLoop
foreach ($result as $channelId => $boh) {
$this->API->feeders[$channelId]->resumeDefer();
}
if ($API->update_deferred) {
$API->logger->logger("Resuming deferred in $this", Logger::VERBOSE);
$API->update_deferred->resolve();
$API->logger->logger("Done resuming deferred in $this", Logger::VERBOSE);
}
if (yield $this->waitSignal($this->pause($timeout))) {
$API->logger->logger("Exiting $this");
$this->exitedLoop();

View File

@ -546,6 +546,9 @@ trait ResponseHandler
$botAPI = isset($request['botAPI']) && $request['botAPI'];
unset($request);
$this->got_response_for_outgoing_message_id($request_id, $datacenter);
if (isset($response['_']) && strpos($datacenter, 'cdn') === false && $this->constructors->find_by_predicate($response['_'])['type'] === 'Updates') {
$this->callForkDefer($this->handle_updates_async($response));
}
$r = isset($response['_']) ? $response['_'] : json_encode($response);
$this->logger->logger("Defer sending $r to deferred");
$this->callFork((

View File

@ -191,7 +191,7 @@ class UpdatesState
*/
public function checkPts($update)
{
return ($this->pts + $update['pts_count']) - $update['pts'];
return $update['pts'] - ($this->pts + $update['pts_count']);
}
/**
* Check validity of seq contained in update