mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-19 07:35:19 +00:00
Allow for Pattern Matching Empty Inline Queries (#4817)
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> Co-authored-by: locobott <25104044+locobott@users.noreply.github.com>
This commit is contained in:
@@ -93,6 +93,8 @@ telegram.jpg
|
||||
|
||||
# virtual env
|
||||
venv*
|
||||
pyvenv.cfg
|
||||
Scripts/
|
||||
|
||||
# environment manager:
|
||||
.mise.toml
|
||||
@@ -80,6 +80,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||
- `Kirill Vasin <https://github.com/vasinkd>`_
|
||||
- `Kjwon15 <https://github.com/kjwon15>`_
|
||||
- `Li-aung Yip <https://github.com/LiaungYip>`_
|
||||
- `locobott <https://github.com/locobott>`_
|
||||
- `Loo Zheng Yuan <https://github.com/loozhengyuan>`_
|
||||
- `LRezende <https://github.com/lrezende>`_
|
||||
- `Luca Bellanti <https://github.com/Trifase>`_
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
bugfixes = "Allow for pattern matching empty inline queries"
|
||||
[[pull_requests]]
|
||||
uid = "4817"
|
||||
author_uid = "locobott"
|
||||
closes_threads = []
|
||||
@@ -118,11 +118,7 @@ class InlineQueryHandler(BaseHandler[Update, CCT, RT]):
|
||||
update.inline_query.chat_type not in self.chat_types
|
||||
):
|
||||
return False
|
||||
if (
|
||||
self.pattern
|
||||
and update.inline_query.query
|
||||
and (match := re.match(self.pattern, update.inline_query.query))
|
||||
):
|
||||
if self.pattern and (match := re.match(self.pattern, update.inline_query.query)):
|
||||
return match
|
||||
if not self.pattern:
|
||||
return True
|
||||
|
||||
@@ -152,6 +152,28 @@ class TestInlineQueryHandler:
|
||||
update.inline_query.query = "not_a_match"
|
||||
assert not handler.check_update(update)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("query", "expected_result"),
|
||||
[
|
||||
pytest.param("", True, id="empty string"),
|
||||
pytest.param("not empty", False, id="non_empty_string"),
|
||||
],
|
||||
)
|
||||
async def test_empty_inline_query_pattern(self, app, query, expected_result):
|
||||
handler = InlineQueryHandler(self.callback, pattern=r"^$")
|
||||
app.add_handler(handler)
|
||||
|
||||
update = Update(
|
||||
update_id=0,
|
||||
inline_query=InlineQuery(
|
||||
id="id", from_user=User(1, "test", False), query=query, offset=""
|
||||
),
|
||||
)
|
||||
|
||||
async with app:
|
||||
await app.process_update(update)
|
||||
assert self.test_flag == expected_result
|
||||
|
||||
@pytest.mark.parametrize("chat_types", [[Chat.SENDER], [Chat.SENDER, Chat.SUPERGROUP], []])
|
||||
@pytest.mark.parametrize(
|
||||
("chat_type", "result"), [(Chat.SENDER, True), (Chat.CHANNEL, False), (None, False)]
|
||||
|
||||
Reference in New Issue
Block a user