mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 19:16:43 +00:00
Support answering inline queries with empty text (#1053)
This commit is contained in:
parent
8c0250f775
commit
4b9b77614f
@ -125,8 +125,11 @@ class InlineBuilder:
|
|||||||
type='photo',
|
type='photo',
|
||||||
photo=fh,
|
photo=fh,
|
||||||
send_message=await self._message(
|
send_message=await self._message(
|
||||||
text=text, parse_mode=parse_mode, link_preview=link_preview,
|
text=text or '',
|
||||||
geo=geo, period=period,
|
parse_mode=parse_mode,
|
||||||
|
link_preview=link_preview,
|
||||||
|
geo=geo,
|
||||||
|
period=period,
|
||||||
contact=contact,
|
contact=contact,
|
||||||
game=game,
|
game=game,
|
||||||
buttons=buttons
|
buttons=buttons
|
||||||
@ -200,8 +203,14 @@ class InlineBuilder:
|
|||||||
type=type,
|
type=type,
|
||||||
document=fh,
|
document=fh,
|
||||||
send_message=await self._message(
|
send_message=await self._message(
|
||||||
text=text, parse_mode=parse_mode, link_preview=link_preview,
|
# Empty string for text if there's media but text is None.
|
||||||
geo=geo, period=period,
|
# We may want to display a document but send text; however
|
||||||
|
# default to sending the media (without text, i.e. stickers).
|
||||||
|
text=text or '',
|
||||||
|
parse_mode=parse_mode,
|
||||||
|
link_preview=link_preview,
|
||||||
|
geo=geo,
|
||||||
|
period=period,
|
||||||
contact=contact,
|
contact=contact,
|
||||||
game=game,
|
game=game,
|
||||||
buttons=buttons
|
buttons=buttons
|
||||||
@ -247,8 +256,9 @@ class InlineBuilder:
|
|||||||
text=None, parse_mode=(), link_preview=True,
|
text=None, parse_mode=(), link_preview=True,
|
||||||
geo=None, period=60, contact=None, game=False, buttons=None
|
geo=None, period=60, contact=None, game=False, buttons=None
|
||||||
):
|
):
|
||||||
args = (text, geo, contact, game)
|
# Empty strings are valid but false-y; if they're empty use dummy '\0'
|
||||||
if sum(1 for x in args if x) != 1:
|
args = ('\0' if text == '' else text, geo, contact, game)
|
||||||
|
if sum(1 for x in args if x is not None and x is not False) != 1:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Must set exactly one of text, geo, contact or game (set {})'
|
'Must set exactly one of text, geo, contact or game (set {})'
|
||||||
.format(', '.join(x[0] for x in zip(
|
.format(', '.join(x[0] for x in zip(
|
||||||
@ -256,7 +266,10 @@ class InlineBuilder:
|
|||||||
)
|
)
|
||||||
|
|
||||||
markup = self._client.build_reply_markup(buttons, inline_only=True)
|
markup = self._client.build_reply_markup(buttons, inline_only=True)
|
||||||
if text:
|
if text is not None:
|
||||||
|
if not text: # Automatic media on empty string, like stickers
|
||||||
|
return types.InputBotInlineMessageMediaAuto('')
|
||||||
|
|
||||||
text, msg_entities = await self._client._parse_message_text(
|
text, msg_entities = await self._client._parse_message_text(
|
||||||
text, parse_mode
|
text, parse_mode
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user