Make build_reply_markup public

This commit is contained in:
Lonami Exo 2018-07-21 13:54:36 +02:00
parent 7750c9ff2f
commit 3bdfd4b32c
4 changed files with 17 additions and 6 deletions

View File

@ -4,7 +4,18 @@ from .. import utils, events
class ButtonMethods(UpdateMethods): class ButtonMethods(UpdateMethods):
def _build_reply_markup(self, buttons, inline_only=False): def build_reply_markup(self, buttons, inline_only=False):
"""
Builds a :tl`ReplyInlineMarkup` or :tl:`ReplyKeyboardMarkup` for
the given buttons, or does nothing if either no buttons are
provided or the provided argument is already a reply markup.
This will add any event handlers defined in the
buttons and delete old ones not to call them twice,
so you should probably call this method manually for
serious bots instead re-adding handlers every time you
send a message. Magic can only go so far.
"""
if buttons is None: if buttons is None:
return None return None

View File

@ -435,7 +435,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
if buttons is None: if buttons is None:
markup = message.reply_markup markup = message.reply_markup
else: else:
markup = self._build_reply_markup(buttons) markup = self.build_reply_markup(buttons)
if silent is None: if silent is None:
silent = message.silent silent = message.silent
@ -463,7 +463,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
reply_to_msg_id=utils.get_message_id(reply_to), reply_to_msg_id=utils.get_message_id(reply_to),
clear_draft=clear_draft, clear_draft=clear_draft,
silent=silent, silent=silent,
reply_markup=self._build_reply_markup(buttons) reply_markup=self.build_reply_markup(buttons)
) )
result = await self(request) result = await self(request)
@ -630,7 +630,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
no_webpage=not link_preview, no_webpage=not link_preview,
entities=msg_entities, entities=msg_entities,
media=media, media=media,
reply_markup=self._build_reply_markup(buttons) reply_markup=self.build_reply_markup(buttons)
) )
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) self._cache_media(msg, file, file_handle)

View File

@ -167,7 +167,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
voice_note=voice_note, video_note=video_note voice_note=voice_note, video_note=video_note
) )
markup = self._build_reply_markup(buttons) 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, reply_markup=markup, silent=silent entities=msg_entities, reply_markup=markup, silent=silent

View File

@ -253,7 +253,7 @@ class InlineBuilder:
if sum(1 for x in (text, geo, contact, game) if x) != 1: 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') raise ValueError('Can only use one of text, geo, contact or game')
markup = self._client._build_reply_markup(buttons, inline_only=True) markup = self._client.build_reply_markup(buttons, inline_only=True)
if text: if text:
text, msg_entities = await self._client._parse_message_text( text, msg_entities = await self._client._parse_message_text(
text, parse_mode text, parse_mode