This commit is contained in:
Daniil Gentili 2017-01-30 12:49:33 +01:00
commit e4c25653c7
6 changed files with 42 additions and 18 deletions

View File

@ -17,6 +17,4 @@ before_script:
script: script:
- "tests/testing.php" - "tests/testing.php"
before_install: before_install:
- openssl aes-256-cbc -K $encrypted_0b05103af24b_key -iv $encrypted_0b05103af24b_iv
-in enc.tar.xz.enc -out enc.tar.xz -d
- tar -xJpf enc.tar.xz - tar -xJpf enc.tar.xz

View File

@ -15,12 +15,14 @@ if (file_exists('token.php') && $MadelineProto === false) {
$offset = 0; $offset = 0;
while (true) { while (true) {
$updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout $updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
var_dump($updates);
foreach ($updates as $update) { foreach ($updates as $update) {
$offset = $update['update_id'] + 1; // Just like in the bot API, the offset must be set to the last update_id $offset = $update['update_id'] + 1; // Just like in the bot API, the offset must be set to the last update_id
var_dump($update); //var_dump($update);
switch ($update['update']['_']) { switch ($update['update']['_']) {
case 'updateNewMessage': case 'updateNewMessage':
if ($update['update']['message']['out']) { case 'updateNewChannelMessage':
if (isset($update['update']['message']['out']) && $update['update']['message']['out']) {
continue; continue;
} }
$res = json_encode($update, JSON_PRETTY_PRINT); $res = json_encode($update, JSON_PRETTY_PRINT);
@ -28,7 +30,8 @@ while (true) {
$res = var_export($update, true); $res = var_export($update, true);
} }
try { try {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); //var_dump($update);
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
} }

View File

@ -25,7 +25,9 @@ class Exception extends \Exception
if (error_reporting() === 0) { if (error_reporting() === 0) {
return true; // return true to continue through the others error handlers return true; // return true to continue through the others error handlers
} }
if (\danog\MadelineProto\Logger::$constructed) \danog\MadelineProto\Logger::log([$errstr], \danog\MadelineProto\Logger::FATAL_ERROR); if (\danog\MadelineProto\Logger::$constructed) {
\danog\MadelineProto\Logger::log([$errstr], \danog\MadelineProto\Logger::FATAL_ERROR);
}
$e = new \danog\MadelineProto\Exception($errstr, $errno); $e = new \danog\MadelineProto\Exception($errstr, $errno);
$e->file = $errfile; $e->file = $errfile;
$e->line = $errline; $e->line = $errline;

View File

@ -66,6 +66,7 @@ trait UpdateHandler
return; return;
} }
$this->updates[$this->updates_key++] = $update; $this->updates[$this->updates_key++] = $update;
$this->should_serialize = true;
//\danog\MadelineProto\Logger::log(['Stored ', $update); //\danog\MadelineProto\Logger::log(['Stored ', $update);
} }
@ -91,8 +92,10 @@ trait UpdateHandler
$params['offset'] = array_reverse(array_keys($this->updates))[abs($params['offset']) - 1]; $params['offset'] = array_reverse(array_keys($this->updates))[abs($params['offset']) - 1];
} }
$updates = []; $updates = [];
ksort($this->updates);
foreach ($this->updates as $key => $value) { foreach ($this->updates as $key => $value) {
if ($params['offset'] > $key) { if ($params['offset'] > $key) {
$this->should_serialize = true;
unset($this->updates[$key]); unset($this->updates[$key]);
} elseif ($params['limit'] === null || count($updates) < $params['limit']) { } elseif ($params['limit'] === null || count($updates) < $params['limit']) {
$updates[] = ['update_id' => $key, 'update' => $value]; $updates[] = ['update_id' => $key, 'update' => $value];
@ -113,7 +116,10 @@ trait UpdateHandler
public function set_channel_state($channel, $data) public function set_channel_state($channel, $data)
{ {
$this->get_channel_state($channel)['pts'] = (!isset($data['pts']) || $data['pts'] === 0) ? $this->get_channel_state($channel)['pts'] : $data['pts']; if (isset($data['pts']) && $data['pts'] !== 0) {
$this->should_serialize = true;
$this->get_channel_state($channel)['pts'] = $data['pts'];
}
} }
public function get_channel_difference($channel) public function get_channel_difference($channel)
@ -147,8 +153,6 @@ trait UpdateHandler
} }
break; break;
case 'updates.channelDifferenceTooLong': case 'updates.channelDifferenceTooLong':
//unset($this->channels_state[$channel]);
//unset($this->chats[$this->get_info('channel#'.$channel)['bot_api_id']]);
$this->handle_update_messages($difference['messages'], $channel); $this->handle_update_messages($difference['messages'], $channel);
$this->set_channel_state($channel, $difference); $this->set_channel_state($channel, $difference);
unset($difference); unset($difference);
@ -164,11 +168,18 @@ trait UpdateHandler
public function set_update_state($data) public function set_update_state($data)
{ {
$this->get_update_state()['pts'] = (!isset($data['pts']) || $data['pts'] === 0) ? $this->get_update_state()['pts'] : $data['pts']; if (isset($data['pts']) && $data['pts'] !== 0) {
$this->get_update_state()['seq'] = (!isset($data['seq']) || $data['seq'] === 0) ? $this->get_update_state()['seq'] : $data['seq']; $this->should_serialize = true;
$this->get_update_state()['date'] = (!isset($data['date']) || $data['date'] < $this->get_update_state()['date']) ? $this->get_update_state()['date'] : $data['date']; $this->get_update_state()['pts'] = $data['pts'];
}
return $this->get_update_state(); if (isset($data['seq']) && $data['seq'] !== 0) {
$this->should_serialize = true;
$this->get_update_state()['seq'] = $data['seq'];
}
if (isset($data['date']) && $data['date'] > $this->get_update_state()['date']) {
$this->should_serialize = true;
$this->get_update_state()['date'] = $data['date'];
}
} }
public function &get_update_state() public function &get_update_state()
@ -325,6 +336,7 @@ trait UpdateHandler
} }
if ($update['pts'] > $cur_state['pts']) { if ($update['pts'] > $cur_state['pts']) {
$cur_state['pts'] = $update['pts']; $cur_state['pts'] = $update['pts'];
$this->should_serialize = true;
$pop_pts = true; $pop_pts = true;
} elseif (isset($update['pts_count'])) { } elseif (isset($update['pts_count'])) {
\danog\MadelineProto\Logger::log(['Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' <= current pts '.$cur_state['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR); \danog\MadelineProto\Logger::log(['Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' <= current pts '.$cur_state['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR);
@ -333,6 +345,7 @@ trait UpdateHandler
} }
if ($channel_id !== false && isset($options['date']) && $this->get_update_state()['date'] < $options['date']) { if ($channel_id !== false && isset($options['date']) && $this->get_update_state()['date'] < $options['date']) {
$this->get_update_state()['date'] = $options['date']; $this->get_update_state()['date'] = $options['date'];
$this->should_serialize = true;
} }
} elseif ($channel_id === false && isset($options['seq']) && $options['seq'] > 0) { } elseif ($channel_id === false && isset($options['seq']) && $options['seq'] > 0) {
$seq = $options['seq']; $seq = $options['seq'];
@ -350,6 +363,7 @@ trait UpdateHandler
} }
if ($cur_state['seq'] != $seq) { if ($cur_state['seq'] != $seq) {
$this->should_serialize = true;
$cur_state['seq'] = $seq; $cur_state['seq'] = $seq;
if (isset($options['date']) && $cur_state['date'] < $options['date']) { if (isset($options['date']) && $cur_state['date'] < $options['date']) {
$cur_state['date'] = $options['date']; $cur_state['date'] = $options['date'];
@ -372,6 +386,7 @@ trait UpdateHandler
if (!$this->settings['updates']['handle_updates']) { if (!$this->settings['updates']['handle_updates']) {
return; return;
} }
$this->should_serialize = true;
$next_seq = $this->get_update_state()['seq'] + 1; $next_seq = $this->get_update_state()['seq'] + 1;
if (empty($this->get_update_state()['pending_seq_updates'][$next_seq]['updates'])) { if (empty($this->get_update_state()['pending_seq_updates'][$next_seq]['updates'])) {
return false; return false;
@ -394,6 +409,7 @@ trait UpdateHandler
if (!$this->settings['updates']['handle_updates']) { if (!$this->settings['updates']['handle_updates']) {
return; return;
} }
$this->should_serialize = true;
if ($channel_id === false) { if ($channel_id === false) {
$cur_state = &$this->get_update_state(); $cur_state = &$this->get_update_state();
} else { } else {
@ -461,6 +477,9 @@ trait UpdateHandler
if (!$this->settings['updates']['handle_updates']) { if (!$this->settings['updates']['handle_updates']) {
return; return;
} }
if (isset($update['message']['_']) && $update['message']['_'] === 'messageEmpty') {
return;
}
if (isset($update['message']['from_id']) && $update['message']['from_id'] === $this->datacenter->authorization['user']['id']) { if (isset($update['message']['from_id']) && $update['message']['from_id'] === $this->datacenter->authorization['user']['id']) {
$update['message']['out'] = true; $update['message']['out'] = true;
} }

View File

@ -181,8 +181,7 @@ trait TL
} }
$auto = false; $auto = false;
if (!is_array($object) && in_array($type['type'], ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'])) { if ((!is_array($object) || (isset($object['_']) && $this->constructors->find_by_predicate($object['_'])['type'] !== $type['type'])) && in_array($type['type'], ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'])) {
//var_dump($this->get_info($object));
$object = $this->get_info($object)[$type['type']]; $object = $this->get_info($object)[$type['type']];
} }
if (!isset($object['_'])) { if (!isset($object['_'])) {
@ -197,7 +196,7 @@ trait TL
$constructorData = $this->constructors->find_by_predicate($predicate); $constructorData = $this->constructors->find_by_predicate($predicate);
if ($constructorData === false) { if ($constructorData === false) {
\danog\MadelineProto\Logger::log([$object], \danog\MadelineProto\Logger::FATAL_WARNING); \danog\MadelineProto\Logger::log([$object], \danog\MadelineProto\Logger::FATAL_ERROR);
throw new Exception('Could not extract type'); throw new Exception('Could not extract type');
} }

View File

@ -53,7 +53,10 @@ trait Login
$this->API->get_updates_state(); $this->API->get_updates_state();
$this->API->should_serialize = true; $this->API->should_serialize = true;
if (!isset($this->API->settings['pwr']['pwr']) || !$this->API->settings['pwr']['pwr']) { if (!isset($this->API->settings['pwr']['pwr']) || !$this->API->settings['pwr']['pwr']) {
try {
file_get_contents('https://api.pwrtelegram.xyz/bot'.$token.'/getme'); file_get_contents('https://api.pwrtelegram.xyz/bot'.$token.'/getme');
} catch (\danog\MadelineProto\Exception $e) {
}
} }
\danog\MadelineProto\Logger::log(['Logged in successfully!'], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(['Logged in successfully!'], \danog\MadelineProto\Logger::NOTICE);