Bugfixes
This commit is contained in:
parent
b3f5ab6710
commit
9ebda4231d
6
bot.php
6
bot.php
@ -25,11 +25,11 @@ try {
|
|||||||
}
|
}
|
||||||
//var_dump($MadelineProto->API->get_config([], ['datacenter' => $MadelineProto->API->datacenter->curdc]));
|
//var_dump($MadelineProto->API->get_config([], ['datacenter' => $MadelineProto->API->datacenter->curdc]));
|
||||||
//var_dump($MadelineProto->API->settings['connection']);
|
//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;
|
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('bot.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
||||||
$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->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]);
|
\danog\MadelineProto\Logger::log([$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
|
||||||
@ -54,7 +54,7 @@ while (true) {
|
|||||||
if (isset($update['update']['message']['media']) && ($update['update']['message']['media']['_'] == 'messageMediaPhoto' || $update['update']['message']['media']['_'] == 'messageMediaDocument')) {
|
if (isset($update['update']['message']['media']) && ($update['update']['message']['media']['_'] == 'messageMediaPhoto' || $update['update']['message']['media']['_'] == 'messageMediaDocument')) {
|
||||||
$time = time();
|
$time = time();
|
||||||
$file = $MadelineProto->download_to_dir($update['update']['message']['media'], '/tmp');
|
$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) {
|
} 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()]);
|
||||||
|
@ -16,6 +16,7 @@ class API extends APIFactory
|
|||||||
{
|
{
|
||||||
use \danog\Serializable;
|
use \danog\Serializable;
|
||||||
public $session;
|
public $session;
|
||||||
|
public $serialized = 0;
|
||||||
|
|
||||||
public function ___construct($params = [])
|
public function ___construct($params = [])
|
||||||
{
|
{
|
||||||
@ -96,7 +97,6 @@ class API extends APIFactory
|
|||||||
public function serialize($filename)
|
public function serialize($filename)
|
||||||
{
|
{
|
||||||
Logger::log([\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']]);
|
Logger::log([\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']]);
|
||||||
|
|
||||||
return Serialization::serialize($filename, $this);
|
return Serialization::serialize($filename, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,10 +131,13 @@ class APIFactory
|
|||||||
$this->API->get_config([], ['datacenter' => $this->API->datacenter->curdc]);
|
$this->API->get_config([], ['datacenter' => $this->API->datacenter->curdc]);
|
||||||
$aargs = isset($arguments[1]) && is_array($arguments[1]) ? $arguments[1] : [];
|
$aargs = isset($arguments[1]) && is_array($arguments[1]) ? $arguments[1] : [];
|
||||||
$aargs['datacenter'] = $this->API->datacenter->curdc;
|
$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) {
|
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);
|
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 {
|
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);
|
$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);
|
Lua::convert_objects($deserialized);
|
||||||
|
@ -535,7 +535,7 @@ trait PeerHandler
|
|||||||
|
|
||||||
public function store_db($res, $force = false)
|
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 {
|
try {
|
||||||
if (isset($res['username'])) {
|
if (isset($res['username'])) {
|
||||||
|
@ -32,6 +32,7 @@ class Serialization
|
|||||||
$instance->API->setdem = false;
|
$instance->API->setdem = false;
|
||||||
$instance->API->__construct($instance->API->settings);
|
$instance->API->__construct($instance->API->settings);
|
||||||
}
|
}
|
||||||
|
$instance->serialized = time();
|
||||||
if (!file_exists($lock = $filename.'.lock')) {
|
if (!file_exists($lock = $filename.'.lock')) {
|
||||||
touch($lock);
|
touch($lock);
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user