I make a keyboard factory. Previously, the input used a string as the second parameter, hit it on characters and walked on it further, like this:
> mode = '(1..6) '... (1..6) (1..6) mode = len(dict) ''' # try: if mode == None: mode = ('1 ' * len(data)).split() else: mode = mode.split() log.info(mode) buttons = [] for key, value in enumerate(mode): buttons_inside = [] value = int(value) for i in range(value): (a piece of code, below is the full implementation)
Now I use the list. Like this:
def make_keyboard(data:list, mode=None): ''' > data = [ [callback_data, text], [callback_data, text],... ] > mode = [(1..6) ... (1..6) (1..6)] mode = [int, int] or None ''' try: if mode == None: mode = [1 for _ in range(len(data))] log.info(mode) buttons = [] for value in mode: buttons_inside = [] for i in range(value): if 1 > i > 6: raise KeyError(f'So long/short {i} row for keyboard') buttons_inside.append(types.InlineKeyboardButton(text=data[0][1], callback_data=data[0][0])) data.pop(0) buttons.append(buttons_inside) return types.InlineKeyboardMarkup(buttons) except KeyError as E: log.error(E) There was a normal answer in the form of a keyboard, now nothing. In the parameters:
reply_markup={"inline_keyboard": []} Tell me where the skis do not go?