Skip to content

Commit 7bb96c3

Browse files
authored
feat(pyrogram.filters): Support filters.regex for ChosenInlineResult. (#243)
1 parent b4f745d commit 7bb96c3

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

pyrogram/filters.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222

2323
import pyrogram
2424
from pyrogram import enums
25-
from pyrogram.types import Message, CallbackQuery, InlineQuery, PreCheckoutQuery, InlineKeyboardMarkup, ReplyKeyboardMarkup, Update
25+
from pyrogram.types import (
26+
Message,
27+
CallbackQuery,
28+
ChosenInlineResult,
29+
InlineQuery,
30+
PreCheckoutQuery,
31+
InlineKeyboardMarkup,
32+
ReplyKeyboardMarkup,
33+
Update,
34+
)
2635

2736

2837
class Filter:
@@ -1007,6 +1016,7 @@ def regex(pattern: Union[str, Pattern], flags: int = 0):
10071016
10081017
- :obj:`~pyrogram.types.Message`: The filter will match ``text`` or ``caption``.
10091018
- :obj:`~pyrogram.types.CallbackQuery`: The filter will match ``data``.
1019+
- :obj:`~pyrogram.types.ChosenInlineResult`: The filter will match ``query``.
10101020
- :obj:`~pyrogram.types.InlineQuery`: The filter will match ``query``.
10111021
- :obj:`~pyrogram.types.PreCheckoutQuery`: The filter will match ``payload``.
10121022
@@ -1026,7 +1036,7 @@ async def func(flt, _, update: Update):
10261036
value = update.text or update.caption
10271037
elif isinstance(update, CallbackQuery):
10281038
value = update.data
1029-
elif isinstance(update, InlineQuery):
1039+
elif isinstance(update, (ChosenInlineResult, InlineQuery)):
10301040
value = update.query
10311041
elif isinstance(update, PreCheckoutQuery):
10321042
value = update.invoice_payload

pyrogram/types/inline_mode/chosen_inline_result.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from typing import List, Match
20+
1921
import pyrogram
2022
from pyrogram import raw
2123
from pyrogram import types
@@ -49,6 +51,10 @@ class ChosenInlineResult(Object, Update):
4951
Identifier of the sent inline message.
5052
Available only if there is an :doc:`inline keyboard <InlineKeyboardMarkup>` attached to the message.
5153
Will be also received in :doc:`callback queries <CallbackQuery>` and can be used to edit the message.
54+
55+
matches (List of regex Matches, *optional*):
56+
A list containing all `Match Objects <https://docs.python.org/3/library/re.html#match-objects>`_ that match
57+
the query of this chosen query. Only applicable when using :obj:`Filters.regex <pyrogram.Filters.regex>`.
5258
"""
5359

5460
def __init__(
@@ -59,7 +65,8 @@ def __init__(
5965
from_user: "types.User",
6066
query: str,
6167
location: "types.Location" = None,
62-
inline_message_id: str = None
68+
inline_message_id: str = None,
69+
matches: List[Match] = None,
6370
):
6471
super().__init__(client)
6572

@@ -68,6 +75,7 @@ def __init__(
6875
self.query = query
6976
self.location = location
7077
self.inline_message_id = inline_message_id
78+
self.matches = matches
7179

7280
@staticmethod
7381
def _parse(client, chosen_inline_result: raw.types.UpdateBotInlineSend, users) -> "ChosenInlineResult":

0 commit comments

Comments
 (0)