utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:teamSpeakTelegram 作者: jossalgon 项目源码 文件源码
def markup_append_pagination(bot, update, items, markup, page, callback, items_per_page=10):
    pag_max = math.ceil(len(items) / items_per_page)
    pag_button = InlineKeyboardButton(_('Page') + ' %s/%s' % (str(page), str(pag_max)),
                                      callback_data='%s_PG_NEXT' % callback)

    if len(items) >= items_per_page:
        if page == 1:
            sig_button = InlineKeyboardButton(_('Page') + ' %s/%s ?' % (str(page), str(pag_max)),
                                              callback_data='%s_PG_NEXT' % callback)
            markup.append([sig_button])

        elif 1 < page < pag_max:
            ant_button = InlineKeyboardButton('? ' + _('Prev'), callback_data='%s_PG_PREV' % callback)
            sig_button = InlineKeyboardButton('? ' + _('Next'), callback_data='%s_PG_NEXT' % callback)
            markup.append([ant_button, pag_button, sig_button])
        elif page == pag_max:
            ant_button = InlineKeyboardButton(_('Page') + ' %s/%s ?' % (str(page), str(pag_max)),
                                              callback_data='%s_PG_PREV' % callback)
            markup.append([ant_button])

    return markup
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号