This commit is contained in:
Daniil Gentili 2017-10-09 13:49:01 +03:00
parent b3f5ab6710
commit 9ebda4231d
5 changed files with 10 additions and 6 deletions

View File

@ -25,11 +25,11 @@ try {
}
//var_dump($MadelineProto->API->get_config([], ['datacenter' => $MadelineProto->API->datacenter->curdc]));
//var_dump($MadelineProto->API->settings['connection']);
$MadelineProto->serialize = 'bot.madeline';
$MadelineProto->session = 'bot.madeline';
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('bot.madeline', $MadelineProto).' bytes'.PHP_EOL;
$offset = 0;
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->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
\danog\MadelineProto\Logger::log([$updates]);
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
@ -54,7 +54,7 @@ while (true) {
if (isset($update['update']['message']['media']) && ($update['update']['message']['media']['_'] == 'messageMediaPhoto' || $update['update']['message']['media']['_'] == 'messageMediaDocument')) {
$time = time();
$file = $MadelineProto->download_to_dir($update['update']['message']['media'], '/tmp');
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => 'Downloaded to '.$file.' in '.(time() - $time).' seconds', 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
$MadelineProto->messages->sendMessage(['peer' => isset($update['update']['message']['from_id']) ? $update['update']['message']['from_id'] : $update['update']['message']['to_id'], 'message' => 'Downloaded to '.$file.' in '.(time() - $time).' seconds', 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);

View File

@ -16,6 +16,7 @@ class API extends APIFactory
{
use \danog\Serializable;
public $session;
public $serialized = 0;
public function ___construct($params = [])
{
@ -96,7 +97,6 @@ class API extends APIFactory
public function serialize($filename)
{
Logger::log([\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']]);
return Serialization::serialize($filename, $this);
}
}

View File

@ -131,10 +131,13 @@ class APIFactory
$this->API->get_config([], ['datacenter' => $this->API->datacenter->curdc]);
$aargs = isset($arguments[1]) && is_array($arguments[1]) ? $arguments[1] : [];
$aargs['datacenter'] = $this->API->datacenter->curdc;
if ($name === 'get_updates' && isset($this->session) && !is_null($this->session) && time() - $this->serialized > 10) {
$this->serialize($this->session);
Logger::log(["Didn't serialize in a while, doing that now..."]);
}
if ($this->lua === false) {
return method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && is_array($arguments[0])) ? $arguments[0] : [], $aargs);
}
try {
$deserialized = method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && is_array($arguments[0])) ? $arguments[0] : [], $aargs);
Lua::convert_objects($deserialized);

View File

@ -535,7 +535,7 @@ trait PeerHandler
public function store_db($res, $force = false)
{
if (!isset($this->settings['pwr']) || $this->settings['pwr']['pwr'] === false) {
if (!isset($this->settings['pwr']) || $this->settings['pwr']['pwr'] === false || (isset($this->settings['connection_settings'][$this->datacenter->curdc]) ? $this->settings['connection_settings'][$this->datacenter->curdc] : $this->settings['connection_settings']['all'])['test_mode']) {
/*
try {
if (isset($res['username'])) {

View File

@ -32,6 +32,7 @@ class Serialization
$instance->API->setdem = false;
$instance->API->__construct($instance->API->settings);
}
$instance->serialized = time();
if (!file_exists($lock = $filename.'.lock')) {
touch($lock);
clearstatcache();