diff --git a/docs b/docs index 480552c07..7840caf79 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 480552c070099271e1df125732296ad11a58b6b0 +Subproject commit 7840caf793a5416453ef85f9f6799d0442b18dcb diff --git a/src/Broadcast/InternalState.php b/src/Broadcast/InternalState.php index a616554c3..cc3defb85 100644 --- a/src/Broadcast/InternalState.php +++ b/src/Broadcast/InternalState.php @@ -37,7 +37,7 @@ final class InternalState { /** @var array */ private array $peers = []; - private int $pendingCount = 0; + private int $totalCount = 0; private int $successCount = 0; private int $failCount = 0; private StatusInternal $status = StatusInternal::IDLING_BEFORE_GATHERING_PEERS; @@ -152,7 +152,7 @@ final class InternalState return true; }); $this->peers = $peers; - $this->pendingCount = \count($peers); + $this->totalCount = \count($peers); $this->setStatus(StatusInternal::IDLING_BEFORE_BROADCASTING); $this->startBroadcast(); }); @@ -227,7 +227,7 @@ final class InternalState $this->API, $this->broadcastId, $this->getStatus(), - $this->pendingCount, + \count($this->peers), $this->successCount, $this->failCount ); diff --git a/src/EventHandler/Filter/AbstractFilterFromSender.php b/src/EventHandler/Filter/AbstractFilterFromSender.php index 434d0590c..de38149b0 100644 --- a/src/EventHandler/Filter/AbstractFilterFromSender.php +++ b/src/EventHandler/Filter/AbstractFilterFromSender.php @@ -16,16 +16,15 @@ namespace danog\MadelineProto\EventHandler\Filter; -use Attribute; use danog\MadelineProto\EventHandler; +use danog\MadelineProto\EventHandler\InlineQuery; use danog\MadelineProto\EventHandler\Message\GroupMessage; use danog\MadelineProto\EventHandler\Query\ButtonQuery; -use danog\MadelineProto\EventHandler\InlineQuery; use danog\MadelineProto\EventHandler\Update; /** * Allow incoming or outgoing group messages made by a certain sender. - * + * * @internal */ abstract class AbstractFilterFromSender extends Filter @@ -43,7 +42,7 @@ abstract class AbstractFilterFromSender extends Filter public function apply(Update $update): bool { return ($update instanceof GroupMessage && $update->senderId === $this->peerResolved) || - ($update instanceof ButtonQuery && $update->userId === $this->peerResolved) || + ($update instanceof ButtonQuery && $update->userId === $this->peerResolved) || ($update instanceof InlineQuery && $update->userId === $this->peerResolved); } } diff --git a/src/EventHandler/Filter/AbstractFilterFromSenders.php b/src/EventHandler/Filter/AbstractFilterFromSenders.php index 85fb59e4b..ff361a354 100644 --- a/src/EventHandler/Filter/AbstractFilterFromSenders.php +++ b/src/EventHandler/Filter/AbstractFilterFromSenders.php @@ -16,16 +16,15 @@ namespace danog\MadelineProto\EventHandler\Filter; -use Attribute; use danog\MadelineProto\EventHandler; +use danog\MadelineProto\EventHandler\InlineQuery; use danog\MadelineProto\EventHandler\Message\GroupMessage; use danog\MadelineProto\EventHandler\Query\ButtonQuery; -use danog\MadelineProto\EventHandler\InlineQuery; use danog\MadelineProto\EventHandler\Update; /** * Allow incoming or outgoing group messages made by a certain list of senders. - * + * * @internal */ abstract class AbstractFilterFromSenders extends Filter @@ -54,7 +53,7 @@ abstract class AbstractFilterFromSenders extends Filter public function apply(Update $update): bool { return $update instanceof GroupMessage && \in_array($update->senderId, $this->peersResolved, true); - ($update instanceof ButtonQuery && \in_array($update->userId, $this->peersResolved, true)) || - ($update instanceof InlineQuery && \in_array($update->userId, $this->peersResolved, true)); + ($update instanceof ButtonQuery && \in_array($update->userId, $this->peersResolved, true)) || + ($update instanceof InlineQuery && \in_array($update->userId, $this->peersResolved, true)); } } diff --git a/src/EventHandler/Filter/FilterFromAdmin.php b/src/EventHandler/Filter/FilterFromAdmin.php index eb887b969..36325eeef 100644 --- a/src/EventHandler/Filter/FilterFromAdmin.php +++ b/src/EventHandler/Filter/FilterFromAdmin.php @@ -19,8 +19,8 @@ namespace danog\MadelineProto\EventHandler\Filter; use Attribute; use danog\MadelineProto\EventHandler; use danog\MadelineProto\EventHandler\AbstractMessage; -use danog\MadelineProto\EventHandler\Query\ButtonQuery; use danog\MadelineProto\EventHandler\InlineQuery; +use danog\MadelineProto\EventHandler\Query\ButtonQuery; use danog\MadelineProto\EventHandler\Update; /** @@ -39,7 +39,7 @@ final class FilterFromAdmin extends Filter public function apply(Update $update): bool { return ($update instanceof AbstractMessage && \in_array($update->senderId, $this->adminIds, true)) || - ($update instanceof ButtonQuery && \in_array($update->userId, $this->adminIds, true)) || + ($update instanceof ButtonQuery && \in_array($update->userId, $this->adminIds, true)) || ($update instanceof InlineQuery && \in_array($update->userId, $this->adminIds, true)); } } diff --git a/src/EventHandler/Filter/FilterFromSender.php b/src/EventHandler/Filter/FilterFromSender.php index 75807a883..acfac4991 100644 --- a/src/EventHandler/Filter/FilterFromSender.php +++ b/src/EventHandler/Filter/FilterFromSender.php @@ -17,9 +17,6 @@ namespace danog\MadelineProto\EventHandler\Filter; use Attribute; -use danog\MadelineProto\EventHandler; -use danog\MadelineProto\EventHandler\Message\GroupMessage; -use danog\MadelineProto\EventHandler\Update; /** * Allow incoming or outgoing group messages made by a certain sender. diff --git a/src/EventHandler/Filter/FilterFromSenders.php b/src/EventHandler/Filter/FilterFromSenders.php index 00c7bbffe..3ea294fc4 100644 --- a/src/EventHandler/Filter/FilterFromSenders.php +++ b/src/EventHandler/Filter/FilterFromSenders.php @@ -17,9 +17,6 @@ namespace danog\MadelineProto\EventHandler\Filter; use Attribute; -use danog\MadelineProto\EventHandler; -use danog\MadelineProto\EventHandler\Message\GroupMessage; -use danog\MadelineProto\EventHandler\Update; /** * Allow incoming or outgoing group messages made by a certain list of senders. diff --git a/src/EventHandler/Filter/FilterRegex.php b/src/EventHandler/Filter/FilterRegex.php index fabe01d4c..5244ba1a7 100644 --- a/src/EventHandler/Filter/FilterRegex.php +++ b/src/EventHandler/Filter/FilterRegex.php @@ -17,9 +17,9 @@ namespace danog\MadelineProto\EventHandler\Filter; use Attribute; +use danog\MadelineProto\EventHandler\InlineQuery; use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\EventHandler\Query\ButtonQuery; -use danog\MadelineProto\EventHandler\InlineQuery; use danog\MadelineProto\EventHandler\Update; use Webmozart\Assert\Assert; diff --git a/src/EventHandler/Filter/FilterSender.php b/src/EventHandler/Filter/FilterSender.php index 64b25ea7b..60b180ed2 100644 --- a/src/EventHandler/Filter/FilterSender.php +++ b/src/EventHandler/Filter/FilterSender.php @@ -17,9 +17,6 @@ namespace danog\MadelineProto\EventHandler\Filter; use Attribute; -use danog\MadelineProto\EventHandler; -use danog\MadelineProto\EventHandler\Message\GroupMessage; -use danog\MadelineProto\EventHandler\Update; /** * Allow incoming or outgoing group messages made by a certain sender. @@ -27,4 +24,4 @@ use danog\MadelineProto\EventHandler\Update; #[Attribute(Attribute::TARGET_METHOD)] final class FilterSender extends AbstractFilterFromSender { -} \ No newline at end of file +} diff --git a/src/EventHandler/Filter/FilterSenders.php b/src/EventHandler/Filter/FilterSenders.php index f681610f9..d02048eb8 100644 --- a/src/EventHandler/Filter/FilterSenders.php +++ b/src/EventHandler/Filter/FilterSenders.php @@ -17,9 +17,6 @@ namespace danog\MadelineProto\EventHandler\Filter; use Attribute; -use danog\MadelineProto\EventHandler; -use danog\MadelineProto\EventHandler\Message\GroupMessage; -use danog\MadelineProto\EventHandler\Update; /** * Allow incoming or outgoing group messages made by a certain list of senders. diff --git a/src/EventHandler/InlineQuery.php b/src/EventHandler/InlineQuery.php index 92a428ae4..e34699cce 100644 --- a/src/EventHandler/InlineQuery.php +++ b/src/EventHandler/InlineQuery.php @@ -6,7 +6,7 @@ use danog\MadelineProto\EventHandler\Media\GeoPoint; use danog\MadelineProto\MTProto; /** - * An incoming inline query + * An incoming inline query. */ final class InlineQuery extends Update { @@ -41,4 +41,4 @@ final class InlineQuery extends Update $this->geo = isset($rawInlineQuery['geo']) ? new GeoPoint($rawInlineQuery['geo']) : null; $this->peerType = InlineQueryPeerType::fromString($rawInlineQuery['peer_type']['_']); } -} \ No newline at end of file +} diff --git a/src/EventHandler/InlineQueryPeerType.php b/src/EventHandler/InlineQueryPeerType.php index f3328caa3..505991f46 100644 --- a/src/EventHandler/InlineQueryPeerType.php +++ b/src/EventHandler/InlineQueryPeerType.php @@ -22,17 +22,18 @@ enum InlineQueryPeerType implements JsonSerializable case SameBotPM; /** - * Get InlineQueryPeerType from update - * + * Get InlineQueryPeerType from update. + * * @param string Type of the chat from which the inline query was sent. * @throws AssertionError */ public static function fromString(string $name): InlineQueryPeerType { - $newName = substr($name, 19); + $newName = \substr($name, 19); foreach (InlineQueryPeerType::cases() as $case) { - if ($case->name === $newName) + if ($case->name === $newName) { return $case; + } } throw new AssertionError("Undefined case InlineQueryPeerType::".$name); } @@ -42,4 +43,4 @@ enum InlineQueryPeerType implements JsonSerializable { return $this->name; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Media/GeoPoint.php b/src/EventHandler/Media/GeoPoint.php index cc695cf91..4a945d9e5 100644 --- a/src/EventHandler/Media/GeoPoint.php +++ b/src/EventHandler/Media/GeoPoint.php @@ -30,4 +30,4 @@ final class GeoPoint implements JsonSerializable $v['_'] = static::class; return $v; } -} \ No newline at end of file +} diff --git a/src/MTProtoTools/FilesLogic.php b/src/MTProtoTools/FilesLogic.php index 571374563..0d8ad9d19 100644 --- a/src/MTProtoTools/FilesLogic.php +++ b/src/MTProtoTools/FilesLogic.php @@ -31,6 +31,7 @@ use Amp\Sync\LocalMutex; use Amp\Sync\Lock; use danog\MadelineProto\API; use danog\MadelineProto\BotApiFileId; +use danog\MadelineProto\EventHandler\Media; use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\Exception; use danog\MadelineProto\FileCallbackInterface; @@ -280,7 +281,7 @@ trait FilesLogic if (\filter_var($file, FILTER_VALIDATE_URL)) { return $this->uploadFromUrl($file, 0, $fileName, $cb, $encrypted); } - } elseif (\is_array($file)) { + } elseif (\is_array($file) || $file instanceof Media) { return $this->uploadFromTgfile($file, $cb, $encrypted); } if ($file instanceof ReadableStream || \is_resource($file)) {