Support answering inline queries with empty text (#1053)

This commit is contained in:
Lonami Exo 2019-01-04 11:13:13 +01:00
parent 8c0250f775
commit 4b9b77614f

View File

@ -125,8 +125,11 @@ class InlineBuilder:
type='photo',
photo=fh,
send_message=await self._message(
text=text, parse_mode=parse_mode, link_preview=link_preview,
geo=geo, period=period,
text=text or '',
parse_mode=parse_mode,
link_preview=link_preview,
geo=geo,
period=period,
contact=contact,
game=game,
buttons=buttons
@ -200,8 +203,14 @@ class InlineBuilder:
type=type,
document=fh,
send_message=await self._message(
text=text, parse_mode=parse_mode, link_preview=link_preview,
geo=geo, period=period,
# Empty string for text if there's media but text is None.
# 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,
game=game,
buttons=buttons
@ -247,8 +256,9 @@ class InlineBuilder:
text=None, parse_mode=(), link_preview=True,
geo=None, period=60, contact=None, game=False, buttons=None
):
args = (text, geo, contact, game)
if sum(1 for x in args if x) != 1:
# Empty strings are valid but false-y; if they're empty use dummy '\0'
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(
'Must set exactly one of text, geo, contact or game (set {})'
.format(', '.join(x[0] for x in zip(
@ -256,7 +266,10 @@ class InlineBuilder:
)
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, parse_mode
)