From dc29a95cef8deca2f18cb1cc95f8ba879a6512b9 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 17 Sep 2021 21:03:47 +0200 Subject: [PATCH] Change list of buttons to show up as rows and not cols --- readthedocs/misc/v2-migration-guide.rst | 27 +++++++++++++++++++++++++ telethon/_client/buttons.py | 6 +++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/readthedocs/misc/v2-migration-guide.rst b/readthedocs/misc/v2-migration-guide.rst index 7e7a2302..4276dec8 100644 --- a/readthedocs/misc/v2-migration-guide.rst +++ b/readthedocs/misc/v2-migration-guide.rst @@ -204,6 +204,33 @@ either ``.md_text`` or ``.html_text`` as needed. This is because both ``.text`` may disappear in future versions, and their behaviour is not immediately obvious. +Using a flat list to define buttons will now create rows and not columns +------------------------------------------------------------------------ + +When sending a message with buttons under a bot account, passing a flat list such as the following: + +.. code-block:: python + + bot.send_message(chat, message, buttons=[ + Button.inline('top'), + Button.inline('middle'), + Button.inline('bottom'), + ]) + +Will now send a message with 3 rows of buttons, instead of a message with 3 columns (old behaviour). +If you still want the old behaviour, wrap the list inside another list: + +.. code-block:: python + + bot.send_message(chat, message, buttons=[[ + # + + Button.inline('top'), + Button.inline('middle'), + Button.inline('bottom'), + ]]) + #+ + + The Conversation API has been removed ------------------------------------- diff --git a/telethon/_client/buttons.py b/telethon/_client/buttons.py index fbd0f51c..599ebc96 100644 --- a/telethon/_client/buttons.py +++ b/telethon/_client/buttons.py @@ -8,7 +8,7 @@ from ..types import _custom def build_reply_markup( buttons: 'typing.Optional[hints.MarkupLike]', inline_only: bool = False) -> 'typing.Optional[_tl.TypeReplyMarkup]': - if buttons is None: + if not buttons: return None try: @@ -18,9 +18,9 @@ def build_reply_markup( pass if not utils.is_list_like(buttons): - buttons = [[buttons]] - elif not buttons or not utils.is_list_like(buttons[0]): buttons = [buttons] + if not utils.is_list_like(buttons[0]): + buttons = [[b] for b in buttons] is_inline = False is_normal = False