1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 05:34:42 +01:00
This commit is contained in:
َAhJ 2023-08-29 23:39:15 +03:30
commit 77f7db1c90
14 changed files with 26 additions and 38 deletions

2
docs

@ -1 +1 @@
Subproject commit 480552c070099271e1df125732296ad11a58b6b0
Subproject commit 7840caf793a5416453ef85f9f6799d0442b18dcb

View File

@ -37,7 +37,7 @@ final class InternalState
{
/** @var array<int> */
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
);

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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.

View File

@ -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.

View File

@ -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;

View File

@ -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
{
}
}

View File

@ -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.

View File

@ -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']['_']);
}
}
}

View File

@ -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;
}
}
}

View File

@ -30,4 +30,4 @@ final class GeoPoint implements JsonSerializable
$v['_'] = static::class;
return $v;
}
}
}

View File

@ -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)) {