diff --git a/CHANGELOG.md b/CHANGELOG.md index d38b82460..a5bad946f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,9 @@ Features: Fixes: - Fixed simple filters with service messages. -- Fixed IDE typehinting for `getEventHandler` +- Fixed IDE typehinting for `getEventHandler`. - Fixed startAndLoopMulti -- Tweaked the default drop timeout on media DCs to avoid timeout errors on slow networks +- Tweaked the default drop timeout on media DCs to avoid timeout errors on slow networks. - Now the admin list only contains user report peers. --- diff --git a/docs b/docs index 36fed16a6..beaafe9ef 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 36fed16a6e3260dc30b0c116d56fe392de71f84b +Subproject commit beaafe9ef45ee1cc080a48fa565c4b63c7c64aa6 diff --git a/examples/bot.php b/examples/bot.php index c5daa585d..df199a9b5 100755 --- a/examples/bot.php +++ b/examples/bot.php @@ -28,7 +28,6 @@ use danog\MadelineProto\EventHandler\Filter\FilterCommand; use danog\MadelineProto\EventHandler\Filter\FilterRegex; use danog\MadelineProto\EventHandler\Filter\FilterText; use danog\MadelineProto\EventHandler\Message; -use danog\MadelineProto\EventHandler\Message\Service\DialogMessagePinned; use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged; use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin; use danog\MadelineProto\EventHandler\SimpleFilter\Incoming; @@ -182,7 +181,6 @@ class MyEventHandler extends SimpleEventHandler $message->reply('hello'); } - /** * Called when the dialog photo of a chat or channel changes. */ @@ -190,10 +188,9 @@ class MyEventHandler extends SimpleEventHandler public function logPhotoChanged(Incoming&DialogPhotoChanged $message): void { if ($message->photo) { - $message->reply("Nice :D"); - } else { - $message->reply("Aww, why did you delete the group photo? :("); + $message->reply("Nice! Here's a download link for the photo: ".$message->photo->getDownloadLink()); } + // The group photo was deleted } /** diff --git a/examples/combinedBot.php b/examples/combinedBot.php index f8207b69d..6c076099d 100755 --- a/examples/combinedBot.php +++ b/examples/combinedBot.php @@ -20,7 +20,6 @@ use danog\MadelineProto\API; use danog\MadelineProto\EventHandler; -use danog\MadelineProto\Logger; /* * Various ways to load MadelineProto diff --git a/src/EventHandler/Filter/Filter.php b/src/EventHandler/Filter/Filter.php index 952a88c70..619276762 100644 --- a/src/EventHandler/Filter/Filter.php +++ b/src/EventHandler/Filter/Filter.php @@ -91,12 +91,13 @@ abstract class Filter HasSticker::class => new FilterSticker, HasVideo::class => new FilterVideo, HasVoice::class => new FilterVoice, - default => is_subclass_of($type->getName(), Update::class) + default => \is_subclass_of($type->getName(), Update::class) ? new class($type->getName()) extends Filter { public function __construct(private readonly string $class) { } - public function apply(Update $update): bool { + public function apply(Update $update): bool + { return $update instanceof $this->class; } } diff --git a/src/InternalDoc.php b/src/InternalDoc.php index 7840d372c..7e37b85ce 100644 --- a/src/InternalDoc.php +++ b/src/InternalDoc.php @@ -652,7 +652,7 @@ abstract class InternalDoc return \danog\MadelineProto\Tools::genVectorHash($ints); } /** - * Get admin IDs (equal to the report peers). + * Get admin IDs (equal to all user report peers). */ public function getAdminIds(): array { @@ -785,7 +785,11 @@ abstract class InternalDoc /** * Get event handler (or plugin instance). * - * @param ?class-string $class + * @template T as EventHandler + * + * @param class-string|null $class + * + * @return T|EventHandlerProxy|__PHP_Incomplete_Class|null */ public function getEventHandler(?string $class = null): \danog\MadelineProto\EventHandler|\danog\MadelineProto\Ipc\EventHandlerProxy|\__PHP_Incomplete_Class|null { @@ -1089,6 +1093,13 @@ abstract class InternalDoc { return $this->wrapper->getAPI()->getWebMessage($message); } + /** + * Check if has admins. + */ + public function hasAdmins(): bool + { + return $this->wrapper->getAPI()->hasAdmins(); + } /** * Check if an event handler instance is present. */ @@ -1985,7 +1996,7 @@ abstract class InternalDoc /** * Wrap a Message constructor into an abstract Message object. */ - public function wrapMessage(array $message): ?\danog\MadelineProto\EventHandler\Message + public function wrapMessage(array $message): ?\danog\MadelineProto\EventHandler\AbstractMessage { return $this->wrapper->getAPI()->wrapMessage($message); } diff --git a/src/MTProto.php b/src/MTProto.php index 2ae98c4cc..09cbdec39 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -1682,7 +1682,7 @@ final class MTProto implements TLCallback, LoggerGetter public function setReportPeers(int|string|array $userOrId): void { $this->reportDest = $this->sanitizeReportPeers($userOrId); - $this->admins = array_values(array_filter($this->reportDest, fn (int $v) => $v > 0)); + $this->admins = \array_values(\array_filter($this->reportDest, fn (int $v) => $v > 0)); } private ?LocalMutex $reportMutex = null; /** diff --git a/src/MTProtoSession/AuthKeyHandler.php b/src/MTProtoSession/AuthKeyHandler.php index b4f459543..64a5a0892 100644 --- a/src/MTProtoSession/AuthKeyHandler.php +++ b/src/MTProtoSession/AuthKeyHandler.php @@ -336,7 +336,7 @@ trait AuthKeyHandler * Generate auth_key */ $this->logger->logger( - extension_loaded('gmp') ? 'Generating authorization key...' : 'Generating authorization key (install gmp to speed up this process)...', + \extension_loaded('gmp') ? 'Generating authorization key...' : 'Generating authorization key (install gmp to speed up this process)...', Logger::VERBOSE ); $auth_key = $g_a->powMod($b, $dh_prime); diff --git a/src/MTProtoSession/CallHandler.php b/src/MTProtoSession/CallHandler.php index d7edf6dad..43c539a32 100644 --- a/src/MTProtoSession/CallHandler.php +++ b/src/MTProtoSession/CallHandler.php @@ -24,7 +24,6 @@ use Amp\DeferredFuture; use danog\MadelineProto\MTProto\Container; use danog\MadelineProto\MTProto\MTProtoOutgoingMessage; use danog\MadelineProto\TL\Exception; -use danog\MadelineProto\Tools; use danog\MadelineProto\WrappedFuture; use Revolt\EventLoop;