def get_chats_keyboard(page: int): chats = Chat.select().order_by(Chat.id).page(page) keyboard = [] for chat in chats: if chat.is_subscribed(): data = 'chats_unsubscribe_{}_{}'.format(chat.chat_id, page) text = '🔔 {}' else: data = 'chats_subscribe_{}_{}'.format(chat.chat_id, page) text = '🔕 {}' keyboard.append([InlineKeyboardButton(text.format(chat.name), callback_data=data)]) footer = [] if page > 1: footer.append(InlineKeyboardButton( BTN_PREV_PAGE, callback_data='chats_{}'.format(page - 1))) footer.append(InlineKeyboardButton( MENU_RETURN, callback_data='admin_return')) if count(c for c in Chat) > page * 10: footer.append(InlineKeyboardButton( BTN_NEXT_PAGE, callback_data='chats_{}'.format(page + 1))) keyboard.append(footer) return keyboard
def get_subscribed_chats() -> list: return [c.chat_id for c in Chat.select(lambda s: s.is_subscribed())]