Add events.filters.Data (#4248)

This commit is contained in:
apepenkov 2023-11-09 21:28:18 +03:00 committed by GitHub
parent ca0d39c4b7
commit ba0371f89e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -1,6 +1,7 @@
from .combinators import All, Any, Filter, Not from .combinators import All, Any, Filter, Not
from .common import Chats, ChatType, Senders from .common import Chats, ChatType, Senders
from .messages import Command, Forward, Incoming, Media, Outgoing, Reply, Text from .messages import Command, Forward, Incoming, Media, Outgoing, Reply, Text
from .callback import Data
__all__ = [ __all__ = [
"All", "All",
@ -17,4 +18,5 @@ __all__ = [
"Outgoing", "Outgoing",
"Reply", "Reply",
"Text", "Text",
"Data",
] ]

View File

@ -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

View File

@ -22,6 +22,7 @@ from .._impl.client.events.filters import (
Reply, Reply,
Senders, Senders,
Text, Text,
Data,
) )
__all__ = [ __all__ = [
@ -39,4 +40,5 @@ __all__ = [
"Reply", "Reply",
"Senders", "Senders",
"Text", "Text",
"Data"
] ]