Skip to content

Commit

Permalink
Add events.filters.Data (#4248)
Browse files Browse the repository at this point in the history
  • Loading branch information
apepenkov committed Nov 9, 2023
1 parent ca0d39c commit ba0371f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/telethon/_impl/client/events/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .combinators import All, Any, Filter, Not
from .common import Chats, ChatType, Senders
from .messages import Command, Forward, Incoming, Media, Outgoing, Reply, Text
from .callback import Data

__all__ = [
"All",
Expand All @@ -17,4 +18,5 @@
"Outgoing",
"Reply",
"Text",
"Data",
]
23 changes: 23 additions & 0 deletions client/src/telethon/_impl/client/events/filters/callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from .combinators import Combinable
from ..event import Event


class Data(Combinable):
"""
Filter by ``event.data`` using a full bytes match, used for events such as :class:`telethon.events.ButtonCallback`.
It checks if ``event.data`` is equal to the data passed to the filter.
:param data: Bytes to match data with.
"""

__slots__ = ("_data",)

def __init__(self, data: bytes) -> None:
self._data = data

def __call__(self, event: Event) -> bool:
data = getattr(event, "data", None)
return self._data == data if data is not None else False
2 changes: 2 additions & 0 deletions client/src/telethon/events/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Reply,
Senders,
Text,
Data,
)

__all__ = [
Expand All @@ -39,4 +40,5 @@
"Reply",
"Senders",
"Text",
"Data"
]

0 comments on commit ba0371f

Please sign in to comment.