diff --git a/src/EventHandler/Filter/FilterRegexAll.php b/src/EventHandler/Filter/FilterRegexMatchAll.php similarity index 98% rename from src/EventHandler/Filter/FilterRegexAll.php rename to src/EventHandler/Filter/FilterRegexMatchAll.php index 3bc6f4e60..d5da7293a 100644 --- a/src/EventHandler/Filter/FilterRegexAll.php +++ b/src/EventHandler/Filter/FilterRegexMatchAll.php @@ -28,7 +28,7 @@ use Webmozart\Assert\Assert; * Allow only messages or button queries matching the specified regex. */ #[Attribute(Attribute::TARGET_METHOD)] -final class FilterRegexAll extends Filter +final class FilterRegexMatchAll extends Filter { /** @param non-empty-string $regex */ public function __construct( diff --git a/src/EventHandler/Filter/FilterTextContain.php b/src/EventHandler/Filter/FilterTextContains.php similarity index 97% rename from src/EventHandler/Filter/FilterTextContain.php rename to src/EventHandler/Filter/FilterTextContains.php index ffb0ba039..197027399 100644 --- a/src/EventHandler/Filter/FilterTextContain.php +++ b/src/EventHandler/Filter/FilterTextContains.php @@ -26,7 +26,7 @@ use Webmozart\Assert\Assert; * Allow only messages that contain a specific content. */ #[Attribute(Attribute::TARGET_METHOD)] -final class FilterTextContain extends Filter +final class FilterTextContains extends Filter { public function __construct( private readonly string $content diff --git a/src/EventHandler/Filter/FilterTextContainsCaseInsensitive.php b/src/EventHandler/Filter/FilterTextContainsCaseInsensitive.php new file mode 100644 index 000000000..029a7e1ef --- /dev/null +++ b/src/EventHandler/Filter/FilterTextContainsCaseInsensitive.php @@ -0,0 +1,41 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @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\Message; +use danog\MadelineProto\EventHandler\Story\Story; +use danog\MadelineProto\EventHandler\Update; +use Webmozart\Assert\Assert; + +/** + * Allow only messages that contain a specific case-insensitive content. + */ +#[Attribute(Attribute::TARGET_METHOD)] +final class FilterTextContainsCaseInsensitive extends Filter +{ + public function __construct( + private readonly string $content + ) { + 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)); + } +} diff --git a/src/EventHandler/Filter/FilterTextEnd.php b/src/EventHandler/Filter/FilterTextEnds.php similarity index 94% rename from src/EventHandler/Filter/FilterTextEnd.php rename to src/EventHandler/Filter/FilterTextEnds.php index 0687a6a17..f1c9a2fe7 100644 --- a/src/EventHandler/Filter/FilterTextEnd.php +++ b/src/EventHandler/Filter/FilterTextEnds.php @@ -23,10 +23,10 @@ use danog\MadelineProto\EventHandler\Update; use Webmozart\Assert\Assert; /** - * Allow only messages that end with a specific content. + * Allow only messages that ends with a specific content. */ #[Attribute(Attribute::TARGET_METHOD)] -final class FilterTextEnd extends Filter +final class FilterTextEnds extends Filter { public function __construct( private readonly string $content diff --git a/src/EventHandler/Filter/FilterTextEndsCaseInsensitive.php b/src/EventHandler/Filter/FilterTextEndsCaseInsensitive.php new file mode 100644 index 000000000..b63866bce --- /dev/null +++ b/src/EventHandler/Filter/FilterTextEndsCaseInsensitive.php @@ -0,0 +1,41 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @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\Message; +use danog\MadelineProto\EventHandler\Story\Story; +use danog\MadelineProto\EventHandler\Update; +use Webmozart\Assert\Assert; + +/** + * Allow only messages that ends with a specific case-insensitive content. + */ +#[Attribute(Attribute::TARGET_METHOD)] +final class FilterTextEndsCaseInsensitive extends Filter +{ + public function __construct( + private readonly string $content + ) { + 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)); + } +} diff --git a/src/EventHandler/Filter/FilterTextStart.php b/src/EventHandler/Filter/FilterTextStarts.php similarity index 100% rename from src/EventHandler/Filter/FilterTextStart.php rename to src/EventHandler/Filter/FilterTextStarts.php diff --git a/src/EventHandler/Filter/FilterTextStartsCaseInsensitive.php b/src/EventHandler/Filter/FilterTextStartsCaseInsensitive.php new file mode 100644 index 000000000..bbe206474 --- /dev/null +++ b/src/EventHandler/Filter/FilterTextStartsCaseInsensitive.php @@ -0,0 +1,41 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @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\Message; +use danog\MadelineProto\EventHandler\Story\Story; +use danog\MadelineProto\EventHandler\Update; +use Webmozart\Assert\Assert; + +/** + * Allow only messages that start with a specific case-insensitive content. + */ +#[Attribute(Attribute::TARGET_METHOD)] +final class FilterTextStartsCaseInsensitive extends Filter +{ + public function __construct( + private readonly string $content + ) { + 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)); + } +}