1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Minor keyboard update followup

This commit is contained in:
Badiboy 2020-08-02 18:58:22 +03:00
parent e987e40ee7
commit cc36207992
2 changed files with 25 additions and 15 deletions

View File

@ -18,7 +18,7 @@ console_output_handler = logging.StreamHandler(sys.stderr)
console_output_handler.setFormatter(formatter) console_output_handler.setFormatter(formatter)
logger.addHandler(console_output_handler) logger.addHandler(console_output_handler)
logger.setLevel(logging.WARNING) logger.setLevel(logging.ERROR)
from telebot import apihelper, types, util from telebot import apihelper, types, util
from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend

View File

@ -808,10 +808,13 @@ class ReplyKeyboardRemove(JsonSerializable):
class ReplyKeyboardMarkup(JsonSerializable): class ReplyKeyboardMarkup(JsonSerializable):
max_row_keys = 12
def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3): def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3):
if row_width>12: if row_width > self.max_row_keys:
logger.warning('Telegram does not support reply keyboard row width over 12') # Todo: Will be replaced with Exception in future releases
row_width=12 logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
self.resize_keyboard = resize_keyboard self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard self.one_time_keyboard = one_time_keyboard
@ -830,12 +833,14 @@ class ReplyKeyboardMarkup(JsonSerializable):
:param row_width: width of row :param row_width: width of row
:return: self, to allow function chaining. :return: self, to allow function chaining.
""" """
row_width = row_width or self.row_width if row_width is None:
row_width = self.row_width
if row_width>12: if row_width > self.max_row_keys:
logger.warning('Telegram does not support reply keyboard row width over 12') # Todo: Will be replaced with Exception in future releases
row_width=12 logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
for row in util.chunks(args, row_width): for row in util.chunks(args, row_width):
button_array = [] button_array = []
@ -907,6 +912,8 @@ class KeyboardButtonPollType(Dictionaryable):
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable): class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
max_row_keys = 12
def __init__(self, row_width=3): def __init__(self, row_width=3):
""" """
This object represents an inline keyboard that appears This object represents an inline keyboard that appears
@ -914,9 +921,10 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
:return: :return:
""" """
if row_width>8: if row_width > self.max_row_keys:
logger.warning('Telegram does not support inline keyboard row width over 8') # Todo: Will be replaced with Exception in future releases
row_width=8 logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
self.row_width = row_width self.row_width = row_width
self.keyboard = [] self.keyboard = []
@ -936,11 +944,13 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
:param row_width: width of row :param row_width: width of row
:return: self, to allow function chaining. :return: self, to allow function chaining.
""" """
row_width = row_width or self.row_width if row_width is None:
row_width = self.row_width
if row_width>8: if row_width > self.max_row_keys:
logger.warning('Telegram does not support inline keyboard row width over 8') # Todo: Will be replaced with Exception in future releases
row_width=8 logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
for row in util.chunks(args, row_width): for row in util.chunks(args, row_width):
button_array = [button.to_dict() for button in row] button_array = [button.to_dict() for button in row]