def library_menu_2_button(self, bot, query, chat_id): """ Меню изучения слов(по одному слову) Args: bot (:class:`telegram.Bot`): хэндлер бота query (:class:`telegram.CallbackQuery`): возвращаемое значение от inline клавиатуры chat_id (:obj:`int`) id пользователя """ index = int(query.data.split("_")[1]) # index in dic of users library dic = flags[chat_id].get_library() title = dic[index][1] # title - imdb_id of film/series logger.info("index %s title %s" % (index, dic[index][1])) postgre = DataBase() flags[chat_id].set_words(postgre.GetWordsForTitle(chat_id, title)) words = flags[chat_id].get_words() reply_markup = learn_navigate_markup_simple_version( 0, len(words), index) bot.edit_message_text( text="*%s* words left to learn for this title\n word - *%s*" % (len(words), words[0][1]), reply_markup=reply_markup, chat_id=chat_id, message_id=query.message.message_id, parse_mode=ParseMode.MARKDOWN)
def learn_button(self, bot, query, chat_id): """ Кнопка для отметки слова как изученого Args: bot (:class:`telegram.Bot`): хэндлер бота query (:class:`telegram.CallbackQuery`): возвращаемое значение от inline клавиатуры chat_id (:obj:`int`) id пользователя """ index = int(query.data.split("_")[1]) title_id = int(query.data.split("_")[2]) word = flags[chat_id].get_words() dic = flags[chat_id].get_library() title = dic[title_id][1] # title - imdb_id of film/series logger.info("Learned word is - %s" % word[index][1]) postgre = DataBase() postgre.LearnWord(word[index][0], chat_id) flags[chat_id].set_words(postgre.GetWordsForTitle( chat_id, title)) # Update words for title words = flags[chat_id].get_words() if (query.data.split("_")[3] == '1'): # if user in simple learn card logger.info("learned word and get another") index += 1 index = index % len(words) text_out = "*%s*" % words[index][1] reply_markup = learn_navigate_markup_simple_version( index, len(words), title_id) if (query.data.split("_")[4] == '1'): logger.info("Got it! Card will stay in history") bot.edit_message_reply_markup( reply_markup=None, chat_id=chat_id, message_id=query.message.message_id) bot.send_message(text=text_out, reply_markup=reply_markup, chat_id=chat_id, message_id=query.message.message_id, parse_mode=ParseMode.MARKDOWN) else: logger.info("User know word! Card would not stay in history") bot.edit_message_text(text=text_out, reply_markup=reply_markup, chat_id=chat_id, message_id=query.message.message_id, parse_mode=ParseMode.MARKDOWN) else: logger.info("index %s title %s" % (index, dic[title_id][1])) reply_markup = learn_navigate_markup(words, index, len(words), title_id) text_out = get_learn_list(words, index) bot.edit_message_reply_markup(reply_markup=None, chat_id=chat_id, message_id=query.message.message_id) bot.send_message(text=text_out, reply_markup=reply_markup, chat_id=chat_id, message_id=query.message.message_id, parse_mode=ParseMode.MARKDOWN) logger.info("navigate in learning")