Minor fixes
This commit is contained in:
parent
b2bd441f42
commit
c09488aa12
@ -120,7 +120,10 @@ class API extends APIFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger::log((string) $e, Logger::ERROR);
|
Logger::log((string) $e, Logger::ERROR);
|
||||||
if (!$changed) throw $e;
|
if (!$changed) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
$unserialized = \danog\Serialization::unserialize($tounserialize);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
Logger::log((string) $e, Logger::ERROR);
|
Logger::log((string) $e, Logger::ERROR);
|
||||||
|
@ -214,6 +214,9 @@ class Connection
|
|||||||
$this->API->logger->logger("Reconnecting DC {$this->datacenter}");
|
$this->API->logger->logger("Reconnecting DC {$this->datacenter}");
|
||||||
$this->disconnect();
|
$this->disconnect();
|
||||||
yield $this->API->datacenter->dcConnectAsync($this->ctx->getDc());
|
yield $this->API->datacenter->dcConnectAsync($this->ctx->getDc());
|
||||||
|
if ($this->API->hasAllAuth() && !$this->hasPendingCalls()) {
|
||||||
|
yield $this->API->method_call_async_read('ping', ['ping_id' => $this->random_int()], ['datacenter' => $this->datacenter]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasPendingCalls()
|
public function hasPendingCalls()
|
||||||
|
@ -49,7 +49,7 @@ class FeedLoop extends ResumableSignalLoop
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!$this->API->settings['updates']['handle_updates'] || !$this->has_all_auth()) {
|
while (!$this->API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||||
if (yield $this->waitSignal($this->pause())) {
|
if (yield $this->waitSignal($this->pause())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ class FeedLoop extends ResumableSignalLoop
|
|||||||
$this->state = $this->channelId === false ? (yield $API->load_update_state_async()) : $API->loadChannelState($this->channelId);
|
$this->state = $this->channelId === false ? (yield $API->load_update_state_async()) : $API->loadChannelState($this->channelId);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
while (!$this->API->settings['updates']['handle_updates'] || !$this->has_all_auth()) {
|
while (!$this->API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||||
if (yield $this->waitSignal($this->pause())) {
|
if (yield $this->waitSignal($this->pause())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -220,7 +220,10 @@ class FeedLoop extends ResumableSignalLoop
|
|||||||
|
|
||||||
$this->API->logger->logger("Not enough data: for message update $log, getting difference...", \danog\MadelineProto\Logger::VERBOSE);
|
$this->API->logger->logger("Not enough data: for message update $log, getting difference...", \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$update = ['_' => 'updateChannelTooLong'];
|
$update = ['_' => 'updateChannelTooLong'];
|
||||||
if ($channelId && $to) $channelId = false;
|
if ($channelId && $to) {
|
||||||
|
$channelId = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -264,21 +267,6 @@ class FeedLoop extends ResumableSignalLoop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function has_all_auth()
|
|
||||||
{
|
|
||||||
if ($this->API->isInitingAuthorization()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->API->datacenter->sockets as $dc) {
|
|
||||||
if (!$dc->authorized || $dc->temp_auth_key === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return !$this->channelId ? 'update feed loop generic' : "update feed loop channel {$this->channelId}";
|
return !$this->channelId ? 'update feed loop generic' : "update feed loop channel {$this->channelId}";
|
||||||
|
@ -46,7 +46,7 @@ class SeqLoop extends ResumableSignalLoop
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!$this->API->settings['updates']['handle_updates'] || !$this->has_all_auth()) {
|
while (!$this->API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||||
if (yield $this->waitSignal($this->pause())) {
|
if (yield $this->waitSignal($this->pause())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ class SeqLoop extends ResumableSignalLoop
|
|||||||
$this->state = yield $API->load_update_state_async();
|
$this->state = yield $API->load_update_state_async();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
while (!$this->API->settings['updates']['handle_updates'] || !$this->has_all_auth()) {
|
while (!$this->API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||||
if (yield $this->waitSignal($this->pause())) {
|
if (yield $this->waitSignal($this->pause())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -134,20 +134,6 @@ class SeqLoop extends ResumableSignalLoop
|
|||||||
$this->pendingWakeups += $wakeups;
|
$this->pendingWakeups += $wakeups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function has_all_auth()
|
|
||||||
{
|
|
||||||
if ($this->API->isInitingAuthorization()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->API->datacenter->sockets as $dc) {
|
|
||||||
if (!$dc->authorized || $dc->temp_auth_key === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ class UpdateLoop extends ResumableSignalLoop
|
|||||||
$API = $this->API;
|
$API = $this->API;
|
||||||
$feeder = $this->feeder = $API->feeders[$this->channelId];
|
$feeder = $this->feeder = $API->feeders[$this->channelId];
|
||||||
|
|
||||||
while (!$API->settings['updates']['handle_updates'] || !$this->has_all_auth()) {
|
while (!$API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||||
if (yield $this->waitSignal($this->pause())) {
|
if (yield $this->waitSignal($this->pause())) {
|
||||||
$API->logger->logger("Exiting $this due to signal");
|
$API->logger->logger("Exiting $this due to signal");
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class UpdateLoop extends ResumableSignalLoop
|
|||||||
$timeout = $API->settings['updates']['getdifference_interval'];
|
$timeout = $API->settings['updates']['getdifference_interval'];
|
||||||
$first = true;
|
$first = true;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (!$API->settings['updates']['handle_updates'] || !$this->has_all_auth()) {
|
while (!$API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||||
if (yield $this->waitSignal($this->pause())) {
|
if (yield $this->waitSignal($this->pause())) {
|
||||||
$API->logger->logger("Exiting $this due to signal");
|
$API->logger->logger("Exiting $this due to signal");
|
||||||
|
|
||||||
@ -206,21 +206,6 @@ class UpdateLoop extends ResumableSignalLoop
|
|||||||
$this->toPts = $toPts;
|
$this->toPts = $toPts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function has_all_auth()
|
|
||||||
{
|
|
||||||
if ($this->API->isInitingAuthorization()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->API->datacenter->sockets as $dc) {
|
|
||||||
if (!$dc->authorized || $dc->temp_auth_key === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return !$this->channelId ? 'getUpdate loop generic' : "getUpdate loop channel {$this->channelId}";
|
return !$this->channelId ? 'getUpdate loop generic' : "getUpdate loop channel {$this->channelId}";
|
||||||
|
@ -264,6 +264,20 @@ class MTProto extends AsyncConstruct implements TLCallback
|
|||||||
return $this->datacenter->fileGetContents($url);
|
return $this->datacenter->fileGetContents($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasAllAuth()
|
||||||
|
{
|
||||||
|
if ($this->isInitingAuthorization()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->datacenter->sockets as $dc) {
|
||||||
|
if (!$dc->authorized || $dc->temp_auth_key === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public function __wakeup()
|
public function __wakeup()
|
||||||
{
|
{
|
||||||
$backtrace = debug_backtrace(0, 3);
|
$backtrace = debug_backtrace(0, 3);
|
||||||
@ -885,11 +899,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
|||||||
return in_array($this->datacenter->sockets[$datacenter]->getCtx()->getStreamName(), [HttpStream::getName(), HttpsStream::getName()]);
|
return in_array($this->datacenter->sockets[$datacenter]->getCtx()->getStreamName(), [HttpStream::getName(), HttpsStream::getName()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close_and_reopen($datacenter)
|
|
||||||
{
|
|
||||||
$this->wait($this->datacenter->sockets[$datacenter]->reconnect());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connects to all datacenters and if necessary creates authorization keys, binds them and writes client info
|
// Connects to all datacenters and if necessary creates authorization keys, binds them and writes client info
|
||||||
public function connect_to_all_dcs_async(): \Generator
|
public function connect_to_all_dcs_async(): \Generator
|
||||||
{
|
{
|
||||||
|
@ -144,11 +144,11 @@ class Magic
|
|||||||
Logger::log('Got sigint', Logger::FATAL_ERROR);
|
Logger::log('Got sigint', Logger::FATAL_ERROR);
|
||||||
die();
|
die();
|
||||||
});
|
});
|
||||||
Loop::onSignal(SIGTERM, static function () {
|
/*Loop::onSignal(SIGTERM, static function () {
|
||||||
Logger::log('Got sigterm', Logger::FATAL_ERROR);
|
Logger::log('Got sigterm', Logger::FATAL_ERROR);
|
||||||
Loop::stop();
|
Loop::stop();
|
||||||
die();
|
die();
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
$DohConfig = new DoHConfig(
|
$DohConfig = new DoHConfig(
|
||||||
[
|
[
|
||||||
|
@ -66,17 +66,17 @@ trait Loop
|
|||||||
$this->logger->logger($needs_restart ? 'Will self-restart' : 'Will not self-restart');
|
$this->logger->logger($needs_restart ? 'Will self-restart' : 'Will not self-restart');
|
||||||
|
|
||||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
$lockfile = dirname(end($backtrace)['file']).'/bot.lock';
|
$lockfile = dirname(end($backtrace)['file']).'/bot'.$this->authorization['user']['id'].'.lock';
|
||||||
unset($backtrace);
|
unset($backtrace);
|
||||||
$try_locking = true;
|
$try_locking = true;
|
||||||
if (!file_exists($lockfile)) {
|
if (!file_exists($lockfile)) {
|
||||||
touch($lockfile);
|
touch($lockfile);
|
||||||
$lock = fopen('bot.lock', 'r+');
|
$lock = fopen($lockfile, 'r+');
|
||||||
} elseif (isset($GLOBALS['lock'])) {
|
} elseif (isset($GLOBALS['lock'])) {
|
||||||
$try_locking = false;
|
$try_locking = false;
|
||||||
$lock = $GLOBALS['lock'];
|
$lock = $GLOBALS['lock'];
|
||||||
} else {
|
} else {
|
||||||
$lock = fopen('bot.lock', 'r+');
|
$lock = fopen($lockfile, 'r+');
|
||||||
}
|
}
|
||||||
if ($try_locking) {
|
if ($try_locking) {
|
||||||
$try = 1;
|
$try = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user