Apply fixes from StyleCI
This commit is contained in:
parent
1e3ec54ce8
commit
6c84ada369
2
bot.php
2
bot.php
@ -65,7 +65,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]];;
|
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]];
|
||||||
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
||||||
|
|
||||||
|
@ -114,7 +114,9 @@ class HttpProxy implements \danog\MadelineProto\Proxy
|
|||||||
{
|
{
|
||||||
list($protocol, $code, $description) = explode(' ', $this->read_http_line(), 3);
|
list($protocol, $code, $description) = explode(' ', $this->read_http_line(), 3);
|
||||||
list($protocol, $protocol_version) = explode('/', $protocol);
|
list($protocol, $protocol_version) = explode('/', $protocol);
|
||||||
if ($protocol !== 'HTTP') throw new \danog\MadelineProto\Exception('Wrong protocol');
|
if ($protocol !== 'HTTP') {
|
||||||
|
throw new \danog\MadelineProto\Exception('Wrong protocol');
|
||||||
|
}
|
||||||
$code = (int) $code;
|
$code = (int) $code;
|
||||||
$headers = [];
|
$headers = [];
|
||||||
while (strlen($current_header = $this->read_http_line())) {
|
while (strlen($current_header = $this->read_http_line())) {
|
||||||
|
@ -120,9 +120,12 @@ If not, see <http://www.gnu.org/licenses/>.
|
|||||||
$packet = '';
|
$packet = '';
|
||||||
while (strlen($packet) < $length) {
|
while (strlen($packet) < $length) {
|
||||||
$read = stream_get_contents($this->sock, $length - strlen($packet));
|
$read = stream_get_contents($this->sock, $length - strlen($packet));
|
||||||
if ($read === false || strlen($read) === 0) throw new \danog\MadelineProto\NothingInTheSocketException();
|
if ($read === false || strlen($read) === 0) {
|
||||||
|
throw new \danog\MadelineProto\NothingInTheSocketException();
|
||||||
|
}
|
||||||
$packet .= $read;
|
$packet .= $read;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $packet;
|
return $packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +139,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
$wrote = 0;
|
$wrote = 0;
|
||||||
if (($wrote += fwrite($this->sock, $buffer, $length)) !== $length) {
|
if (($wrote += fwrite($this->sock, $buffer, $length)) !== $length) {
|
||||||
while (($wrote += fwrite($this->sock, substr($buffer, $wrote), $length-$wrote)) !== $length) {
|
while (($wrote += fwrite($this->sock, substr($buffer, $wrote), $length - $wrote)) !== $length) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,9 +285,12 @@ if (!extension_loaded('pthreads')) {
|
|||||||
$packet = '';
|
$packet = '';
|
||||||
while (strlen($packet) < $length) {
|
while (strlen($packet) < $length) {
|
||||||
$read = socket_read($this->sock, $length - strlen($packet), $flags);
|
$read = socket_read($this->sock, $length - strlen($packet), $flags);
|
||||||
if ($read === false || strlen($read) === false) throw new \danog\MadelineProto\NothingInTheSocketException();
|
if ($read === false || strlen($read) === false) {
|
||||||
|
throw new \danog\MadelineProto\NothingInTheSocketException();
|
||||||
|
}
|
||||||
$packet .= $read;
|
$packet .= $read;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $packet;
|
return $packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +304,7 @@ if (!extension_loaded('pthreads')) {
|
|||||||
|
|
||||||
$wrote = 0;
|
$wrote = 0;
|
||||||
if (($wrote += socket_write($this->sock, $buffer, $length)) !== $length) {
|
if (($wrote += socket_write($this->sock, $buffer, $length)) !== $length) {
|
||||||
while (($wrote += socket_write($this->sock, substr($buffer, $wrote), $length-$wrote)) !== $length) {
|
while (($wrote += socket_write($this->sock, substr($buffer, $wrote), $length - $wrote)) !== $length) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,39 +33,51 @@ class SocksProxy implements \danog\MadelineProto\Proxy
|
|||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->protocol = $protocol;
|
$this->protocol = $protocol;
|
||||||
}
|
}
|
||||||
public function setExtra(array $extra = []) {
|
|
||||||
|
public function setExtra(array $extra = [])
|
||||||
|
{
|
||||||
$this->extra = $extra;
|
$this->extra = $extra;
|
||||||
$name = $this->protocol === PHP_INT_MAX ? '\\FSocket' : '\\Socket';
|
$name = $this->protocol === PHP_INT_MAX ? '\\FSocket' : '\\Socket';
|
||||||
$this->sock = new $name(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, $this->protocol);
|
$this->sock = new $name(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, $this->protocol);
|
||||||
}
|
}
|
||||||
public function setOption(int $level, int $name, $value) {
|
|
||||||
|
public function setOption(int $level, int $name, $value)
|
||||||
|
{
|
||||||
return $this->sock->setOption($level, $name, $value);
|
return $this->sock->setOption($level, $name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOption(int $level, int $name) {
|
public function getOption(int $level, int $name)
|
||||||
|
{
|
||||||
return $this->sock->getOption($level, $name);
|
return $this->sock->getOption($level, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlocking(bool $blocking) {
|
public function setBlocking(bool $blocking)
|
||||||
|
{
|
||||||
return $this->sock->setBlocking($blocking);
|
return $this->sock->setBlocking($blocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bind(string $address, int $port = 0) {
|
public function bind(string $address, int $port = 0)
|
||||||
|
{
|
||||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listen(int $backlog = 0) {
|
public function listen(int $backlog = 0)
|
||||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
{
|
||||||
}
|
|
||||||
public function accept() {
|
|
||||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function accept()
|
||||||
|
{
|
||||||
|
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||||
|
}
|
||||||
|
|
||||||
public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0) {
|
public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0)
|
||||||
|
{
|
||||||
return $this->sock->select($read, $write, $except, $tv_sec, $tv_usec);
|
return $this->sock->select($read, $write, $except, $tv_sec, $tv_usec);
|
||||||
}
|
}
|
||||||
public function connect(string $address, int $port = 0) {
|
|
||||||
|
public function connect(string $address, int $port = 0)
|
||||||
|
{
|
||||||
$this->sock->connect($this->extra['address'], $this->extra['port']);
|
$this->sock->connect($this->extra['address'], $this->extra['port']);
|
||||||
|
|
||||||
$methods = chr(0);
|
$methods = chr(0);
|
||||||
@ -92,17 +104,18 @@ class SocksProxy implements \danog\MadelineProto\Proxy
|
|||||||
if ($result !== 0) {
|
if ($result !== 0) {
|
||||||
throw new \danog\MadelineProto\Exception("Wrong authorization status: $version");
|
throw new \danog\MadelineProto\Exception("Wrong authorization status: $version");
|
||||||
}
|
}
|
||||||
} else if ($method !== 0) {
|
} elseif ($method !== 0) {
|
||||||
throw new \danog\MadelineProto\Exception("Wrong method: $method");
|
throw new \danog\MadelineProto\Exception("Wrong method: $method");
|
||||||
}
|
}
|
||||||
$payload = pack("C3", 0x05, 0x01, 0x00);
|
$payload = pack('C3', 0x05, 0x01, 0x00);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$ip = inet_pton($address);
|
$ip = inet_pton($address);
|
||||||
$payload .= pack("C1", strlen($ip) === 4 ? 0x01 : 0x04).$ip;
|
$payload .= pack('C1', strlen($ip) === 4 ? 0x01 : 0x04).$ip;
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
$payload .= pack("C2", 0x03, strlen($address)).$address;
|
$payload .= pack('C2', 0x03, strlen($address)).$address;
|
||||||
}
|
}
|
||||||
$payload .= pack("n", $port);
|
$payload .= pack('n', $port);
|
||||||
$this->sock->write($payload);
|
$this->sock->write($payload);
|
||||||
|
|
||||||
$version = ord($this->sock->read(1));
|
$version = ord($this->sock->read(1));
|
||||||
@ -130,37 +143,49 @@ class SocksProxy implements \danog\MadelineProto\Proxy
|
|||||||
$ip = $this->sock->read(ord($this->sock->read(1)));
|
$ip = $this->sock->read(ord($this->sock->read(1)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$port = unpack("n", $this->sock->read(2))[1];
|
$port = unpack('n', $this->sock->read(2))[1];
|
||||||
\danog\MadelineProto\Logger::log(['Connected to '.$ip.':'.$port.' via socks5']);
|
\danog\MadelineProto\Logger::log(['Connected to '.$ip.':'.$port.' via socks5']);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public function read(int $length, int $flags = 0) {
|
|
||||||
|
public function read(int $length, int $flags = 0)
|
||||||
|
{
|
||||||
return $this->sock->read($length, $flags);
|
return $this->sock->read($length, $flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(string $buffer, int $length = -1) {
|
public function write(string $buffer, int $length = -1)
|
||||||
|
{
|
||||||
return $this->sock->write($buffer, $length);
|
return $this->sock->write($buffer, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send(string $data, int $length, int $flags) {
|
public function send(string $data, int $length, int $flags)
|
||||||
|
{
|
||||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close() {
|
public function close()
|
||||||
|
{
|
||||||
$this->sock->close();
|
$this->sock->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPeerName(bool $port = true) {
|
public function getPeerName(bool $port = true)
|
||||||
|
{
|
||||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSockName(bool $port = true) {
|
public function getSockName(bool $port = true)
|
||||||
|
{
|
||||||
throw new \danog\MadelineProto\Exception('Not Implemented');
|
throw new \danog\MadelineProto\Exception('Not Implemented');
|
||||||
}
|
}
|
||||||
public function getProxyHeaders() {
|
|
||||||
|
public function getProxyHeaders()
|
||||||
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
public function getResource() {
|
|
||||||
|
public function getResource()
|
||||||
|
{
|
||||||
return $this->sock->getResource();
|
return $this->sock->getResource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,9 @@ class Connection
|
|||||||
{
|
{
|
||||||
list($protocol, $code, $description) = explode(' ', $this->read_http_line(), 3);
|
list($protocol, $code, $description) = explode(' ', $this->read_http_line(), 3);
|
||||||
list($protocol, $protocol_version) = explode('/', $protocol);
|
list($protocol, $protocol_version) = explode('/', $protocol);
|
||||||
if ($protocol !== 'HTTP') throw new \danog\MadelineProto\Exception('Wrong protocol');
|
if ($protocol !== 'HTTP') {
|
||||||
|
throw new \danog\MadelineProto\Exception('Wrong protocol');
|
||||||
|
}
|
||||||
$code = (int) $code;
|
$code = (int) $code;
|
||||||
$headers = [];
|
$headers = [];
|
||||||
while (strlen($current_header = $this->read_http_line())) {
|
while (strlen($current_header = $this->read_http_line())) {
|
||||||
|
@ -100,9 +100,9 @@ class DataCenter
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\danog\MadelineProto\Exception $e) {
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
\danog\MadelineProto\Logger::log("Connection failed: ".$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
|
\danog\MadelineProto\Logger::log('Connection failed: '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
|
||||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||||
\danog\MadelineProto\Logger::log("Connection failed: read timeout", \danog\MadelineProto\Logger::ERROR);
|
\danog\MadelineProto\Logger::log('Connection failed: read timeout', \danog\MadelineProto\Logger::ERROR);
|
||||||
}
|
}
|
||||||
if (isset($this->settings[$dc_config_number]['do_not_retry']) && $this->settings[$dc_config_number]['do_not_retry']) {
|
if (isset($this->settings[$dc_config_number]['do_not_retry']) && $this->settings[$dc_config_number]['do_not_retry']) {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user