Bugfixes
This commit is contained in:
parent
491c15e5e3
commit
6711f6e814
@ -20,6 +20,7 @@ class Logger
|
||||
public static $mode = null;
|
||||
public static $optional = null;
|
||||
public static $constructed = false;
|
||||
public static $prefix = '';
|
||||
|
||||
/*
|
||||
* Constructor function
|
||||
@ -29,7 +30,7 @@ class Logger
|
||||
* 2 - Log to file defined in second parameter
|
||||
* 3 - Echo logs
|
||||
*/
|
||||
public static function constructor(&$mode, &$optional = null)
|
||||
public static function constructor(&$mode, &$optional = null, $prefix = '')
|
||||
{
|
||||
if ($mode == null) {
|
||||
throw new Exception('No mode was specified!');
|
||||
@ -37,6 +38,7 @@ class Logger
|
||||
self::$mode = &$mode;
|
||||
self::$optional = &$optional;
|
||||
self::$constructed = true;
|
||||
self::$prefix = $prefix === '' ? '' : ', '.$prefix;
|
||||
}
|
||||
|
||||
public static function log(...$params)
|
||||
@ -48,7 +50,7 @@ class Logger
|
||||
if (!is_string($param)) {
|
||||
$param = var_export($param, true);
|
||||
}
|
||||
$param = str_pad(basename(debug_backtrace()[0]['file'], '.php').': ', 16)."\t".$param;
|
||||
$param = str_pad(basename(debug_backtrace()[0]['file'], '.php').self::$prefix.': ', 16+strlen(self::$prefix))."\t".$param;
|
||||
switch (self::$mode) {
|
||||
case 1:
|
||||
error_log($param);
|
||||
|
@ -226,10 +226,10 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
|
||||
public function setup_logger()
|
||||
{
|
||||
if (!\danog\MadelineProto\Logger::$constructed) {
|
||||
//if (!\danog\MadelineProto\Logger::$constructed) {
|
||||
// Set up logger class
|
||||
\danog\MadelineProto\Logger::constructor($this->settings['logger']['logger'], $this->settings['logger']['logger_param']);
|
||||
}
|
||||
\danog\MadelineProto\Logger::constructor($this->settings['logger']['logger'], $this->settings['logger']['logger_param'], isset($this->datacenter->authorization['user']) ? (isset($this->datacenter->authorization['user']['username']) ? $this->datacenter->authorization['user']['username'] : $this->datacenter->authorization['user']['id']) : '');
|
||||
//}
|
||||
}
|
||||
|
||||
public function reset_session()
|
||||
|
@ -29,7 +29,13 @@ trait PeerHandler
|
||||
if (!isset($this->chats[$user['id']]) || $this->chats[$user['id']] !== $user) {
|
||||
$this->chats[$user['id']] = $user;
|
||||
$this->should_serialize = true;
|
||||
try {
|
||||
$this->get_pwr_chat($user['id'], false, true);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
}
|
||||
}
|
||||
case 'userEmpty':
|
||||
break;
|
||||
@ -50,7 +56,13 @@ trait PeerHandler
|
||||
if (!isset($this->chats[-$chat['id']]) || $this->chats[-$chat['id']] !== $chat) {
|
||||
$this->chats[-$chat['id']] = $chat;
|
||||
$this->should_serialize = true;
|
||||
try {
|
||||
$this->get_pwr_chat(-$chat['id'], true, true);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
case 'channelEmpty':
|
||||
@ -60,7 +72,13 @@ trait PeerHandler
|
||||
if (!isset($this->chats[(int) ('-100'.$chat['id'])]) || $this->chats[(int) ('-100'.$chat['id'])] !== $chat) {
|
||||
$this->chats[(int) ('-100'.$chat['id'])] = $chat;
|
||||
$this->should_serialize = true;
|
||||
try {
|
||||
$this->get_pwr_chat('-100'.$chat['id'], true, true);
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
\danog\MadelineProto\Logger::log($e->getMessage());
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -74,38 +74,12 @@ trait ResponseHandler
|
||||
$response = $this->datacenter->incoming_messages[$current_msg_id]['content'];
|
||||
\danog\MadelineProto\Logger::log('Received '.$response['_'].'.');
|
||||
|
||||
if (isset($response['users'])) {
|
||||
$this->add_users($response['users']);
|
||||
}
|
||||
if (isset($response['chats'])) {
|
||||
$this->add_chats($response['chats']);
|
||||
}
|
||||
if (isset($response['result']['users'])) {
|
||||
$this->add_users($response['result']['users']);
|
||||
}
|
||||
if (isset($response['result']['chats'])) {
|
||||
$this->add_chats($response['result']['chats']);
|
||||
}
|
||||
if (isset($response['result']['_'])) {
|
||||
switch ($this->constructors->find_by_predicate($response['result']['_'])['type']) {
|
||||
case 'Update':
|
||||
$this->handle_update($response['result']);
|
||||
break;
|
||||
|
||||
case 'userFull':
|
||||
$this->chats[$response['result']['user']['id']] = $response['result'];
|
||||
$this->should_serialize = true;
|
||||
break;
|
||||
|
||||
case 'chatFull':
|
||||
$this->chats[-$response['result']['chat']['id']] = $response['result'];
|
||||
$this->should_serialize = true;
|
||||
break;
|
||||
|
||||
case 'channelFull':
|
||||
$this->chats[(int) ('-100'.$response['result']['channel']['id'])] = $response['result'];
|
||||
$this->should_serialize = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch ($response['_']) {
|
||||
@ -266,6 +240,18 @@ trait ResponseHandler
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isset($response['users'])) {
|
||||
$this->add_users($response['users']);
|
||||
}
|
||||
if (isset($response['chats'])) {
|
||||
$this->add_chats($response['chats']);
|
||||
}
|
||||
if (isset($response['result']['users'])) {
|
||||
$this->add_users($response['result']['users']);
|
||||
}
|
||||
if (isset($response['result']['chats'])) {
|
||||
$this->add_chats($response['result']['chats']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,24 @@ trait UpdateHandler
|
||||
public $updates = [];
|
||||
public $updates_key = 0;
|
||||
private $getting_state = false;
|
||||
public $full_chats;
|
||||
|
||||
|
||||
public function full_chat_last_updated($id) {
|
||||
$id = $this->get_info($id)['bot_api_id'];
|
||||
return isset($this->full_chats[$id]['last_update']) ? $this->full_chats[$id]['last_update'] : 0;
|
||||
}
|
||||
public function pwr_update_handler($update)
|
||||
{
|
||||
if (isset($update['message']['to_id'])) {
|
||||
if (isset($update['message']['to_id']) && time() - $this->full_chat_last_updated($update['message']['to_id']) <= 600) {
|
||||
$full_chat = $this->get_pwr_chat($update['message']['to_id']);
|
||||
$full_chat['last_update'] = time();
|
||||
$this->full_chats[$full_chat['id']] = $full_chat;
|
||||
}
|
||||
if (isset($update['message']['from_id'])) {
|
||||
if (isset($update['message']['from_id']) && time() - $this->full_chat_last_updated($update['message']['from_id']) <= 600) {
|
||||
$full_chat = $this->get_pwr_chat($update['message']['from_id']);
|
||||
$full_chat['last_update'] = time();
|
||||
$this->full_chats[$full_chat['id']] = $full_chat;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ trait TL
|
||||
}
|
||||
throw new Exception('Missing required parameter ('.$current_argument['name'].')');
|
||||
}
|
||||
\danog\MadelineProto\Logger::log('Serializing '.$current_argument['name'].' of type '.$current_argument['type']);
|
||||
//\danog\MadelineProto\Logger::log('Serializing '.$current_argument['name'].' of type '.$current_argument['type']);
|
||||
$serialized .= $this->serialize_object($current_argument, $arguments[$current_argument['name']]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user