Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-04-21 11:14:21 +00:00 committed by StyleCI Bot
parent 5c50d63cfb
commit 1ad81319a3
15 changed files with 142 additions and 109 deletions

View File

@ -36,16 +36,24 @@ class API extends APIFactory
$this->API->v = $this->API->getV();
\danog\MadelineProto\Logger::log(['MadelineProto is ready!'], Logger::NOTICE);
}
public function __wakeup() {
public function __wakeup()
{
//if (method_exists($this->API, 'wakeup')) $this->API = $this->API->wakeup();
$this->APIFactory();
}
public function __destruct() {
public function __destruct()
{
restore_error_handler();
}
public function __sleep() { return ['API']; }
public function __sleep()
{
return ['API'];
}
public function APIFactory()
{
foreach ($this->API->get_method_namespaces() as $namespace) {

View File

@ -38,6 +38,7 @@ class DataCenter
$socket->close_and_reopen();
}
}
public function dc_disconnect($dc_number)
{
if ($this->curdc === $dc_number) {
@ -85,8 +86,7 @@ class DataCenter
return array_keys($this->dclist[$test][$ipv6]);
}
/*
public function &__get($name)
{

View File

@ -325,7 +325,7 @@ description: List of methods
}
$layer = isset($this->constructors->layer[$key]) ? '_'.$this->constructors->layer[$key] : '';
$rtype = $this->constructors->type[$key];
$type = str_replace(['.', '<', '>'], ['_', '_of_', ''], $rtype);
$real_type = preg_replace('/.*_of_/', '', $type);
$constructor = str_replace(['.', '<', '>'], ['_', '_of_', ''], $rconstructor);
@ -338,7 +338,6 @@ description: List of methods
$types[$real_type]['constructors'][] = $key;
}
$params = '';
foreach ($this->constructors->params[$key] as $param) {
if (in_array($param['name'], ['flags', 'random_id', 'random_bytes'])) {
@ -524,7 +523,6 @@ description: List of constructors
\danog\MadelineProto\Logger::log(['Generating types documentation...'], \danog\MadelineProto\Logger::NOTICE);
foreach ($types as $otype => $keys) {
$new_namespace = preg_replace('/_.*/', '', $method);
$br = $new_namespace != $last_namespace ? '***
<br><br>' : '';
@ -602,7 +600,9 @@ $'.$type.' = -147286699; // Numeric chat id returned by request_secret_chat, can
'.$methods.'
';
if (file_exists('types/'.$type.'.md')) var_dump($type);
if (file_exists('types/'.$type.'.md')) {
var_dump($type);
}
file_put_contents('types/'.$type.'.md', $header.$constructors.$methods);
$last_namespace = $new_namespace;
}

View File

@ -51,7 +51,7 @@ class MTProto
public $bigint = false;
public $run_workers = false;
public $threads = false;
public function __construct($settings = [])
{
//if ($this->unserialized($settings)) return true;
@ -107,7 +107,7 @@ class MTProto
$this->v = $this->getV();
$this->should_serialize = true;
}
public function __sleep()
{
$t = get_object_vars($this);
@ -142,7 +142,9 @@ class MTProto
if (!isset($this->v) || $this->v !== $this->getV()) {
\danog\MadelineProto\Logger::log(['Serialization is out of date, reconstructing object!'], Logger::WARNING);
$settings = $this->settings;
if (isset($settings['updates']['callback'][0]) && $settings['updates']['callback'][0] === $this) $settings['updates']['callback'] = 'get_updates_update_handler';
if (isset($settings['updates']['callback'][0]) && $settings['updates']['callback'][0] === $this) {
$settings['updates']['callback'] = 'get_updates_update_handler';
}
unset($settings['tl_schema']);
$this->reset_session(true, true);
$this->__construct($settings);
@ -153,7 +155,6 @@ class MTProto
\danog\MadelineProto\Logger::log(['Getting updates after deserialization...'], Logger::NOTICE);
$this->get_updates_difference();
}
}
public function __destruct()
@ -161,14 +162,15 @@ class MTProto
if (isset($this->reader_pool)) {
$this->run_workers = false;
while ($number = $this->reader_pool->collect()) {
\danog\MadelineProto\Logger::log(['Shutting down reader pool, '.$number .' jobs left'], \danog\MadelineProto\Logger::NOTICE);
\danog\MadelineProto\Logger::log(['Shutting down reader pool, '.$number.' jobs left'], \danog\MadelineProto\Logger::NOTICE);
}
$this->reader_pool->shutdown();
}
}
public function setup_threads()
{
if ($this->threads = $this->run_workers = class_exists('\Pool') && in_array(php_sapi_name(), ['cli', 'phpdbg']) && $this->settings['threading']['allow_threading'] && extension_loaded("pthreads")) {
if ($this->threads = $this->run_workers = class_exists('\Pool') && in_array(php_sapi_name(), ['cli', 'phpdbg']) && $this->settings['threading']['allow_threading'] && extension_loaded('pthreads')) {
\danog\MadelineProto\Logger::log(['THREADING IS ENABLED'], \danog\MadelineProto\Logger::NOTICE);
$this->start_threads();
}
@ -364,7 +366,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
case 'FATAL ERROR': $settings['logger']['logger_level'] = 0; break;
}
$this->settings = $settings;
// Setup logger
$this->setup_logger();
@ -373,10 +374,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
public function setup_logger()
{
\danog\MadelineProto\Logger::constructor(
$this->settings['logger']['logger'],
$this->settings['logger']['logger_param'],
$this->settings['logger']['logger_param'],
isset($this->authorization['user']) ? (isset($this->authorization['user']['username']) ? $this->authorization['user']['username'] : $this->authorization['user']['id']) : '', isset($this->settings['logger']['logger_level']) ? $this->settings['logger']['logger_level'] : Logger::VERBOSE);
}
@ -384,7 +384,7 @@ isset($this->authorization['user']) ? (isset($this->authorization['user']['usern
{
foreach ($this->datacenter->sockets as $id => $socket) {
if ($de) {
\danog\MadelineProto\Logger::log(['Resetting session id'.($auth_key ? ', authorization key':'').' and seq_no in DC '.$id.'...'], Logger::VERBOSE);
\danog\MadelineProto\Logger::log(['Resetting session id'.($auth_key ? ', authorization key' : '').' and seq_no in DC '.$id.'...'], Logger::VERBOSE);
$socket->session_id = $this->random(8);
$socket->session_in_seq_no = 0;
$socket->session_out_seq_no = 0;
@ -413,13 +413,17 @@ isset($this->authorization['user']) ? (isset($this->authorization['user']['usern
$this->connect_to_all_dcs();
}
}
private $initing_authorization = false;
// Creates authorization keys
public function init_authorization()
{
$this->initing_authorization = true;
foreach ($this->datacenter->sockets as $id => $socket) {
if (strpos($id, 'media')) continue;
if (strpos($id, 'media')) {
continue;
}
if ($socket->session_id === null) {
$socket->session_id = $this->random(8);
$socket->session_in_seq_no = 0;
@ -450,7 +454,9 @@ isset($this->authorization['user']) ? (isset($this->authorization['user']['usern
if (($int_dc = preg_replace('|/D+|', '', $new_dc)) == $authorized_dc) {
continue;
}
if ($int_dc != $new_dc) continue;
if ($int_dc != $new_dc) {
continue;
}
\danog\MadelineProto\Logger::log(['Copying authorization from dc '.$authorized_dc.' to dc '.$new_dc.'...'], Logger::VERBOSE);
$this->should_serialize = true;
$exported_authorization = $this->method_call('auth.exportAuthorization', ['dc_id' => $new_dc], ['datacenter' => $authorized_dc]);
@ -467,15 +473,15 @@ isset($this->authorization['user']) ? (isset($this->authorization['user']['usern
'invokeWithLayer',
[
'layer' => $this->settings['tl_schema']['layer'],
'query' => $this->serialize_method('initConnection',
'query' => $this->serialize_method('initConnection',
[
'api_id' => $this->settings['app_info']['api_id'],
'api_hash' => $this->settings['app_info']['api_hash'],
'device_model' => strpos($options['datacenter'], 'cdn') === false ? $this->settings['app_info']['device_model'] : "n/a",
'system_version' => strpos($options['datacenter'], 'cdn') === false ? $this->settings['app_info']['system_version'] : "n/a",
'app_version' => $this->settings['app_info']['app_version'],
'lang_code' => $this->settings['app_info']['lang_code'],
'query' => $this->serialize_method($method, $arguments)
'api_id' => $this->settings['app_info']['api_id'],
'api_hash' => $this->settings['app_info']['api_hash'],
'device_model' => strpos($options['datacenter'], 'cdn') === false ? $this->settings['app_info']['device_model'] : 'n/a',
'system_version' => strpos($options['datacenter'], 'cdn') === false ? $this->settings['app_info']['system_version'] : 'n/a',
'app_version' => $this->settings['app_info']['app_version'],
'lang_code' => $this->settings['app_info']['lang_code'],
'query' => $this->serialize_method($method, $arguments),
]
),
],
@ -499,7 +505,7 @@ isset($this->authorization['user']) ? (isset($this->authorization['user']['usern
unset($this->config['dc_options']);
\danog\MadelineProto\Logger::log(['Updated config!', $this->config], Logger::NOTICE);
}
public function parse_dc_options($dc_options)
{
foreach ($dc_options as $dc) {

View File

@ -72,18 +72,18 @@ trait AuthKeyHandler
$this->should_serialize = true;
}
}
/*
* ***********************************************************************
* Find our key in the server_public_key_fingerprints vector
*/
foreach ($this->rsa_keys as $fp => $curkey) {
if (in_array($fp, $ResPQ['server_public_key_fingerprints'])) {
$key = $curkey;
}
}
if (!isset($key)) {
throw new \danog\MadelineProto\SecurityException("Couldn't find any of our keys in the server_public_key_fingerprints vector.");
}

View File

@ -61,7 +61,9 @@ trait CallHandler
$server_answer = null;
$update_count = 0;
$only_updates = false;
if ($canunset = !$this->getting_state && !$this->threads && !$this->run_workers) $this->getting_state = true;
if ($canunset = !$this->getting_state && !$this->threads && !$this->run_workers) {
$this->getting_state = true;
}
while ($server_answer === null && $res_count++ < $this->settings['max_tries']['response'] + 1) { // Loop until we get a response, loop for a max of $this->settings['max_tries']['response'] times
try {
\danog\MadelineProto\Logger::log(['Getting response (try number '.$res_count.' for '.$method.')...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
@ -96,7 +98,7 @@ trait CallHandler
continue;
}
}
if ($canunset) {
$this->getting_state = false;
$this->handle_pending_updates();
@ -162,12 +164,13 @@ trait CallHandler
$this->handle_pending_updates();
}
}
if ($server_answer === null) {
if ($last_recv === $this->last_recv && $this->datacenter->sockets[$args['datacenter']]->temp_auth_key != null) {
\danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$args['datacenter']]->temp_auth_key = null;
$this->init_authorization();
return $this->method_call($method, $args, $aargs);
}
throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.' ('.$last_error.').');
@ -178,9 +181,10 @@ trait CallHandler
$server_answer = [$server_answer];
foreach ($message_chunks as $message) {
$args['message'] = $message;
$server_answer []= $this->method_call($method, $args, $aargs);
$server_answer[] = $this->method_call($method, $args, $aargs);
}
}
return $server_answer;
}

View File

@ -35,7 +35,7 @@ trait Crypt
return $cipher->encrypt($message);
}
public function ctr_encrypt($message, $key, $iv, $length)
{
$cipher = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_CTR);

View File

@ -22,6 +22,7 @@ trait MessageHandler
* :param message: byte string to send.
*/
private $last_recv = 0;
public function send_message($message_data, $content_related, $aargs = [])
{
if (!isset($aargs['message_id']) || $aargs['message_id'] === null) {
@ -55,7 +56,6 @@ trait MessageHandler
*/
public function recv_message($datacenter)
{
$payload = $this->datacenter->sockets[$datacenter]->read_message();
if (strlen($payload) === 4) {
$error = \danog\PHP\Struct::unpack('<i', $payload)[0];

View File

@ -145,7 +145,11 @@ trait UpdateHandler
try {
$difference = $this->method_call('updates.getChannelDifference', ['channel' => $input, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $this->get_channel_state($channel)['pts'], 'limit' => 30], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->getMessage() === 'CHANNEL_PRIVATE') return false; else throw $e;
if ($e->getMessage() === 'CHANNEL_PRIVATE') {
return false;
} else {
throw $e;
}
}
\danog\MadelineProto\Logger::log(['Got '.$difference['_']], \danog\MadelineProto\Logger::VERBOSE);
$this->get_channel_state($channel)['sync_loading'] = false;

View File

@ -13,7 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
namespace danog\MadelineProto;
/**
* Just a stream wrapper
* Just a stream wrapper.
*/
class Stream
{

View File

@ -448,35 +448,43 @@ trait BotAPI
return $arguments;
}
function split_to_chunks($text){
$total_length = 4096;
$text_arr = multipleExplodeKeepDelimiters(array("\n"),$text);
$i=0;
$message[0]="";
foreach ($text_arr as $word){
if ( strlen($message[$i] . $word . ' ') <= $total_length ){
if ($text_arr[count($text_arr)-1] == $word){
$message[$i] .= $word;
} else {
$message[$i] .= $word . ' ';
}
} else {
$i++;
if ($text_arr[count($text_arr)-1] == $word){
$message[$i] = $word;
} else {
$message[$i] = $word . ' ';
}
}
}
return $message;
public function split_to_chunks($text)
{
$total_length = 4096;
$text_arr = multipleExplodeKeepDelimiters(["\n"], $text);
$i = 0;
$message[0] = '';
foreach ($text_arr as $word) {
if (strlen($message[$i].$word.' ') <= $total_length) {
if ($text_arr[count($text_arr) - 1] == $word) {
$message[$i] .= $word;
} else {
$message[$i] .= $word.' ';
}
} else {
$i++;
if ($text_arr[count($text_arr) - 1] == $word) {
$message[$i] = $word;
} else {
$message[$i] = $word.' ';
}
}
}
return $message;
}
function multipleExplodeKeepDelimiters($delimiters, $string) {
$initialArray = explode(chr(1), str_replace($delimiters, chr(1), $string));
$finalArray = array();
foreach($initialArray as $item) {
if(strlen($item) > 0) array_push($finalArray, $item . $string[strpos($string, $item) + strlen($item)]);
public function multipleExplodeKeepDelimiters($delimiters, $string)
{
$initialArray = explode(chr(1), str_replace($delimiters, chr(1), $string));
$finalArray = [];
foreach ($initialArray as $item) {
if (strlen($item) > 0) {
array_push($finalArray, $item.$string[strpos($string, $item) + strlen($item)]);
}
}
return $finalArray;
}
return $finalArray;
}
}

View File

@ -182,7 +182,9 @@ trait TL
if ($this->constructors->find_by_id($id) === false) {
unset($this->td_descriptions['constructors'][$name]);
} else {
if (!count($this->td_descriptions['constructors'][$name]['params'])) continue;
if (!count($this->td_descriptions['constructors'][$name]['params'])) {
continue;
}
foreach ($this->td_descriptions['constructors'][$name]['params'] as $k => $param) {
$this->td_descriptions['constructors'][$name]['params'][$k] = str_replace('nullable', 'optional', $param);
}

View File

@ -18,6 +18,7 @@ namespace danog\MadelineProto\Threads;
class SocketReader extends \Threaded implements \Collectable
{
public $ready = false;
public function __construct($me, $current)
{
return;
@ -42,7 +43,7 @@ class SocketReader extends \Threaded implements \Collectable
*/
public function run()
{
var_dump("BLOCK");
var_dump('BLOCK');
while (true);
require_once __DIR__.'/../SecurityException.php';
require_once __DIR__.'/../RPCErrorException.php';
@ -51,7 +52,7 @@ var_dump("BLOCK");
require_once __DIR__.'/../TL/Exception.php';
require_once __DIR__.'/../NothingInTheSocketException.php';
require_once __DIR__.'/../Exception.php';
$handler_pool = new \Pool($this->API->settings['threading']['handler_workers']);
$this->ready = true;
@ -64,7 +65,7 @@ var_dump("BLOCK");
//} catch (\danog\MadelineProto\NothingInTheSocketException $e) { \danog\MadelineProto\Logger::log(['Nothing in the socket for dc '.$this->current], \danog\MadelineProto\Logger::VERBOSE); }
//}
while ($number = $handler_pool->collect()) {
\danog\MadelineProto\Logger::log(['Shutting down handler pool for dc '.$this->current.', '.$number .' jobs left'], \danog\MadelineProto\Logger::NOTICE);
\danog\MadelineProto\Logger::log(['Shutting down handler pool for dc '.$this->current.', '.$number.' jobs left'], \danog\MadelineProto\Logger::NOTICE);
}
$this->setGarbage();
}

View File

@ -44,7 +44,9 @@ trait Tools
{
if (is_array($d)) {
foreach ($d as $k => $v) {
if ($k === 'bytes') $d[$k] = $this->utf8ize($v);
if ($k === 'bytes') {
$d[$k] = $this->utf8ize($v);
}
}
} elseif (is_string($d)) {
return utf8_encode($d);
@ -57,15 +59,23 @@ trait Tools
{
return is_array($elem) || (is_object($elem) && get_class($elem) === 'Volatile');
}
public function array_replace_recursive($a, ...$b) {
public function array_replace_recursive($a, ...$b)
{
return array_replace_recursive($this->array_cast_recursive($a), ...$this->array_cast_recursive($b));
}
public function array_cast_recursive($array) {
public function array_cast_recursive($array)
{
if ($this->is_array($array)) {
if (!is_array($array)) $array = $array;
foreach ($array as $key => $value) { $array[$key] = $this->array_cast_recursive($value); }
if (!is_array($array)) {
$array = $array;
}
foreach ($array as $key => $value) {
$array[$key] = $this->array_cast_recursive($value);
}
}
return $array;
}
}

View File

@ -59,13 +59,12 @@ if ($MadelineProto === false) {
\danog\MadelineProto\Logger::log(['Registering new user'], \danog\MadelineProto\Logger::NOTICE);
$authorization = $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
} else {
$MadelineProto->bot_login(getenv('BOT_TOKEN'));
}
}
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
@ -74,7 +73,6 @@ echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline',
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
if (stripos(readline('Do you want to make the secret chat tests? (y/n)'), 'y') !== false) {
/*
$call = $MadelineProto->API->request_call(getenv('TEST_SECRET_CHAT'));
@ -85,16 +83,16 @@ while ($MadelineProto->call_status($call) !== $MadelineProto->API->READY) {
var_dump($MadelineProto->get_call($call));
*/
$secret = $MadelineProto->API->request_secret_chat(getenv('TEST_SECRET_CHAT'));
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' to accept the secret chat...'.PHP_EOL;
while ($MadelineProto->secret_chat_status($secret) !== 2) {
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' to accept the secret chat...'.PHP_EOL;
while ($MadelineProto->secret_chat_status($secret) !== 2) {
$MadelineProto->get_updates();
}
$MadelineProto->get_updates();
}
$MadelineProto->get_updates();
$InputEncryptedChat = $MadelineProto->get_secret_chat($secret)['InputEncryptedChat'];
$sentMessage = $MadelineProto->messages->sendEncrypted(['peer' => $InputEncryptedChat, 'message' => ['_' => 'decryptedMessage', 'media' => ['_' => 'decryptedMessageMediaEmpty'], 'ttl' => 10, 'message' => $message, 'entities' => [['_' => 'messageEntityCode', 'offset' => 0, 'length' => mb_strlen($message)]]]]); // should work with all layers
$InputEncryptedChat = $MadelineProto->get_secret_chat($secret)['InputEncryptedChat'];
$sentMessage = $MadelineProto->messages->sendEncrypted(['peer' => $InputEncryptedChat, 'message' => ['_' => 'decryptedMessage', 'media' => ['_' => 'decryptedMessageMediaEmpty'], 'ttl' => 10, 'message' => $message, 'entities' => [['_' => 'messageEntityCode', 'offset' => 0, 'length' => mb_strlen($message)]]]]); // should work with all layers
\danog\MadelineProto\Logger::log([$sentMessage], \danog\MadelineProto\Logger::NOTICE);
$secret_media = [];
$secret_media = [];
// Photo uploaded as document, secret chat
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/faust.jpg', 'fausticorn.jpg'); // This gets an inputFile object with file name magic
@ -104,32 +102,30 @@ $secret_media['document_photo'] = ['peer' => $secret, 'file' => $inputEncryptedF
$secret_media['photo'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaPhoto', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'caption' => 'This file was uploaded using MadelineProto', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'size' => filesize('tests/faust.jpg'), 'w' => 1280, 'h' => 914]]];
// GIF, secret chat
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/pony.mp4');
$secret_media['gif'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/pony.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/pony.mp4'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'pony.mp4', 'size' => filesize('tests/faust.jpg'), 'attributes' => [['_' => 'documentAttributeAnimated']]]]];
$secret_media['gif'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/pony.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/pony.mp4'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'pony.mp4', 'size' => filesize('tests/faust.jpg'), 'attributes' => [['_' => 'documentAttributeAnimated']]]]];
// Sticker, secret chat
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/lel.webp');
$secret_media['sticker'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/lel.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/lel.webp'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'lel.webp', 'size' => filesize('tests/lel.webp'), 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL', 'stickerset' => ['_' => 'inputStickerSetEmpty']]]]]];
$secret_media['sticker'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/lel.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/lel.webp'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'lel.webp', 'size' => filesize('tests/lel.webp'), 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL', 'stickerset' => ['_' => 'inputStickerSetEmpty']]]]]];
// Document, secrey chat
$time = time();
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/60', 'magic'); // This gets an inputFile object with file name magic
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/60', 'magic'); // This gets an inputFile object with file name magic
var_dump(time() - $time);
$secret_media['document'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => 'magic/magic', 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'magic.magic', 'size' => filesize('tests/60'), 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'fairy']]]]];
$secret_media['document'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => 'magic/magic', 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'magic.magic', 'size' => filesize('tests/60'), 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'fairy']]]]];
// Video, secret chat
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/swing.mp4');
$secret_media['video'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/swing.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/swing.mp4'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'swing.mp4', 'size' => filesize('tests/swing.mp4'), 'attributes' => [['_' => 'documentAttributeVideo', 'duration' => 5, 'w' => 1280, 'h' => 720]]]]];
$secret_media['video'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/swing.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/swing.mp4'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'swing.mp4', 'size' => filesize('tests/swing.mp4'), 'attributes' => [['_' => 'documentAttributeVideo', 'duration' => 5, 'w' => 1280, 'h' => 720]]]]];
// audio, secret chat
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/mosconi.mp3');
$secret_media['audio'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'mosconi.mp3', 'size' => filesize('tests/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
$secret_media['audio'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'mosconi.mp3', 'size' => filesize('tests/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
$secret_media['voice'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'mosconi.mp3', 'size' => filesize('tests/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
foreach ($secret_media as $type => $smessage) {
$type = $MadelineProto->messages->sendEncryptedFile($smessage);
}
$secret_media['voice'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'mosconi.mp3', 'size' => filesize('tests/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
foreach ($secret_media as $type => $smessage) {
$type = $MadelineProto->messages->sendEncryptedFile($smessage);
}
}
$mention = $MadelineProto->get_info(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
$mention = $mention['user_id']; // Selects only the numeric user id
@ -151,22 +147,17 @@ $media['gif'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mim
$inputFile = $MadelineProto->upload('tests/lel.webp');
$media['sticker'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => mime_content_type('tests/lel.webp'), 'caption' => 'test', 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL', 'stickerset' => ['_' => 'inputStickerSetEmpty']]]];
// Video
$inputFile = $MadelineProto->upload('tests/swing.mp4');
$media['video'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => mime_content_type('tests/swing.mp4'), 'caption' => 'test', 'attributes' => [['_' => 'documentAttributeVideo', 'duration' => 5, 'w' => 1280, 'h' => 720]]];
// audio
$inputFile = $MadelineProto->upload('tests/mosconi.mp3');
$media['audio'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
// voice
$media['voice'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
// Document
$time = time();
$inputFile = $MadelineProto->upload('tests/60', 'magic'); // This gets an inputFile object with file name magic
@ -201,5 +192,4 @@ foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
\danog\MadelineProto\Logger::log([$sentMessage], \danog\MadelineProto\Logger::NOTICE);
}
var_dump($MadelineProto->API->get_updates());
var_dump("HERE");
var_dump('HERE');