def reply_select_books(update: Update, context: CallbackContext): query = update.callback_query message = update.effective_message # Если функция вызвана из CallbackQueryHandler if query: query.answer() current_index = int(context.match.group(1)) else: current_index = 0 prev_index = (current_index - 1) % len(BOOKS) next_index = (current_index + 1) % len(BOOKS) book = BOOKS[current_index] cover = book.get_coverpage_io() title = book.title_html reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton(text_of.BTN_PREV, callback_data=fill_string_pattern( PATTERN_SELECT_BOOKS, prev_index)), InlineKeyboardButton(text_of.BTN_NEXT, callback_data=fill_string_pattern( PATTERN_SELECT_BOOKS, next_index)) ], [book.get_button_book(text_of.BTN_SELECT_BOOK)]]) if query: message.edit_media(InputMediaPhoto(cover, title, parse_mode=ParseMode.HTML), reply_markup=reply_markup) else: message.reply_photo(cover, title, reply_markup=reply_markup, parse_mode=ParseMode.HTML)
def get_button_page(self, from_page: str, page: str, text: str = None, visited_pages: List[str] = None, is_visited=False) -> InlineKeyboardButton: postfix = '' if visited_pages: result = self.check_path(page, visited_pages, is_visited) if result == VisitedPathEnum.FULL: postfix = emoji.VISITED_FULL elif result == VisitedPathEnum.PARTIALLY: postfix = emoji.VISITED_PARTIALLY callback_data = fill_string_pattern(PATTERN_BOOK_PAGE, self.id, from_page, page) return InlineKeyboardButton(text=f"{text or page} {postfix}", callback_data=callback_data)
def get_button_delete_message(text: str) -> InlineKeyboardButton: return InlineKeyboardButton( text, callback_data=fill_string_pattern(PATTERN_DELETE_MESSAGE))
def get_button_annotation(self) -> InlineKeyboardButton: callback_data = fill_string_pattern(PATTERN_BOOK_ANNOTATION, self.id) return InlineKeyboardButton(text=text_of.BTN_ANNOTATION, callback_data=callback_data)
def get_button_all_images(self) -> InlineKeyboardButton: callback_data = fill_string_pattern(PATTERN_BOOK_ALL_IMAGES, self.id) return InlineKeyboardButton(text=text_of.BTN_ALL_IMAGES, callback_data=callback_data)
def get_button_image(self, text: str, img_name: str) -> InlineKeyboardButton: callback_data = fill_string_pattern(PATTERN_BOOK_IMAGE, self.id, img_name) return InlineKeyboardButton(text=text, callback_data=callback_data)
def get_button_book(self, text) -> InlineKeyboardButton: callback_data = fill_string_pattern(PATTERN_BOOK, self.id) return InlineKeyboardButton(text=text, callback_data=callback_data)
def get_button_coin_flip(text: str) -> InlineKeyboardButton: return InlineKeyboardButton( text, callback_data=fill_string_pattern(PATTERN_COIN_FLIP))