1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 03:34:42 +01:00
This commit is contained in:
Daniil Gentili 2023-07-06 22:09:09 +02:00
parent b5a7513555
commit 1d850a6209
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 32 additions and 7 deletions

View File

@ -24,7 +24,9 @@ use Amp\DeferredFuture;
use Amp\Future;
use Amp\Sync\LocalMutex;
use danog\MadelineProto\Db\DbPropertiesTrait;
use danog\MadelineProto\EventHandler\Filter\Filter;
use Generator;
use ReflectionAttribute;
use ReflectionClass;
use ReflectionMethod;
use Revolt\EventLoop;
@ -126,7 +128,18 @@ abstract class EventHandler extends AbstractAPI
$method_name = \lcfirst(\substr($method, 2));
if (($constructor = $constructors->findByPredicate($method_name)) && $constructor['type'] === 'Update') {
$methods[$method_name] = $this->$method(...);
continue;
}
$filter = $methodRefl->getAttributes(
Filter::class,
ReflectionAttribute::IS_INSTANCEOF
)[0] ?? null;
if (!$filter) {
return $filter;
}
$filter = $filter->newInstance();
$filter->initialize($this);
}
if ($has_any) {
$onAny = $this->onAny(...);

View File

@ -5,15 +5,15 @@ namespace danog\MadelineProto\EventHandler\Filter;
use danog\MadelineProto\EventHandler\Update;
/**
* Filter that always returns the specified boolean.
* Filter that always allows all updates.
*/
final class FilterConstant extends Filter
final class Handler extends Filter
{
public function __construct(private readonly bool $result)
public function __construct()
{
}
public function apply(Update $update): bool
{
return $this->result;
return true;
}
}

View File

@ -24,6 +24,7 @@ use Amp\DeferredFuture;
use Amp\File\Driver\BlockingFile;
use Amp\Future;
use Amp\Http\Client\Request;
use danog\MadelineProto\EventHandler\Media;
use danog\MadelineProto\EventHandler\Media\Audio;
use danog\MadelineProto\EventHandler\Media\CustomEmoji;
use danog\MadelineProto\EventHandler\Media\Document;
@ -545,12 +546,20 @@ trait Files
/**
* Wrap a media constructor into an abstract Media object.
*/
public function wrapMedia(array $media): Media
public function wrapMedia(array $media): ?Media
{
if ($media['_'] === 'messageMediaPhoto') {
if (!isset($media['photo'])) {
return null;
}
return new Photo($this, $media);
}
Assert::eq($media['_'], 'messageMediaDocument');
if ($media['_'] !== 'messageMediaDocument') {
return null;
}
if (!isset($media['document'])) {
return null;
}
$has_video = null;
$has_animated = false;
foreach ($media['attributes'] as $attr) {

View File

@ -344,7 +344,10 @@ trait UpdateHandler
$message['action']['title']
),
'messageActionChatEditPhoto' => new DialogPhotoChanged(
$this->wrapMedia($message['action']['photo'])
$this->wrapMedia([
'_' => 'messageMediaPhoto',
'photo' => $message['action']['photo']
])
),
'messageActionChatDeletePhoto' => new DialogPhotoChanged(null),
'messageActionChatAddUser' => new DialogMembersJoined(