implement callback data filter

This commit is contained in:
apepenkov 2023-11-09 20:57:10 +03:00
parent ca0d39c4b7
commit adeb5f8d73
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 CallbackData
__all__ = [ __all__ = [
"All", "All",
@ -17,4 +18,5 @@ __all__ = [
"Outgoing", "Outgoing",
"Reply", "Reply",
"Text", "Text",
"CallbackData",
] ]

View File

@ -0,0 +1,23 @@
from __future__ import annotations
from .combinators import Combinable
from ..event import Event
class CallbackData(Combinable):
"""
Filter by ``event.data`` using a full bytes match, used for callback events :class:`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,
CallbackData,
) )
__all__ = [ __all__ = [
@ -39,4 +40,5 @@ __all__ = [
"Reply", "Reply",
"Senders", "Senders",
"Text", "Text",
"CallbackData"
] ]