mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 19:00:21 +03:00
Support buttons when sending a file too
This commit is contained in:
parent
8c28be04bc
commit
531a02a2a1
|
@ -15,7 +15,7 @@ from ..tl import types, functions, custom
|
||||||
__log__ = logging.getLogger(__name__)
|
__log__ = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MessageMethods(ButtonMethods, UploadMethods, MessageParseMethods):
|
class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
@ -396,7 +396,8 @@ class MessageMethods(ButtonMethods, UploadMethods, MessageParseMethods):
|
||||||
if file is not None:
|
if file is not None:
|
||||||
return await self.send_file(
|
return await self.send_file(
|
||||||
entity, file, caption=message, reply_to=reply_to,
|
entity, file, caption=message, reply_to=reply_to,
|
||||||
parse_mode=parse_mode, force_document=force_document
|
parse_mode=parse_mode, force_document=force_document,
|
||||||
|
buttons=buttons
|
||||||
)
|
)
|
||||||
elif not message:
|
elif not message:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
|
@ -7,7 +7,7 @@ from . import (
|
||||||
|
|
||||||
class TelegramClient(
|
class TelegramClient(
|
||||||
AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
|
AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
|
||||||
MessageMethods, ButtonMethods, UpdateMethods, UploadMethods,
|
MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
|
||||||
MessageParseMethods, UserMethods
|
MessageParseMethods, UserMethods
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -9,6 +9,7 @@ from mimetypes import guess_type
|
||||||
|
|
||||||
from .messageparse import MessageParseMethods
|
from .messageparse import MessageParseMethods
|
||||||
from .users import UserMethods
|
from .users import UserMethods
|
||||||
|
from .buttons import ButtonMethods
|
||||||
from .. import utils, helpers
|
from .. import utils, helpers
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ except ImportError:
|
||||||
__log__ = logging.getLogger(__name__)
|
__log__ = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class UploadMethods(MessageParseMethods, UserMethods):
|
class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ class UploadMethods(MessageParseMethods, UserMethods):
|
||||||
self, entity, file, *, caption='', force_document=False,
|
self, entity, file, *, caption='', force_document=False,
|
||||||
progress_callback=None, reply_to=None, attributes=None,
|
progress_callback=None, reply_to=None, attributes=None,
|
||||||
thumb=None, allow_cache=True, parse_mode=utils.Default,
|
thumb=None, allow_cache=True, parse_mode=utils.Default,
|
||||||
voice_note=False, video_note=False, **kwargs):
|
voice_note=False, video_note=False, buttons=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Sends a file to the specified entity.
|
Sends a file to the specified entity.
|
||||||
|
|
||||||
|
@ -98,6 +99,13 @@ class UploadMethods(MessageParseMethods, UserMethods):
|
||||||
Set `allow_cache` to ``False`` if you sent the same file
|
Set `allow_cache` to ``False`` if you sent the same file
|
||||||
without this setting before for it to work.
|
without this setting before for it to work.
|
||||||
|
|
||||||
|
buttons (`list`, `custom.Button <telethon.tl.custom.button.Button>`,
|
||||||
|
:tl:`KeyboardButton`):
|
||||||
|
The matrix (list of lists), row list or button to be shown
|
||||||
|
after sending the message. This parameter will only work if
|
||||||
|
you have signed in as a bot. You can also pass your own
|
||||||
|
:tl:`ReplyMarkup` here.
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
If the ``hachoir3`` package (``hachoir`` module) is installed,
|
If the ``hachoir3`` package (``hachoir`` module) is installed,
|
||||||
it will be used to determine metadata from audio and video files.
|
it will be used to determine metadata from audio and video files.
|
||||||
|
@ -136,7 +144,7 @@ class UploadMethods(MessageParseMethods, UserMethods):
|
||||||
caption=caption, force_document=force_document,
|
caption=caption, force_document=force_document,
|
||||||
progress_callback=progress_callback, reply_to=reply_to,
|
progress_callback=progress_callback, reply_to=reply_to,
|
||||||
attributes=attributes, thumb=thumb, voice_note=voice_note,
|
attributes=attributes, thumb=thumb, voice_note=voice_note,
|
||||||
video_note=video_note, **kwargs
|
video_note=video_note, buttons=buttons, **kwargs
|
||||||
))
|
))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -159,9 +167,10 @@ class UploadMethods(MessageParseMethods, UserMethods):
|
||||||
voice_note=voice_note, video_note=video_note
|
voice_note=voice_note, video_note=video_note
|
||||||
)
|
)
|
||||||
|
|
||||||
|
markup = self._build_reply_markup(buttons)
|
||||||
request = functions.messages.SendMediaRequest(
|
request = functions.messages.SendMediaRequest(
|
||||||
entity, media, reply_to_msg_id=reply_to, message=caption,
|
entity, media, reply_to_msg_id=reply_to, message=caption,
|
||||||
entities=msg_entities
|
entities=msg_entities, reply_markup=markup
|
||||||
)
|
)
|
||||||
msg = self._get_response_message(request, await self(request), entity)
|
msg = self._get_response_message(request, await self(request), entity)
|
||||||
self._cache_media(msg, file, file_handle, force_document=force_document)
|
self._cache_media(msg, file, file_handle, force_document=force_document)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user