Improvements to web logging

This commit is contained in:
Daniil Gentili 2019-09-14 14:21:11 +02:00
parent e479bf6bf3
commit 5570f9ddc9
9 changed files with 87 additions and 31 deletions

View File

@ -32,6 +32,11 @@ class API extends APIFactory
use \danog\MadelineProto\Wrappers\ApiTemplates;
public $session;
public $serialized = 0;
/**
* Instance of MadelineProto
*
* @var MTProto
*/
public $API;
public $getting_api_id = false;
public $my_telegram_org_wrapper;

View File

@ -33,6 +33,7 @@ use Amp\Failure;
use Amp\Internal;
use Amp\Promise;
use Amp\Success;
use ReflectionGenerator;
/**
* Creates a promise from a generator function yielding promises.
@ -209,4 +210,16 @@ final class Coroutine implements Promise, \ArrayAccess
unset($result[$offset]);
})());
}
/**
* Get stacktrace from when the generator was started
*
* @param integer $options Backtrace options
*
* @return array
*/
public function getTrace(int $options = \DEBUG_BACKTRACE_PROVIDE_OBJECT): array
{
return (new ReflectionGenerator($this->generator))->getTrace($options);
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* Lang module
* Lang module.
*
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
@ -19,9 +19,9 @@ namespace danog\MadelineProto;
class Lang
{
public static $lang = array (
'it' =>
array (
public static $lang = [
'it' =>
[
'phpseclib_fork' => 'Per favore installa questo fork di phpseclib: https://github.com/danog/phpseclib',
'inst_dc' => 'Istanziamento dei DataCenter...',
'load_rsa' => 'Caricamento delle chiavi RSA...',
@ -161,9 +161,9 @@ class Lang
'done' => 'Fatto!',
'cdn_reupload' => 'Il file non è disponibile sul nostro CDN, richiedo la copia!',
'stored_on_cdn' => 'Il file è scaricabile tramite CDN!',
),
'en' =>
array (
],
'en' =>
[
'req_pq' => 'Requesting pq...',
'done' => 'Done!',
'cdn_reupload' => 'File is not stored on CDN, requesting reupload!',
@ -5244,11 +5244,11 @@ class Lang
'method_account.installTheme_param_dark_type_true' => 'Whether to install the dark version',
'method_account.getThemes' => 'Get installed themes',
'method_account.saveTheme' => 'Save theme',
),
);
],
];
// THIS WILL BE OVERWRITTEN BY $lang["en"]
public static $current_lang = array (
public static $current_lang = [
'req_pq' => 'Requesting pq...',
'done' => 'Done!',
'cdn_reupload' => 'File is not stored on CDN, requesting reupload!',
@ -10329,5 +10329,5 @@ class Lang
'method_account.installTheme_param_dark_type_true' => 'Whether to install the dark version',
'method_account.getThemes' => 'Get installed themes',
'method_account.saveTheme' => 'Save theme',
);
}
];
}

View File

@ -19,7 +19,6 @@
namespace danog\MadelineProto\MTProtoTools;
use danog\MadelineProto\Exception;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\TL\TLCallback;
use danog\MadelineProto\Tools;
@ -246,13 +245,24 @@ class MinDatabase implements TLCallback
return $object;
}
return $new;
} else {
$this->API->logger->logger("Don't have origin info with min peer $id, this may fail");
}
$this->API->logger->logger("Don't have origin info with min peer $id, this may fail");
return $object;
}
/**
* Check if location info is available for peer.
*
* @param float|int $id Peer ID
*
* @return boolean
*/
public function hasPeer($id): bool
{
return isset($this->db[$id]);
}
public function __debugInfo()
{
return ['MinDatabase instance '.\spl_object_hash($this)];

View File

@ -79,7 +79,7 @@ trait PeerHandler
}
switch ($user['_']) {
case 'user':
if (!isset($this->chats[$user['id']]) || ($this->chats[$user['id']] !== $user && !$user['min'])) {
if (!isset($this->chats[$user['id']]) || $this->chats[$user['id']] !== $user) {
$this->logger->logger("Updated user {$user['id']}", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->chats[$user['id']] = $user;
$this->cache_pwr_chat($user['id'], false, true);
@ -127,7 +127,7 @@ trait PeerHandler
return;
}
if (!isset($this->chats[$bot_api_id]) || ($this->chats[$bot_api_id] !== $chat && !($chat['min'] ?? false))) {
if (!isset($this->chats[$bot_api_id]) || $this->chats[$bot_api_id] !== $chat) {
$this->logger->logger("Updated chat $bot_api_id", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->chats[$bot_api_id] = $chat;
@ -259,7 +259,7 @@ trait PeerHandler
case 'messageEntityMentionName':
case 'messageActionChatDeleteUser':
return $id['user_id'];
case 'messageActionChatDeleteUser':
case 'messageActionChatJoinedByLink':
return $id['inviter_id'];
case 'chat':
case 'chatForbidden':
@ -415,6 +415,21 @@ trait PeerHandler
}
}
if (isset($this->chats[$id])) {
if ($this->chats[$id]['min'] ?? false && $this->minDatabase->hasPeer($id)) {
$this->logger->logger("Only have min peer for $id in database, trying to fetch full info");
try {
if ($id < 0) {
yield $this->method_call_async_read('channels.getChannels', ['id' => [$this->from_supergroup($id)]], ['datacenter' => $this->datacenter->curdc]);
} else {
yield $this->method_call_async_read('users.getUsers', ['id' => [$id]], ['datacenter' => $this->datacenter->curdc]);
}
} catch (\danog\MadelineProto\Exception $e) {
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
try {
return $this->gen_all($this->chats[$id], $folder_id);
} catch (\danog\MadelineProto\Exception $e) {
@ -474,6 +489,18 @@ trait PeerHandler
}
foreach ($this->chats as $chat) {
if (isset($chat['username']) && \strtolower($chat['username']) === $id) {
if ($this->chats[$id]['min'] ?? false) {
if ($id < 0) {
if ($this->is_supergroup($id)) {
yield $this->method_call_async_read('channels.getChannels', ['id' => [['access_hash' => 0, 'channel_id' => $this->from_supergroup($id), '_' => 'inputChannel']]], ['datacenter' => $this->datacenter->curdc]);
} else {
yield $this->method_call_async_read('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]);
}
} else {
yield $this->method_call_async_read('users.getUsers', ['id' => [['access_hash' => 0, 'user_id' => $id, '_' => 'inputUser']]], ['datacenter' => $this->datacenter->curdc]);
}
}
return $this->gen_all($chat, $folder_id);
}
}

View File

@ -19,6 +19,8 @@
namespace danog\MadelineProto\TL;
use danog\MadelineProto\Tools;
trait PrettyException
{
public $tl_trace;

View File

@ -482,9 +482,8 @@ trait Tools
}
foreach ($trace as $frame) {
if (isset($frame['object']) && $frame['object'] instanceof \Generator) {
$reflection = new ReflectionGenerator($frame['object']);
yield from self::backtrace($ignoreArgs, $reflection->getTrace($flags));
if (isset($frame['object']) && $frame['object'] instanceof Coroutine) {
yield from self::backtrace($ignoreArgs, $frame['object']->getTrace($flags));
return;
}
//var_dump(get_class($frame['object'] ?? new class {}));

View File

@ -58,7 +58,7 @@ trait DialogHandler
$last_date = 0;
$last_id = 0;
$res['messages'] = \array_reverse($res['messages'] ?? []);
foreach (\array_reverse($res['dialogs']) as $dialog) {
foreach (\array_reverse($res['dialogs'] ?? []) as $dialog) {
$id = $this->get_id($dialog['peer']);
if (!isset($dialogs[$id])) {
$dialogs[$id] = $dialog;

View File

@ -175,19 +175,19 @@ trait Loop
return;
}
$this->logger->logger($message);
$buffer = @\ob_get_contents();
@\ob_end_clean();
\header('Connection: close');
\ignore_user_abort(true);
$buffer = @\ob_get_clean() ?: '';
$buffer .= '<html><body><h1>'.\htmlentities($message).'</h1></body></html>';
echo $buffer;
$size = \max(\ob_get_length(), \strlen($buffer));
\header("Content-Length: $size");
\ignore_user_abort(true);
\header('Connection: close');
\header('Content-Type: text/html');
\ob_end_flush();
echo $buffer;
\flush();
$GLOBALS['exited'] = true;
if (\function_exists('fastcgi_finish_request')) {
if (\function_exists(\fastcgi_finish_request::class)) {
\fastcgi_finish_request();
}
}