def keyboard(key, counts):
# We don't want a keyboard if there's no results
if counts[1] == 0:
return None
cur_page = counts[0] // 3 + 1
last_page = math.ceil((counts[1]) / 3)
data = 'page|{}|{}'.format(key, '{}')
buttons = [InlineKeyboardButton('First' if cur_page > 1 else ' ',
callback_data=data.format(1) if cur_page > 1 else 'page'),
InlineKeyboardButton('Previous'.format(cur_page - 1) if cur_page > 1 else '?',
callback_data=data.format((cur_page - 1)) if cur_page > 1 else 'page'),
InlineKeyboardButton('•{}•'.format(cur_page),
callback_data='page'),
InlineKeyboardButton('Next'.format(cur_page + 1) if cur_page < last_page else '?',
callback_data=data.format(cur_page + 1) if cur_page < last_page else 'page'),
InlineKeyboardButton('Last'.format(last_page) if cur_page < last_page else ' ',
callback_data=data.format(last_page) if cur_page < last_page else 'page')]
return InlineKeyboardMarkup([buttons])
评论列表
文章目录