1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 05:34:42 +01:00

Merge branch 'v8' into story

This commit is contained in:
Daniil Gentili 2023-09-01 16:10:22 +02:00
commit 2d0bea4d03
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
6 changed files with 76 additions and 4 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@d3463e30f3768de1f61d1ef4834b4bcd8aa179ef">
<files psalm-version="dev-master@96d83947615641734a5baa181d44da7f10ee0246">
<file src="src/API.php">
<ArgumentTypeCoercion>
<code>$settings</code>
@ -428,6 +428,14 @@
<code>$adminIds</code>
</MissingConstructor>
</file>
<file src="src/EventHandler/Filter/FilterFromBot.php">
<InaccessibleProperty>
<code><![CDATA[$this->API]]></code>
</InaccessibleProperty>
<MissingConstructor>
<code>$API</code>
</MissingConstructor>
</file>
<file src="src/EventHandler/Filter/FilterPeer.php">
<PropertyNotSetInConstructor>
<code>$peerResolved</code>
@ -1420,7 +1428,6 @@
</PossiblyNullArgument>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$_SERVER['REQUEST_METHOD']]]></code>
<code><![CDATA[$_SERVER['REQUEST_METHOD']]]></code>
</PossiblyUndefinedArrayOffset>
<PossiblyUndefinedMethod>
<code>seek</code>
@ -1478,6 +1485,9 @@
</RedundantCastGivenDocblockType>
</file>
<file src="src/MTProtoTools/PeerHandler.php">
<InvalidArgument>
<code><![CDATA[self::isSupergroupOrChannel($peer) && $this->getInfo($peer, \danog\MadelineProto\API::INFO_TYPE_CONSTRUCTOR)['forum']]]></code>
</InvalidArgument>
<InvalidArrayOffset>
<code><![CDATA[$this->getInfo($peer, \danog\MadelineProto\API::INFO_TYPE_CONSTRUCTOR)['forum']]]></code>
</InvalidArrayOffset>

View File

@ -24,7 +24,7 @@ use danog\MadelineProto\EventHandler\Query\ButtonQuery;
use danog\MadelineProto\EventHandler\Update;
/**
* Allow only messages coming from the admin (defined as the first peer returned by getReportPeers).
* Allow only messages coming from the admin (defined as the peers returned by getReportPeers).
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FilterFromAdmin extends Filter

View File

@ -0,0 +1,45 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Filter;
use Attribute;
use danog\MadelineProto\EventHandler;
use danog\MadelineProto\EventHandler\AbstractMessage;
use danog\MadelineProto\EventHandler\InlineQuery;
use danog\MadelineProto\EventHandler\Query\ButtonQuery;
use danog\MadelineProto\EventHandler\Update;
/**
* Allow only messages coming from bots.
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FilterFromBot extends Filter
{
private readonly EventHandler $API;
/** Run some initialization logic, optionally returning a new filter to replace the current one. */
public function initialize(EventHandler $API): Filter
{
$this->API = $API;
return $this;
}
public function apply(Update $update): bool
{
return ($update instanceof AbstractMessage && $this->API->isBot($update->senderId)) ||
($update instanceof ButtonQuery && $this->API->isBot($update->userId)) ||
($update instanceof InlineQuery && $this->API->isBot($update->userId));
}
}

View File

@ -1204,6 +1204,14 @@ abstract class InternalDoc
{
return \danog\MadelineProto\Tools::isArrayOrAlike($var);
}
/**
* Check if the specified peer is a bot.
*
*/
public function isBot(mixed $peer): bool
{
return $this->wrapper->getAPI()->isBot($peer);
}
/**
* Check if the specified peer is a forum.
*

View File

@ -102,6 +102,15 @@ trait PeerHandler
return $this->getInfo($peer, \danog\MadelineProto\API::INFO_TYPE_CONSTRUCTOR)['forum'] ?? false;
}
/**
* Check if the specified peer is a bot.
*
*/
public function isBot(mixed $peer): bool
{
return $this->getType($peer) === API::PEER_TYPE_BOT;
}
/**
* Check if peer is present in internal peer database.
*

View File

@ -12,7 +12,7 @@ RUN apk add --no-cache make g++ && \
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions uv-beta ffi pq memprof intl gmp mbstring pdo_mysql xml dom iconv zip opcache igbinary && \
install-php-extensions pcntl uv-beta ffi pq memprof intl gmp mbstring pdo_mysql xml dom iconv zip opcache igbinary && \
rm /usr/local/bin/install-php-extensions
RUN apk add ffmpeg