1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-23 04:11:11 +01:00

fixing content

This commit is contained in:
AhJ 2024-01-06 19:40:32 +03:30
parent 6ca86777a8
commit 8657940860
6 changed files with 34 additions and 13 deletions

View File

@ -16,12 +16,12 @@
namespace danog\MadelineProto\EventHandler\Filter; namespace danog\MadelineProto\EventHandler\Filter;
use AssertionError;
use Attribute; use Attribute;
use danog\MadelineProto\EventHandler\CommandType; use AssertionError;
use Webmozart\Assert\Assert;
use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Update; use danog\MadelineProto\EventHandler\Update;
use Webmozart\Assert\Assert; use danog\MadelineProto\EventHandler\CommandType;
/** /**
* Allow only messages containing the specified command. * Allow only messages containing the specified command.

View File

@ -17,10 +17,11 @@
namespace danog\MadelineProto\EventHandler\Filter; namespace danog\MadelineProto\EventHandler\Filter;
use Attribute; use Attribute;
use danog\MadelineProto\EventHandler\Message; use AssertionError;
use danog\MadelineProto\EventHandler\Story\Story;
use danog\MadelineProto\EventHandler\Update;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\CommandType;
/** /**
* Allow only messages containing the specified case-insensitive command. * Allow only messages containing the specified case-insensitive command.
@ -29,15 +30,23 @@ use Webmozart\Assert\Assert;
final class FilterCommandCaseInsensetive extends Filter final class FilterCommandCaseInsensetive extends Filter
{ {
/** /**
* @var array<CommandType> * @var list<CommandType>
*/ */
public readonly array $commandTypes; public readonly array $commandTypes;
/** Command */
private readonly string $command;
/** /**
* @param string $command Command * @param string $command Command
* @param list<CommandType> $types Command types, if empty all command types are allowed. * @param list<CommandType> $types Command types, if empty all command types are allowed.
*/ */
public function __construct(private readonly string $command, array $types = [CommandType::BANG, CommandType::DOT, CommandType::SLASH]) public function __construct(
{ string $command,
array $types = [CommandType::BANG, CommandType::DOT, CommandType::SLASH],
private readonly ?string $encoding = null,
) {
$this->command = mb_strtolower($command, $encoding);
Assert::true(preg_match("/^\w+$/", $command) === 1, "An invalid command was specified!"); Assert::true(preg_match("/^\w+$/", $command) === 1, "An invalid command was specified!");
Assert::notEmpty($types, 'No command types were specified!'); Assert::notEmpty($types, 'No command types were specified!');
$c = []; $c = [];

View File

@ -28,11 +28,14 @@ use Webmozart\Assert\Assert;
#[Attribute(Attribute::TARGET_METHOD)] #[Attribute(Attribute::TARGET_METHOD)]
final class FilterTextCaseInsensitive extends Filter final class FilterTextCaseInsensitive extends Filter
{ {
private readonly string $content;
public function __construct( public function __construct(
private readonly string $content, string $content,
private readonly ?string $encoding = null, private readonly ?string $encoding = null,
) { ) {
Assert::notEmpty($content); Assert::notEmpty($content);
$this->content = mb_strtolower($content, $encoding);
} }
public function apply(Update $update): bool public function apply(Update $update): bool

View File

@ -28,11 +28,14 @@ use Webmozart\Assert\Assert;
#[Attribute(Attribute::TARGET_METHOD)] #[Attribute(Attribute::TARGET_METHOD)]
final class FilterTextContainsCaseInsensitive extends Filter final class FilterTextContainsCaseInsensitive extends Filter
{ {
private readonly string $content;
public function __construct( public function __construct(
private readonly string $content, string $content,
private readonly ?string $encoding = null, private readonly ?string $encoding = null,
) { ) {
Assert::notEmpty($content); Assert::notEmpty($content);
$this->content = mb_strtolower($content, $encoding);
} }
public function apply(Update $update): bool public function apply(Update $update): bool
{ {

View File

@ -28,11 +28,14 @@ use Webmozart\Assert\Assert;
#[Attribute(Attribute::TARGET_METHOD)] #[Attribute(Attribute::TARGET_METHOD)]
final class FilterTextEndsCaseInsensitive extends Filter final class FilterTextEndsCaseInsensitive extends Filter
{ {
private readonly string $content;
public function __construct( public function __construct(
private readonly string $content, string $content,
private readonly ?string $encoding = null, private readonly ?string $encoding = null,
) { ) {
Assert::notEmpty($content); Assert::notEmpty($content);
$this->content = mb_strtolower($content, $encoding);
} }
public function apply(Update $update): bool public function apply(Update $update): bool

View File

@ -28,11 +28,14 @@ use Webmozart\Assert\Assert;
#[Attribute(Attribute::TARGET_METHOD)] #[Attribute(Attribute::TARGET_METHOD)]
final class FilterTextStartsCaseInsensitive extends Filter final class FilterTextStartsCaseInsensitive extends Filter
{ {
private readonly string $content;
public function __construct( public function __construct(
private readonly string $content, string $content,
private readonly ?string $encoding = null, private readonly ?string $encoding = null,
) { ) {
Assert::notEmpty($content); Assert::notEmpty($content);
$this->content = mb_strtolower($content, $encoding);
} }
public function apply(Update $update): bool public function apply(Update $update): bool