1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 07:58:58 +01:00

Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-11-03 12:02:33 +00:00 committed by StyleCI Bot
parent e5da891ac2
commit da912540f9
13 changed files with 101 additions and 100 deletions

View File

@ -66,7 +66,7 @@ $message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sem
echo 'Serializing MadelineProto to s.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('s.madeline', $MadelineProto).' bytes'.PHP_EOL;
$sent = [-440592694=>true];
$sent = [-440592694 => true];
$offset = 0;
while (true) {

View File

@ -32,16 +32,16 @@ class API extends APIFactory
$unserialized = file_get_contents($params);
flock($lock, LOCK_UN);
fclose($lock);
$tounserialize = str_replace('O:26:"danog\MadelineProto\Button":', 'O:35:"danog\MadelineProto\TL\Types\Button":', $unserialized);
foreach (['RSA', 'TL\TLMethod', 'TL\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\Types\Button', 'TL\Types\Bytes', 'APIFactory'] as $class) {
class_exists('\danog\MadelineProto\\'.$class);
}
class_exists('\Volatile');
\danog\MadelineProto\Logger::class_exists();
try {
// $unserialized = \danog\Serialization::unserialize($tounserialize);
// $unserialized = \danog\Serialization::unserialize($tounserialize);
$unserialized = unserialize($tounserialize);
} catch (\danog\MadelineProto\Bug74586Exception $e) {
$unserialized = \danog\Serialization::unserialize($tounserialize);
@ -63,9 +63,10 @@ class API extends APIFactory
if ($unserialized === false) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['deserialization_error']);
}
$this->APIFactory();
$this->API = $unserialized->API;
return;
}
$this->API = new MTProto($params);

View File

@ -78,12 +78,12 @@ class MTProto
'updates.getDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates',
'updates.getState' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates',
'upload.getCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.getCdnFileHashes' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.reuploadCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.getFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.saveFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.saveBigFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.getCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.getCdnFileHashes' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.reuploadCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.getFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.saveFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
'upload.saveBigFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info',
];
const BAD_MSG_ERROR_CODES = [
@ -153,7 +153,7 @@ class MTProto
];
const TD_REVERSE = [
'sendMessage'=> 'messages.sendMessage',
'sendMessage' => 'messages.sendMessage',
];
const TD_IGNORE = ['updateMessageID'];
@ -174,7 +174,7 @@ class MTProto
private $msg_ids = [];
private $v = 0;
private $dialog_params = ['_' => 'MadelineProto.dialogParams', 'limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0];
private $dialog_params = ['_' => 'MadelineProto.dialogParams', 'limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0];
private $zero;
private $one;
private $two;
@ -520,35 +520,35 @@ class MTProto
],
'connection_settings' => [ // connection settings
'all' => [ // These settings will be applied on every datacenter that hasn't a custom settings subarray...
'protocol' => 'tcp_full', // can be tcp_full, tcp_abridged, tcp_intermediate, http, https, obfuscated2, udp (unsupported)
'test_mode' => false, // decides whether to connect to the main telegram servers or to the testing servers (deep telegram)
'ipv6' => $this->ipv6, // decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
'timeout' => 2, // timeout for sockets
'proxy' => '\Socket', // The proxy class to use
'proxy_extra' => [], // Extra parameters to pass to the proxy class using setExtra
'protocol' => 'tcp_full', // can be tcp_full, tcp_abridged, tcp_intermediate, http, https, obfuscated2, udp (unsupported)
'test_mode' => false, // decides whether to connect to the main telegram servers or to the testing servers (deep telegram)
'ipv6' => $this->ipv6, // decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
'timeout' => 2, // timeout for sockets
'proxy' => '\Socket', // The proxy class to use
'proxy_extra' => [], // Extra parameters to pass to the proxy class using setExtra
],
],
'app_info' => [ // obtained in https://my.telegram.org
//'api_id' => you should put an API id in the settings array you provide
//'api_hash' => you should put an API hash in the settings array you provide
'device_model' => $device_model,
'system_version' => $system_version,
'app_version' => 'Unicorn', // 🌚
'device_model' => $device_model,
'system_version' => $system_version,
'app_version' => 'Unicorn', // 🌚
// 'app_version' => self::V,
'lang_code' => $lang_code,
'lang_code' => $lang_code,
],
'tl_schema' => [ // TL scheme files
'layer' => 72, // layer version
'src' => [
'mtproto' => __DIR__.'/TL_mtproto_v1.json', // mtproto TL scheme
'telegram' => __DIR__.'/TL_telegram_v72.tl', // telegram TL scheme
'secret' => __DIR__.'/TL_secret.tl', // secret chats TL scheme
'calls' => __DIR__.'/TL_calls.tl', // calls TL scheme
'tl_schema' => [ // TL scheme files
'layer' => 72, // layer version
'src' => [
'mtproto' => __DIR__.'/TL_mtproto_v1.json', // mtproto TL scheme
'telegram' => __DIR__.'/TL_telegram_v72.tl', // telegram TL scheme
'secret' => __DIR__.'/TL_secret.tl', // secret chats TL scheme
'calls' => __DIR__.'/TL_calls.tl', // calls TL scheme
//'td' => __DIR__.'/TL_td.tl', // telegram-cli TL scheme
'botAPI' => __DIR__.'/TL_botAPI.tl', // bot API TL scheme for file ids
'botAPI' => __DIR__.'/TL_botAPI.tl', // bot API TL scheme for file ids
],
],
'logger' => [ // Logger settings
'logger' => [ // Logger settings
/*
* logger modes:
* 0 - No logger
@ -558,38 +558,38 @@ class MTProto
* 4 - Call callable provided in logger_param. logger_param must accept two parameters: array $message, int $level
* $message is an array containing the messages the log, $level, is the logging level
*/
'logger' => 1, // write to
'logger_param' => '/tmp/MadelineProto.log',
'logger' => 3, // overwrite previous setting and echo logs
'logger_level' => Logger::VERBOSE, // Logging level, available logging levels are: ULTRA_VERBOSE, VERBOSE, NOTICE, WARNING, ERROR, FATAL_ERROR. Can be provided as last parameter to the logging function.
'rollbar_token' => 'c07d9b2f73c2461297b0beaef6c1662f',
'logger' => 1, // write to
'logger_param' => '/tmp/MadelineProto.log',
'logger' => 3, // overwrite previous setting and echo logs
'logger_level' => Logger::VERBOSE, // Logging level, available logging levels are: ULTRA_VERBOSE, VERBOSE, NOTICE, WARNING, ERROR, FATAL_ERROR. Can be provided as last parameter to the logging function.
'rollbar_token' => 'c07d9b2f73c2461297b0beaef6c1662f',
//'rollbar_token' => 'f9fff6689aea4905b58eec73f66c791d' // You can provide a token for the rollbar log management system
],
'max_tries' => [
'max_tries' => [
'query' => 5, // How many times should I try to call a method or send an object before throwing an exception
'authorization' => 5, // How many times should I try to generate an authorization key before throwing an exception
'response' => 5, // How many times should I try to get a response of a query before throwing an exception
],
'flood_timeout' => [
'wait_if_lt' => 20, // Sleeps if flood block time is lower than this
'flood_timeout' => [
'wait_if_lt' => 20, // Sleeps if flood block time is lower than this
],
'msg_array_limit' => [ // How big should be the arrays containing the incoming and outgoing messages?
'msg_array_limit' => [ // How big should be the arrays containing the incoming and outgoing messages?
'incoming' => 200,
'outgoing' => 200,
'call_queue' => 200,
],
'peer' => [
'peer' => [
'full_info_cache_time' => 60,
],
'requests' => [
'gzip_encode_if_gt' => 500, // Should I try using gzip encoding for requests bigger than N bytes? Set to -1 to disable.
],
'updates' => [
'handle_updates' => true, // Should I handle updates?
'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter
'updates' => [
'handle_updates' => true, // Should I handle updates?
'callback' => 'get_updates_update_handler', // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter
],
'secret_chats' => [
'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats
'accept_chats' => true, // Should I accept secret chats? Can be true, false or on array of user ids from which to accept chats
],
'threading' => [
'allow_threading' => false, // Should I use threading, if it is enabled?
@ -749,15 +749,15 @@ class MTProto
'layer' => $this->settings['tl_schema']['layer'],
'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'],
'system_lang_code' => $this->settings['app_info']['lang_code'],
'lang_code' => $this->settings['app_info']['lang_code'],
'lang_pack' => '',
'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'],
'system_lang_code' => $this->settings['app_info']['lang_code'],
'lang_code' => $this->settings['app_info']['lang_code'],
'lang_pack' => '',
'query' => $this->serialize_method($method, $arguments),
]
),
],

View File

@ -103,13 +103,13 @@ trait AuthKeyHandler
$new_nonce = $this->random(32);
$data_unserialized = [
'pq' => $pq_bytes,
'p' => $p_bytes,
'q' => $q_bytes,
'nonce' => $nonce,
'server_nonce' => $server_nonce,
'new_nonce' => $new_nonce,
'expires_in' => $expires_in,
'pq' => $pq_bytes,
'p' => $p_bytes,
'q' => $q_bytes,
'nonce' => $nonce,
'server_nonce' => $server_nonce,
'new_nonce' => $new_nonce,
'expires_in' => $expires_in,
];
$p_q_inner_data = $this->serialize_object(['type' => 'p_q_inner_data'.($expires_in < 0 ? '' : '_temp')], $data_unserialized, 'p_q_inner_data');
@ -282,10 +282,10 @@ trait AuthKeyHandler
$data = $this->serialize_object(
['type' => 'client_DH_inner_data'],
[
'nonce' => $nonce,
'server_nonce' => $server_nonce,
'retry_id' => $retry_id,
'g_b' => $g_b_str,
'nonce' => $nonce,
'server_nonce' => $server_nonce,
'retry_id' => $retry_id,
'g_b' => $g_b_str,
], 'client_DH_inner_data'
);
@ -318,9 +318,9 @@ trait AuthKeyHandler
$Set_client_DH_params_answer = $this->method_call(
'set_client_DH_params',
[
'nonce' => $nonce,
'server_nonce' => $server_nonce,
'encrypted_data' => $encrypted_data,
'nonce' => $nonce,
'server_nonce' => $server_nonce,
'encrypted_data' => $encrypted_data,
],
['datacenter' => $datacenter]
@ -531,11 +531,11 @@ trait AuthKeyHandler
$temp_session_id = $this->datacenter->sockets[$datacenter]->session_id;
$message_data = $this->serialize_object(['type' => 'bind_auth_key_inner'],
[
'nonce' => $nonce,
'temp_auth_key_id' => $temp_auth_key_id,
'perm_auth_key_id' => $perm_auth_key_id,
'temp_session_id' => $temp_session_id,
'expires_at' => $expires_at,
'nonce' => $nonce,
'temp_auth_key_id' => $temp_auth_key_id,
'perm_auth_key_id' => $perm_auth_key_id,
'temp_session_id' => $temp_session_id,
'expires_at' => $expires_at,
], 'bind_temp_auth_key_inner'
);
$message_id = $this->generate_message_id($datacenter);

View File

@ -214,7 +214,7 @@ trait PeerHandler
return $this->gen_all($this->chats[$id]);
}
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) {
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http'=> [
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => [
'timeout' => 2,
],
])), true);

View File

@ -58,6 +58,6 @@ class Serialization
*/
public static function deserialize($filename, $no_updates = false)
{
throw new \danog\MadelineProto\Exception('You can\'t call \danog\MadelineProto\Serialization::deserialize($filename) anymore, use new \danog\MadelineProto\API($filename) instead'.PHP_EOL.PHP_EOL."Protip: run the following command to fix all of your scripts:".PHP_EOL.PHP_EOL."find . -type f -exec sed 's/\\\\danog\\\\MadelineProto\\\\Serialization::deserialize/new \\\\danog\\\\MadelineProto\\\\API/g' -i {} +".PHP_EOL.PHP_EOL, 0, null, 'MadelineProto', 0);
throw new \danog\MadelineProto\Exception('You can\'t call \danog\MadelineProto\Serialization::deserialize($filename) anymore, use new \danog\MadelineProto\API($filename) instead'.PHP_EOL.PHP_EOL.'Protip: run the following command to fix all of your scripts:'.PHP_EOL.PHP_EOL."find . -type f -exec sed 's/\\\\danog\\\\MadelineProto\\\\Serialization::deserialize/new \\\\danog\\\\MadelineProto\\\\API/g' -i {} +".PHP_EOL.PHP_EOL, 0, null, 'MadelineProto', 0);
}
}

View File

@ -108,7 +108,7 @@ trait TD
if (isset($params['fwd_from'])) {
$newparams[$td] = ['_' => 'messageForwardedFromUser'];
if (isset($params['fwd_from']['channel_id'])) {
$newparams[$td] = ['_'=> 'messageForwardedPost', 'chat_id' => '-100'.$params['fwd_from']['channel_id']];
$newparams[$td] = ['_' => 'messageForwardedPost', 'chat_id' => '-100'.$params['fwd_from']['channel_id']];
}
$newparams[$td]['date'] = $params['fwd_from']['date'];
if (isset($params['fwd_from']['channel_post'])) {

View File

@ -139,15 +139,15 @@ trait AuthKeyHandler
$this->calls[$params['id']]->configuration['shared_config'] = array_merge($this->method_call('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc]), $this->calls[$params['id']]->configuration['shared_config']);
$this->calls[$params['id']]->configuration['endpoints'] = array_merge([$res['connection']], $res['alternative_connections'], $this->calls[$params['id']]->configuration['endpoints']);
$this->calls[$params['id']]->configuration = array_merge([
'recv_timeout' => $this->config['call_receive_timeout_ms'] / 1000,
'init_timeout' => $this->config['call_connect_timeout_ms'] / 1000,
'data_saving' => \danog\MadelineProto\VoIP::DATA_SAVING_NEVER,
'enable_NS' => true,
'enable_AEC' => true,
'enable_AGC' => true,
'recv_timeout' => $this->config['call_receive_timeout_ms'] / 1000,
'init_timeout' => $this->config['call_connect_timeout_ms'] / 1000,
'data_saving' => \danog\MadelineProto\VoIP::DATA_SAVING_NEVER,
'enable_NS' => true,
'enable_AEC' => true,
'enable_AGC' => true,
'auth_key' => $key,
'network_type' => \danog\MadelineProto\VoIP::NET_TYPE_ETHERNET,
'auth_key' => $key,
'network_type' => \danog\MadelineProto\VoIP::NET_TYPE_ETHERNET,
], $this->calls[$params['id']]->configuration);
$this->calls[$params['id']]->parseConfig();
$res = $this->calls[$params['id']]->startTheMagic();
@ -199,15 +199,15 @@ trait AuthKeyHandler
$this->calls[$params['id']]->configuration['endpoints'] = array_merge([$params['connection']], $params['alternative_connections'], $this->calls[$params['id']]->configuration['endpoints']);
$this->calls[$params['id']]->configuration = array_merge([
'recv_timeout' => $this->config['call_receive_timeout_ms'] / 1000,
'init_timeout' => $this->config['call_connect_timeout_ms'] / 1000,
'data_saving' => \danog\MadelineProto\VoIP::DATA_SAVING_NEVER,
'enable_NS' => true,
'enable_AEC' => true,
'enable_AGC' => true,
'recv_timeout' => $this->config['call_receive_timeout_ms'] / 1000,
'init_timeout' => $this->config['call_connect_timeout_ms'] / 1000,
'data_saving' => \danog\MadelineProto\VoIP::DATA_SAVING_NEVER,
'enable_NS' => true,
'enable_AEC' => true,
'enable_AGC' => true,
'auth_key' => $key,
'network_type' => \danog\MadelineProto\VoIP::NET_TYPE_ETHERNET,
'auth_key' => $key,
'network_type' => \danog\MadelineProto\VoIP::NET_TYPE_ETHERNET,
], $this->calls[$params['id']]->configuration);
var_dump($this->calls[$params['id']]->configuration);
$this->calls[$params['id']]->parseConfig();

View File

@ -22,7 +22,7 @@ trait DialogHandler
!isset($this->dialog_params['offset_peer']) || is_null($this->dialog_params['offset_peer']) ||
!isset($this->dialog_params['count']) || is_null($this->dialog_params['count'])
) {
$this->dialog_params = ['limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0];
$this->dialog_params = ['limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0];
}
$this->updates_state['sync_loading'] = true;
$res = ['dialogs' => [0], 'count' => 1];

View File

@ -45,9 +45,9 @@ trait Login
$this->authorization = $this->method_call(
'auth.importBotAuthorization',
[
'bot_auth_token' => $token,
'api_id' => $this->settings['app_info']['api_id'],
'api_hash' => $this->settings['app_info']['api_hash'],
'bot_auth_token' => $token,
'api_id' => $this->settings['app_info']['api_id'],
'api_hash' => $this->settings['app_info']['api_hash'],
], ['datacenter' => $this->datacenter->curdc]
);
$this->authorized = self::LOGGED_IN;

View File

@ -13,7 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
require '../vendor/autoload.php';
$settings = [];
$settings = ['app_info'=>['api_id'=>6, 'api_hash'=>'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$MadelineProto = false;
try {

View File

@ -12,7 +12,7 @@ If not, see <http://www.gnu.org/licenses/>.
*/
require '../vendor/autoload.php';
$settings = ['app_info'=>['api_id'=>6, 'api_hash'=>'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$MadelineProto = false;
$uMadelineProto = false;

View File

@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with Mad
If not, see <http://www.gnu.org/licenses/>.
*/
require '../vendor/autoload.php';
$settings = ['app_info'=>['api_id'=>6, 'api_hash'=>'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
include_once 'token.php';
try {