mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 19:03:46 +03:00
Add events.filters.Data (#4248)
This commit is contained in:
parent
ca0d39c4b7
commit
ba0371f89e
|
@ -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",
|
||||||
]
|
]
|
||||||
|
|
23
client/src/telethon/_impl/client/events/filters/callback.py
Normal file
23
client/src/telethon/_impl/client/events/filters/callback.py
Normal 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
|
|
@ -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"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user