mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 09:58:59 +01:00
Improve text filters
This commit is contained in:
parent
54b39937a4
commit
cb38b371cf
@ -33,6 +33,7 @@ final class FilterText extends Filter
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && $update->message === $this->content) ||
|
||||
|
@ -29,14 +29,15 @@ use Webmozart\Assert\Assert;
|
||||
final class FilterTextCaseInsensitive extends Filter
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $content
|
||||
private readonly string $content,
|
||||
private readonly ?string $encoding = null,
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
Assert::lower($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && strtolower($update->message) === $this->content) ||
|
||||
($update instanceof Story && strtolower($update->caption) === $this->content);
|
||||
return ($update instanceof Message && mb_strtolower($update->message, $this->encoding) === $this->content) ||
|
||||
($update instanceof Story && mb_strtolower($update->caption, $this->encoding) === $this->content);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ final class FilterTextContains extends Filter
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && str_contains($update->message, $this->content)) ||
|
||||
|
@ -29,13 +29,14 @@ use Webmozart\Assert\Assert;
|
||||
final class FilterTextContainsCaseInsensitive extends Filter
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $content
|
||||
private readonly string $content,
|
||||
private readonly ?string $encoding = null,
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && str_contains(strtolower($update->message), $this->content)) ||
|
||||
($update instanceof Story && str_contains(strtolower($update->caption), $this->content));
|
||||
return ($update instanceof Message && str_contains(mb_strtolower($update->message, $this->encoding), $this->content)) ||
|
||||
($update instanceof Story && str_contains(mb_strtolower($update->caption, $this->encoding), $this->content));
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ final class FilterTextEnds extends Filter
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && str_ends_with($update->message, $this->content)) ||
|
||||
|
@ -29,13 +29,15 @@ use Webmozart\Assert\Assert;
|
||||
final class FilterTextEndsCaseInsensitive extends Filter
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $content
|
||||
private readonly string $content,
|
||||
private readonly ?string $encoding = null,
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && str_ends_with(strtolower($update->message), $this->content)) ||
|
||||
($update instanceof Story && str_ends_with(strtolower($update->caption), $this->content));
|
||||
return ($update instanceof Message && str_ends_with(mb_strtolower($update->message, $this->encoding), $this->content)) ||
|
||||
($update instanceof Story && str_ends_with(mb_strtolower($update->caption, $this->encoding), $this->content));
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ final class FilterTextStart extends Filter
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && str_starts_with($update->message, $this->content)) ||
|
||||
|
@ -29,13 +29,15 @@ use Webmozart\Assert\Assert;
|
||||
final class FilterTextStartsCaseInsensitive extends Filter
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $content
|
||||
private readonly string $content,
|
||||
private readonly ?string $encoding = null,
|
||||
) {
|
||||
Assert::notEmpty($content);
|
||||
}
|
||||
|
||||
public function apply(Update $update): bool
|
||||
{
|
||||
return ($update instanceof Message && str_starts_with(strtolower($update->message), $this->content)) ||
|
||||
($update instanceof Story && str_starts_with(strtolower($update->caption), $this->content));
|
||||
return ($update instanceof Message && str_starts_with(mb_strtolower($update->message, $this->encoding), $this->content)) ||
|
||||
($update instanceof Story && str_starts_with(mb_strtolower($update->caption, $this->encoding), $this->content));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user