From 0a96355c5dcda94a7ce982421ca0eeba66adf80d Mon Sep 17 00:00:00 2001 From: ColinShark Date: Sat, 1 Jun 2019 23:31:17 +0200 Subject: [PATCH 1/6] Add Filter for Callback_Query.data --- pyrogram/client/filters/filters.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 9c80d870..a3e39117 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -339,4 +339,19 @@ class Filters: and message.from_user.is_self and not message.outgoing))) + @staticmethod + def data(data: str or bytes = None): + """Filter callback queries for their data. + + Parameters: + data (``str`` | ``bytes``): + Pass the data you want to filter for. + Defaults to None (no data). + """ + + def f(_, cb): + return bool(cb.data and cb.data == _.d) + + return create("Data", f, d=data) + dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) From 2eba6e58f9f0eb983aedc25ea9b0c250bd52980a Mon Sep 17 00:00:00 2001 From: ColinShark Date: Sat, 1 Jun 2019 23:34:20 +0200 Subject: [PATCH 2/6] Remove Optionality for args --- pyrogram/client/filters/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index a3e39117..83e862e6 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -340,7 +340,7 @@ class Filters: and not message.outgoing))) @staticmethod - def data(data: str or bytes = None): + def data(data: str or bytes): """Filter callback queries for their data. Parameters: From 04aada818e4a6482128ff7448a6a8843b7adf0cc Mon Sep 17 00:00:00 2001 From: ColinShark Date: Sat, 1 Jun 2019 23:36:45 +0200 Subject: [PATCH 3/6] Less arbitrary name for Filter, Adapt Docstring --- pyrogram/client/filters/filters.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 83e862e6..c8b5b2f8 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -346,12 +346,11 @@ class Filters: Parameters: data (``str`` | ``bytes``): Pass the data you want to filter for. - Defaults to None (no data). """ def f(_, cb): return bool(cb.data and cb.data == _.d) - return create("Data", f, d=data) + return create("CallbackData", f, d=data) dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) From d3cb386a6f68eaa9ab94656c8826dd9b7c86d82b Mon Sep 17 00:00:00 2001 From: ColinShark Date: Sat, 1 Jun 2019 23:39:26 +0200 Subject: [PATCH 4/6] Appropiate naming --- pyrogram/client/filters/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index c8b5b2f8..1bcc858d 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -340,7 +340,7 @@ class Filters: and not message.outgoing))) @staticmethod - def data(data: str or bytes): + def callback_data(data: str or bytes): """Filter callback queries for their data. Parameters: From 12cc6fa4eb038af53621e14cf0b0565cc3b5db6f Mon Sep 17 00:00:00 2001 From: ColinShark Date: Sun, 2 Jun 2019 00:13:52 +0200 Subject: [PATCH 5/6] Removed Placeholder, break down comparison --- pyrogram/client/filters/filters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 1bcc858d..12d5a69e 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -348,9 +348,9 @@ class Filters: Pass the data you want to filter for. """ - def f(_, cb): - return bool(cb.data and cb.data == _.d) + def f(flt, cb): + return cb.data == flt.data - return create("CallbackData", f, d=data) + return create("CallbackData", f, data=data) dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162)) From 5cb709ee75bdf16065a9f213c78f34b87ed41107 Mon Sep 17 00:00:00 2001 From: ColinShark Date: Sun, 2 Jun 2019 00:25:59 +0200 Subject: [PATCH 6/6] Make it one-line --- pyrogram/client/filters/filters.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 12d5a69e..1d962e85 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -348,9 +348,6 @@ class Filters: Pass the data you want to filter for. """ - def f(flt, cb): - return cb.data == flt.data - - return create("CallbackData", f, data=data) + return create("CallbackData", lambda flt, cb: cb.data == flt.data, data=data) dan = create("Dan", lambda _, m: bool(m.from_user and m.from_user.id == 23122162))