From 9ee415749d7c08fc21c08d942951358b000db676 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 12 Oct 2018 11:50:36 +0200 Subject: [PATCH] Fix InlineBuilder.photo/document and clearer errors --- telethon/tl/custom/__init__.py | 2 +- .../tl/custom/{inline.py => inlinebuilder.py} | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) rename telethon/tl/custom/{inline.py => inlinebuilder.py} (93%) diff --git a/telethon/tl/custom/__init__.py b/telethon/tl/custom/__init__.py index 8db2d53f..2a7b7aa8 100644 --- a/telethon/tl/custom/__init__.py +++ b/telethon/tl/custom/__init__.py @@ -5,7 +5,7 @@ from .messagebutton import MessageButton from .forward import Forward from .message import Message from .button import Button -from .inline import InlineBuilder +from .inlinebuilder import InlineBuilder from .inlineresult import InlineResult from .inlineresults import InlineResults from .conversation import Conversation diff --git a/telethon/tl/custom/inline.py b/telethon/tl/custom/inlinebuilder.py similarity index 93% rename from telethon/tl/custom/inline.py rename to telethon/tl/custom/inlinebuilder.py index 4a9070be..8a9e6582 100644 --- a/telethon/tl/custom/inline.py +++ b/telethon/tl/custom/inlinebuilder.py @@ -115,10 +115,10 @@ class InlineBuilder: Same as ``file`` for `client.send_file `. """ - fh = self._client.upload_file(file, use_cache=types.InputPhoto) + fh = await self._client.upload_file(file, use_cache=types.InputPhoto) if not isinstance(fh, types.InputPhoto): r = await self._client(functions.messages.UploadMediaRequest( - types.InputPeerEmpty(), media=types.InputMediaUploadedPhoto(fh) + types.InputPeerSelf(), media=types.InputMediaUploadedPhoto(fh) )) fh = utils.get_input_photo(r.photo) @@ -177,9 +177,9 @@ class InlineBuilder: type = 'document' use_cache = types.InputDocument if use_cache else None - fh = self._client.upload_file(file, use_cache=use_cache) + fh = await self._client.upload_file(file, use_cache=use_cache) if not isinstance(fh, types.InputDocument): - attributes, mime_type = utils.get_attributes( + attributes, mime_type = utils.get_attributes( file, mime_type=mime_type, attributes=attributes, @@ -188,7 +188,7 @@ class InlineBuilder: video_note=video_note ) r = await self._client(functions.messages.UploadMediaRequest( - types.InputPeerEmpty(), media=types.InputMediaUploadedDocument( + types.InputPeerSelf(), media=types.InputMediaUploadedDocument( fh, mime_type=mime_type, attributes=attributes, @@ -249,8 +249,13 @@ class InlineBuilder: text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): - if sum(1 for x in (text, geo, contact, game) if x) != 1: - raise ValueError('Can only use one of text, geo, contact or game') + args = (text, geo, contact, game) + if sum(1 for x in args if x) != 1: + raise ValueError( + 'Must set exactly one of text, geo, contact or game (set {})' + .format(', '.join(x[0] for x in zip( + 'text geo contact game'.split(), args) if x[1]) or 'none') + ) markup = self._client.build_reply_markup(buttons, inline_only=True) if text: