Skip to content

Commit

Permalink
Add filter message media
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateodioev committed Oct 9, 2023
1 parent d8e8b09 commit 8e7502e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Filters/FilterMessageMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Mateodioev\TgHandler\Filters;

use Attribute;
use Mateodioev\Bots\Telegram\Types\abstractType;
use Mateodioev\TgHandler\Context;

#[Attribute]
class FilterMessageMedia implements Filter
{
public function __construct(
private readonly MediaType $mediaType
) {
}

public function apply(Context $ctx): bool
{
return $ctx->{$this->mediaType->name} !== abstractType::DEFAULT_PARAM;
}
}
22 changes: 22 additions & 0 deletions src/Filters/FilterMessageSticker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Mateodioev\TgHandler\Filters;

use Attribute;
use Mateodioev\TgHandler\Context;

#[Attribute]
class FilterMessageSticker implements Filter
{
private Filter $filter;

public function __construct()
{
$this->filter = new FilterMessageMedia(MediaType::sticker);
}

public function apply(Context $ctx): bool
{
return $this->filter->apply($ctx);
}
}
16 changes: 16 additions & 0 deletions src/Filters/MediaType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Mateodioev\TgHandler\Filters;

enum MediaType
{
case animation;
case audio;
case document;
case photo;
case sticker;
case story;
case video;
case video_note;
case voice;
}

0 comments on commit 8e7502e

Please sign in to comment.