Apply fixes from StyleCI
This commit is contained in:
parent
aaa5177607
commit
fde7307f1d
2
bot.php
2
bot.php
@ -13,7 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
|||||||
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
|
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];//, 'connection_settings' => ['all' => ['test_mode' => true]]];
|
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']]; //, 'connection_settings' => ['all' => ['test_mode' => true]]];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline');
|
||||||
|
@ -84,7 +84,7 @@ if (!extension_loaded('pthreads')) {
|
|||||||
}
|
}
|
||||||
$errno = 0;
|
$errno = 0;
|
||||||
$errstr = '';
|
$errstr = '';
|
||||||
$this->sock = fsockopen($this->protocol.'://'.$address, $port, $errno, $errstr, $this->timeout['sec'] + ($this->timeout['usec']/1000000));
|
$this->sock = fsockopen($this->protocol.'://'.$address, $port, $errno, $errstr, $this->timeout['sec'] + ($this->timeout['usec'] / 1000000));
|
||||||
stream_set_timeout($this->sock, $this->timeout['sec'], $this->timeout['usec']);
|
stream_set_timeout($this->sock, $this->timeout['sec'], $this->timeout['usec']);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -66,43 +66,42 @@ class DataCenter
|
|||||||
$x = 0;
|
$x = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
$ipv6 = $this->settings[$dc_config_number]['ipv6'] ? 'ipv6' : 'ipv4';
|
||||||
|
|
||||||
$ipv6 = $this->settings[$dc_config_number]['ipv6'] ? 'ipv6' : 'ipv4';
|
if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) {
|
||||||
|
unset($this->sockets[$dc_number]);
|
||||||
|
|
||||||
|
return false;
|
||||||
if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) {
|
|
||||||
unset($this->sockets[$dc_number]);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$address = $this->dclist[$test][$ipv6][$dc_number]['ip_address'];
|
|
||||||
$port = $this->dclist[$test][$ipv6][$dc_number]['port'];
|
|
||||||
|
|
||||||
if (isset($this->dclist[$test][$ipv6][$dc_number]['tcpo_only']) && $this->dclist[$test][$ipv6][$dc_number]['tcpo_only']) {
|
|
||||||
if ($dc_config_number === 'all') {
|
|
||||||
$dc_config_number = $dc_number;
|
|
||||||
}
|
}
|
||||||
if (!isset($this->settings[$dc_config_number])) {
|
$address = $this->dclist[$test][$ipv6][$dc_number]['ip_address'];
|
||||||
$this->settings[$dc_config_number] = $this->settings['all'];
|
$port = $this->dclist[$test][$ipv6][$dc_number]['port'];
|
||||||
}
|
|
||||||
$this->settings[$dc_config_number]['protocol'] = 'obfuscated2';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->settings[$dc_config_number]['protocol'] === 'https') {
|
if (isset($this->dclist[$test][$ipv6][$dc_number]['tcpo_only']) && $this->dclist[$test][$ipv6][$dc_number]['tcpo_only']) {
|
||||||
$subdomain = $this->dclist['ssl_subdomains'][$dc_number];
|
if ($dc_config_number === 'all') {
|
||||||
$path = $this->settings[$dc_config_number]['test_mode'] ? 'apiw_test1' : 'apiw1';
|
$dc_config_number = $dc_number;
|
||||||
$address = $this->settings[$dc_config_number]['protocol'].'://'.$subdomain.'.web.telegram.org/'.$path;
|
}
|
||||||
}
|
if (!isset($this->settings[$dc_config_number])) {
|
||||||
|
$this->settings[$dc_config_number] = $this->settings['all'];
|
||||||
if ($this->settings[$dc_config_number]['protocol'] === 'http') {
|
}
|
||||||
if ($ipv6) {
|
$this->settings[$dc_config_number]['protocol'] = 'obfuscated2';
|
||||||
$address = '['.$address.']';
|
|
||||||
}
|
}
|
||||||
$address = $this->settings[$dc_config_number]['protocol'].'://'.$address.'/api';
|
|
||||||
}
|
if ($this->settings[$dc_config_number]['protocol'] === 'https') {
|
||||||
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['dc_con_test_start'], $dc_number, $test, $ipv6, $this->settings[$dc_config_number]['protocol'])], \danog\MadelineProto\Logger::VERBOSE);
|
$subdomain = $this->dclist['ssl_subdomains'][$dc_number];
|
||||||
|
$path = $this->settings[$dc_config_number]['test_mode'] ? 'apiw_test1' : 'apiw1';
|
||||||
|
$address = $this->settings[$dc_config_number]['protocol'].'://'.$subdomain.'.web.telegram.org/'.$path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->settings[$dc_config_number]['protocol'] === 'http') {
|
||||||
|
if ($ipv6) {
|
||||||
|
$address = '['.$address.']';
|
||||||
|
}
|
||||||
|
$address = $this->settings[$dc_config_number]['protocol'].'://'.$address.'/api';
|
||||||
|
}
|
||||||
|
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['dc_con_test_start'], $dc_number, $test, $ipv6, $this->settings[$dc_config_number]['protocol'])], \danog\MadelineProto\Logger::VERBOSE);
|
||||||
foreach (array_unique([$port, 443, 80, 88]) as $port) {
|
foreach (array_unique([$port, 443, 80, 88]) as $port) {
|
||||||
\danog\MadelineProto\Logger::log(['Trying connection on port '.$port.'...'], \danog\MadelineProto\Logger::WARNING);
|
\danog\MadelineProto\Logger::log(['Trying connection on port '.$port.'...'], \danog\MadelineProto\Logger::WARNING);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isset($this->sockets[$dc_number]->old)) {
|
if (isset($this->sockets[$dc_number]->old)) {
|
||||||
$this->sockets[$dc_number]->__construct($this->settings[$dc_config_number]['proxy'], $this->settings[$dc_config_number]['proxy_extra'], $address, $port, $this->settings[$dc_config_number]['protocol'], $this->settings[$dc_config_number]['timeout'], $this->settings[$dc_config_number]['ipv6']);
|
$this->sockets[$dc_number]->__construct($this->settings[$dc_config_number]['proxy'], $this->settings[$dc_config_number]['proxy_extra'], $address, $port, $this->settings[$dc_config_number]['protocol'], $this->settings[$dc_config_number]['timeout'], $this->settings[$dc_config_number]['ipv6']);
|
||||||
@ -111,6 +110,7 @@ class DataCenter
|
|||||||
$this->sockets[$dc_number] = new Connection($this->settings[$dc_config_number]['proxy'], $this->settings[$dc_config_number]['proxy_extra'], $address, $port, $this->settings[$dc_config_number]['protocol'], $this->settings[$dc_config_number]['timeout'], $this->settings[$dc_config_number]['ipv6']);
|
$this->sockets[$dc_number] = new Connection($this->settings[$dc_config_number]['proxy'], $this->settings[$dc_config_number]['proxy_extra'], $address, $port, $this->settings[$dc_config_number]['protocol'], $this->settings[$dc_config_number]['timeout'], $this->settings[$dc_config_number]['ipv6']);
|
||||||
}
|
}
|
||||||
\danog\MadelineProto\Logger::log(['OK!'], \danog\MadelineProto\Logger::WARNING);
|
\danog\MadelineProto\Logger::log(['OK!'], \danog\MadelineProto\Logger::WARNING);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||||
|
@ -601,7 +601,7 @@ trait AuthKeyHandler
|
|||||||
$config = $this->method_call('help.getConfig', [], ['datacenter' => $id]);
|
$config = $this->method_call('help.getConfig', [], ['datacenter' => $id]);
|
||||||
$this->sync_authorization($id);
|
$this->sync_authorization($id);
|
||||||
$this->get_config($config);
|
$this->get_config($config);
|
||||||
} else if ($socket->temp_auth_key === null) {
|
} elseif ($socket->temp_auth_key === null) {
|
||||||
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id)], \danog\MadelineProto\Logger::NOTICE);
|
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id)], \danog\MadelineProto\Logger::NOTICE);
|
||||||
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
|
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
|
||||||
}
|
}
|
||||||
@ -611,7 +611,7 @@ trait AuthKeyHandler
|
|||||||
$config = $this->method_call('help.getConfig', [], ['datacenter' => $id]);
|
$config = $this->method_call('help.getConfig', [], ['datacenter' => $id]);
|
||||||
$this->sync_authorization($id);
|
$this->sync_authorization($id);
|
||||||
$this->get_config($config);
|
$this->get_config($config);
|
||||||
} else if ($socket->temp_auth_key === null) {
|
} elseif ($socket->temp_auth_key === null) {
|
||||||
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id)], \danog\MadelineProto\Logger::NOTICE);
|
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id)], \danog\MadelineProto\Logger::NOTICE);
|
||||||
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
|
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ trait CallHandler
|
|||||||
'system_lang_code' => $this->settings['app_info']['lang_code'],
|
'system_lang_code' => $this->settings['app_info']['lang_code'],
|
||||||
'lang_code' => $this->settings['app_info']['lang_code'],
|
'lang_code' => $this->settings['app_info']['lang_code'],
|
||||||
'lang_pack' => '',
|
'lang_pack' => '',
|
||||||
'query' => $serialized
|
'query' => $serialized,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
@ -271,7 +271,9 @@ trait CallHandler
|
|||||||
throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.' ('.$last_error.').');
|
throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.' ('.$last_error.').');
|
||||||
}
|
}
|
||||||
\danog\MadelineProto\Logger::log(['Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
\danog\MadelineProto\Logger::log(['Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||||
if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] === false)) $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] = true;
|
if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] === false)) {
|
||||||
|
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id] = [];
|
$this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id] = [];
|
||||||
if (isset($message_chunks) && count($message_chunks)) {
|
if (isset($message_chunks) && count($message_chunks)) {
|
||||||
|
@ -413,6 +413,7 @@ trait Files
|
|||||||
$data = substr($data, $this->cdn_hashes[$file][$offset]['limit']);
|
$data = substr($data, $this->cdn_hashes[$file][$offset]['limit']);
|
||||||
$offset += $this->cdn_hashes[$file][$offset]['limit'];
|
$offset += $this->cdn_hashes[$file][$offset]['limit'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,9 @@ trait ResponseHandler
|
|||||||
case 'Updates':
|
case 'Updates':
|
||||||
unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]);
|
unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]);
|
||||||
$unset = true;
|
$unset = true;
|
||||||
if (strpos($datacenter, 'cdn') === false) $this->handle_updates($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']);
|
if (strpos($datacenter, 'cdn') === false) {
|
||||||
|
$this->handle_updates($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']);
|
||||||
|
}
|
||||||
$only_updates = true && $only_updates;
|
$only_updates = true && $only_updates;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -221,7 +221,6 @@ $message = 'yay';
|
|||||||
$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 = $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
|
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||||
|
|
||||||
|
|
||||||
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||||
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
|
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
|
||||||
\danog\MadelineProto\Logger::log([$sentMessage], \danog\MadelineProto\Logger::NOTICE);
|
\danog\MadelineProto\Logger::log([$sentMessage], \danog\MadelineProto\Logger::NOTICE);
|
||||||
|
Loading…
Reference in New Issue
Block a user