1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 03:14:39 +01:00
This commit is contained in:
Daniil Gentili 2023-05-26 21:42:02 +02:00
parent e4f9b657b7
commit 948a697ff5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 39 additions and 23 deletions

2
docs

@ -1 +1 @@
Subproject commit cd0f06e07029bb18a69bf330d4c53f0b68005b21 Subproject commit 774abcdbb214481cc7f00e25ca2b882b6957dc14

View File

@ -28,7 +28,6 @@ use Amp\Ipc\Sync\ChannelledSocket;
use Amp\SignalException; use Amp\SignalException;
use Amp\TimeoutCancellation; use Amp\TimeoutCancellation;
use Amp\TimeoutException; use Amp\TimeoutException;
use AssertionError;
use danog\MadelineProto\ApiWrappers\Start; use danog\MadelineProto\ApiWrappers\Start;
use danog\MadelineProto\ApiWrappers\Templates; use danog\MadelineProto\ApiWrappers\Templates;
use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\Ipc\Client;
@ -112,12 +111,6 @@ final class API extends AbstractAPI
*/ */
private SessionPaths $session; private SessionPaths $session;
/**
* Whether this is an old instance.
*
*/
private bool $oldInstance = false;
/** /**
* Unlock callback. * Unlock callback.
* *
@ -317,11 +310,11 @@ final class API extends AbstractAPI
*/ */
public function __wakeup(): void public function __wakeup(): void
{ {
$this->oldInstance = true; $this->__construct($this->session->getSessionDirectoryPath());
} }
public function __sleep(): array public function __sleep(): array
{ {
throw new AssertionError("MadelineProto can't be serialized!"); return ['session'];
} }
/** /**
* @var array<Future<null>> * @var array<Future<null>>
@ -343,9 +336,6 @@ final class API extends AbstractAPI
*/ */
public function __destruct() public function __destruct()
{ {
if ($this->oldInstance) {
return;
}
$id = \count(self::$destructors); $id = \count(self::$destructors);
self::$destructors[$id] = async(function () use ($id): void { self::$destructors[$id] = async(function () use ($id): void {
$this->wrapper->logger('Shutting down MadelineProto ('.static::class.')'); $this->wrapper->logger('Shutting down MadelineProto ('.static::class.')');

View File

@ -22,6 +22,7 @@ namespace danog\MadelineProto\Broadcast\Action;
use Amp\Cancellation; use Amp\Cancellation;
use danog\MadelineProto\Broadcast\Action; use danog\MadelineProto\Broadcast\Action;
use danog\MadelineProto\Exception;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
use danog\MadelineProto\RPCErrorException; use danog\MadelineProto\RPCErrorException;
@ -54,6 +55,9 @@ final class ActionForward implements Action
if ($e->rpc === 'CHAT_WRITE_FORBIDDEN') { if ($e->rpc === 'CHAT_WRITE_FORBIDDEN') {
return; return;
} }
if ($e->rpc === 'CHANNEL_PRIVATE') {
return;
}
if ($e->rpc === 'USER_IS_BLOCKED') { if ($e->rpc === 'USER_IS_BLOCKED') {
return; return;
} }
@ -61,6 +65,11 @@ final class ActionForward implements Action
return; return;
} }
throw $e; throw $e;
} catch (Exception $e) {
if ($e->getMessage() === 'This peer is not present in the internal peer database') {
return;
}
throw $e;
} }
} }
} }

View File

@ -22,6 +22,7 @@ namespace danog\MadelineProto\Broadcast\Action;
use Amp\Cancellation; use Amp\Cancellation;
use danog\MadelineProto\Broadcast\Action; use danog\MadelineProto\Broadcast\Action;
use danog\MadelineProto\Exception;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
use danog\MadelineProto\RPCErrorException; use danog\MadelineProto\RPCErrorException;
@ -43,7 +44,7 @@ final class ActionSend implements Action
$message['media']['_'] !== 'messageMediaWebPage' $message['media']['_'] !== 'messageMediaWebPage'
? 'messages.sendMedia' ? 'messages.sendMedia'
: 'messages.sendMessage', : 'messages.sendMessage',
\array_merge($message, ['to_peer' => $peer]), \array_merge($message, ['peer' => $peer]),
['FloodWaitLimit' => 2*86400] ['FloodWaitLimit' => 2*86400]
); );
} }
@ -57,6 +58,9 @@ final class ActionSend implements Action
if ($e->rpc === 'CHAT_WRITE_FORBIDDEN') { if ($e->rpc === 'CHAT_WRITE_FORBIDDEN') {
return; return;
} }
if ($e->rpc === 'CHANNEL_PRIVATE') {
return;
}
if ($e->rpc === 'USER_IS_BLOCKED') { if ($e->rpc === 'USER_IS_BLOCKED') {
return; return;
} }
@ -64,6 +68,11 @@ final class ActionSend implements Action
return; return;
} }
throw $e; throw $e;
} catch (Exception $e) {
if ($e->getMessage() === 'This peer is not present in the internal peer database') {
return;
}
throw $e;
} }
} }
} }

View File

@ -112,16 +112,24 @@ final class InternalState
$this->setStatus(StatusInternal::GATHERING_PEERS); $this->setStatus(StatusInternal::GATHERING_PEERS);
async(function (): void { async(function (): void {
$peers = $this->API->getDialogIds(); $peers = $this->API->getDialogIds();
$peers = \array_filter($peers, fn (int $peer): bool => !( $peers = \array_filter($peers, function (int $peer): bool {
\in_array($peer, $this->filter->blacklist, true) if (\in_array($peer, $this->filter->blacklist, true)) {
|| !match ($this->API->getType($peer)) { return false;
'user' => $this->filter->allowUsers,
'bot' => $this->filter->allowBots,
'chat' => $this->filter->allowGroups,
'supergroup' => $this->filter->allowGroups,
'channel' => $this->filter->allowChannels,
} }
)); try {
if (!match ($this->API->getType($peer)) {
'user' => $this->filter->allowUsers,
'bot' => $this->filter->allowBots,
'chat' => $this->filter->allowGroups,
'supergroup' => $this->filter->allowGroups,
'channel' => $this->filter->allowChannels,
}) {
return false;
}
} catch (Throwable) {
}
return true;
});
$this->peers = $peers; $this->peers = $peers;
$this->pendingCount = \count($peers); $this->pendingCount = \count($peers);
$this->setStatus(StatusInternal::IDLING_BEFORE_BROADCASTING); $this->setStatus(StatusInternal::IDLING_BEFORE_BROADCASTING);