Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-02-11 14:18:18 +00:00 committed by StyleCI Bot
parent f7f37c0888
commit 7a05342e47
11 changed files with 200 additions and 152 deletions

View File

@ -34,32 +34,46 @@ if ($uMadelineProto === false) {
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $uMadelineProto).' bytes'.PHP_EOL;
}
function inputify(&$stuff) {
function inputify(&$stuff)
{
$stuff['_'] = 'input'.ucfirst($stuff['_']);
return $stuff;
}
function translatetext (&$value) {
function translatetext(&$value)
{
inputify($value);
if (isset($value['entities'])) {
foreach ($value['entities'] as &$entity) {
if ($entity['_'] === 'messageEntityMentionName') inputify($entity);
if ($entity['_'] === 'messageEntityMentionName') {
inputify($entity);
}
}
}
if (isset($value['geo'])) {
$value['geo_point'] = inputify($value['geo']);
}
}
function translate (&$value, $key) {
function translate(&$value, $key)
{
switch ($value['_']) {
case 'botInlineResult':
$value['_'] = 'inputBotInlineResult';
translatetext($value['send_message']);
return $value;
case 'botInlineMediaResult':
if (isset($value['game'])) throw new \danog\MadelineProto\RPCErrorException('Games are not supported.');
if (isset($value['photo'])) $value['_'] = 'inputBotInlineResultPhoto';
if (isset($value['document'])) $value['_'] = 'inputBotInlineResultDocument';
if (isset($value['game'])) {
throw new \danog\MadelineProto\RPCErrorException('Games are not supported.');
}
if (isset($value['photo'])) {
$value['_'] = 'inputBotInlineResultPhoto';
}
if (isset($value['document'])) {
$value['_'] = 'inputBotInlineResultDocument';
}
translatetext($value['send_message']);
return $value;
}
}
@ -114,9 +128,10 @@ var_dump($update);
} else {
$toset = ['query_id' => $update['update']['query_id'], 'results' => [], 'cache_time' => 0, 'private' => true];
if (preg_match('|\$\s*$|', $update['update']['query'])) {
$exploded = explode('|', preg_replace('/\$\s*$/', '', $update['update']['query']));
array_walk($exploded, function (&$value, $key) { $value = preg_replace(['/^\s+/', '/\s+$/'], '', $value); });
array_walk($exploded, function (&$value, $key) {
$value = preg_replace(['/^\s+/', '/\s+$/'], '', $value);
});
$query = array_shift($exploded);
foreach ($exploded as $current => $botq) {
$bot = preg_replace('|:.*|', '', $botq);
@ -143,8 +158,12 @@ var_dump($update);
}
}
}
if (!isset($toset['results'][0])) $toset['results'] = $results['results'];
if (count($exploded) - 1 === $current || !isset($toset['results'][0]['send_message']['message'])) break;
if (!isset($toset['results'][0])) {
$toset['results'] = $results['results'];
}
if (count($exploded) - 1 === $current || !isset($toset['results'][0]['send_message']['message'])) {
break;
}
$query = $toset['results'][0]['send_message']['message'];
}
}
@ -160,23 +179,27 @@ var_dump($update);
try {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
} catch (\danog\MadelineProto\Exception $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
try {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
}
}
}

View File

@ -203,6 +203,7 @@ class Connection
case 'tcp_intermediate':
$packet_length_data = $this->read(4);
$packet_length = \danog\PHP\Struct::unpack('<I', $packet_length_data)[0];
return $this->read($packet_length);
case 'tcp_abridged':
$packet_length_data = $this->read(1);
@ -213,6 +214,7 @@ class Connection
$packet_length_data = $this->read(3);
$packet_length = \danog\PHP\Struct::unpack('<I', $packet_length_data.pack('x'))[0] << 2;
}
return $this->read($packet_length);
case 'http':
case 'https':
@ -245,6 +247,7 @@ class Connection
if ($close) {
$this->close_and_reopen();
}
return $read;
case 'udp':
throw new Exception("Connection: This protocol wasn't implemented yet.");

View File

@ -341,7 +341,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
unset($this->config['dc_options']);
\danog\MadelineProto\Logger::log(['Updated config!', $this->config], Logger::NOTICE);
}
public function parse_dc_options($dc_options) {
public function parse_dc_options($dc_options)
{
foreach ($dc_options as $dc) {
$test = $this->config['test_mode'] ? 'test' : 'main';
$ipv6 = ($dc['ipv6'] ? 'ipv6' : 'ipv4');

View File

@ -32,6 +32,7 @@ trait Crypt
$cipher = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_IGE);
$cipher->setKey($key);
$cipher->setIV($iv);
return $cipher->encrypt($message);
}
@ -40,6 +41,7 @@ trait Crypt
$cipher = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_IGE);
$cipher->setKey($key);
$cipher->setIV($iv);
return $cipher->decrypt($message);
}
}

View File

@ -262,6 +262,7 @@ trait PeerHandler
return $res;
}
public function full_chat_last_updated($id)
{
$id = $this->get_info($id)['bot_api_id'];

View File

@ -111,15 +111,21 @@ trait UpdateHandler
$this->get_channel_state($channel)['pts'] = $data['pts'];
}
}
public function get_msg_id($peer) {
public function get_msg_id($peer)
{
$id = $this->get_info($peer)['bot_api_id'];
return isset($this->msg_ids[$id]) ? $this->msg_ids[$id] : false;
}
public function set_msg_id($peer, $msg_id) {
public function set_msg_id($peer, $msg_id)
{
$id = $this->get_info($peer)['bot_api_id'];
$this->msg_ids[$id] = $msg_id;
$this->should_serialize = true;
}
public function get_channel_difference($channel)
{
if (!$this->settings['updates']['handle_updates']) {
@ -468,6 +474,7 @@ trait UpdateHandler
if ($update['_'] === 'updateDcOptions') {
\danog\MadelineProto\Logger::log(['Got new dc options'], \danog\MadelineProto\Logger::VERBOSE);
$this->parse_dc_options($update['dc_options']);
return;
}
if (!$this->settings['updates']['handle_updates']) {

View File

@ -42,15 +42,19 @@ class Serialization
*
* @param string $filename
*
* @return API
*
* @throws \danog\MadelineProto\Exception
*
* @return API
*/
public static function deserialize($filename)
{
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
if (file_exists($filename)) $unserialized = unserialize(file_get_contents($filename)); else throw new Exception('File does not exist');
if (file_exists($filename)) {
$unserialized = unserialize(file_get_contents($filename));
} else {
throw new Exception('File does not exist');
}
//if ($unserialized === false) throw new Exception('An error occurred on deserialization');
return $unserialized;
}

View File

@ -28,6 +28,7 @@ class Stream
{
$d = substr($this->string, $this->pos, $length);
$this->pos += $length;
return $d;
}
}

View File

@ -18,9 +18,12 @@ namespace danog\MadelineProto\Threads;
class SocketHandler extends Threaded
{
public $payloads = [];
public function __construct(&$me) {
public function __construct(&$me)
{
$this->API = $me;
}
/**
* Reading connection and receiving message from server. Check the CRC32.
*/
@ -107,6 +110,5 @@ class SocketHandler extends Threaded
}
}
}, $this);
}
}

View File

@ -17,9 +17,11 @@ namespace danog\MadelineProto\Threads;
*/
class SocketReader extends Threaded
{
public function __construct(&$me) {
public function __construct(&$me)
{
$this->API = $me;
}
/**
* Reading connection and receiving message from server. Check the CRC32.
*/
@ -31,6 +33,7 @@ class SocketReader extends Threaded
$thread->payloads[] = $payload;
$thread->notify();
}, $this->API->socket_handler, $payload);
} catch (\danog\MadelineProto\NothingInTheSocketException $e) { ; };
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
}
}
}