def add_word_category(self, update, context, student): student.destination = 'Add custom word' student.callback_data = [c.name for c in self.categories] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.message.reply_text(text='Now choose category.' + self.menu_text, reply_markup=reply_markup)
def menu(self, update, context, student): """ Display bot menu :param bot: telegram.ext.Dispatcher.bot :param update: telegram.Update :param student: users.models.Student """ menu_list = [ 'Add words', 'My words', 'Learn words', 'Play matching', 'Play reversed matching', 'Play typing', 'Play reversed typing', 'Help', 'Change learn language', 'Add more learn language', ] student.callback_data = menu_list reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=2)) student.destination = 'Menu_action' update.message.reply_text(text='Menu' + self.menu_text, reply_markup=reply_markup)
def show_category_words(self, update, context, student): category = student.callback_data[int(update.callback_query.data)] category = self.categories.get(name=category) category_language = self.langs.get( name=student.student.current_language) translate_language = self.langs.get(name=student.student.home_language) category_words = self.global_words.filter( category=category, language=category_language, translate_language=translate_language) student.callback_data = ['Add all'] student.destination = 'Add from global word' reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.message.edit_text(text=category.name, reply_markup=reply_markup) for word in category_words: button_list = [ InlineKeyboardButton(text='Add', callback_data=str(word.pk)) ] reply_markup = InlineKeyboardMarkup( build_menu(button_list, n_cols=3)) update.message.reply_text( text='Word [%s]\nPronunciation [%s]\nTranslation [%s]' % (word.name, word.pronunciation, word.translation), reply_markup=reply_markup) student.temp_data = {'category': category, 'words': category_words}
def choose_from_presets(self, update, context, student): student.callback_data = [c.name for c in self.categories] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) student.destination = 'Show category words' update.message.edit_text(text='Choose category' + self.menu_text, reply_markup=reply_markup)
def register_home_language(self, update, context, student): student.destination = 'Register current language' student.temp_data['home_language'] = student.callback_data[int( update.callback_query.data)] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.callback_query.message.edit_text( text='Now choose your learn language') update.callback_query.message.reply_text(text=' -:- ', reply_markup=reply_markup)
def add_words(self, update, context, student): student.callback_data = [ 'Add word by typing', 'Choose word from presets' ] student.destination = 'Add words option' reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.message.edit_text(text='How do you want to add word?' + self.menu_text, reply_markup=reply_markup)
def register_current_language(self, update, context, student): student.destination = 'Accept privacy policy' student.temp_data['current_language'] = student.callback_data[int( update.callback_query.data)] student.callback_data = ['Yes', 'No'] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.callback_query.message.edit_text( text='To use our service you need to accept Privacy Policy.' ' You can read it at https://linguint.pro/privacy_policy . ' 'Do you accept Privacy Policy?', reply_markup=reply_markup)
def register_first_name(self, update, context, student): student.destination = 'Register home language' student.temp_data = { 'username': update.effective_user.id, 'first_name': update.message.text } student.callback_data = [l.name for l in self.langs] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.message.reply_text( text='Okay %s. Now choose your home language' % update.message.text, reply_markup=reply_markup)
def add_more_learn_language(self, update, context, student): """ Adding new learn language for student from list :param bot: telegram.ext.Dispatcher.bot :param update: telegram.Update :param student: users.models.Student """ student.destination = 'Change language' student.callback_data = [l.name for l in self.langs] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.callback_query.message.edit_text( 'Choose your new learn language' + self.menu_text, reply_markup=reply_markup)
def change_learn_language(self, update, context, student): """ Change student current learn language from list of all student learn languages :param bot: telegram.ext.Dispatcher.bot :param update: telegram.Update :param student: users.models.Student """ student.destination = 'Change language' cats = student.student.language_set.all() student.callback_data = [c.name for c in cats] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.callback_query.message.edit_text('Choose your learn language' + self.menu_text, reply_markup=reply_markup)
def play_matching_result(self, update, context, student): answer = student.callback_data[int(update.callback_query.data)] word = student.temp_data['answer'] reverse = False learned = False if student.destination == 'Play matching result': learned = self.check_answer(word.translation, answer) student.destination = 'Play matching' else: reverse = True learned = self.check_answer(word.name, answer) student.destination = 'Play reversed matching' student.HQ.update_match_field(word, learned['update'], reverse) student.callback_data = ['Next'] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) update.message.edit_text(text=learned['text'] + self.menu_text, reply_markup=reply_markup)
def search_word(self, update, context, student): result = student.HQ.search_word(word_name=update.message.text.strip()) if result['global_word_search'] is False and result[ 'google_translate_search'] is False: student.temp_data['word_name'] = update.message.text.strip() student.destination = 'Add word translation' update.message.reply_text( text= 'Sorry. Could not find any translation. Enter your translation:' ) if result['google_translate_search'] is True: student.temp_data['word_name'] = result['words'].origin student.temp_data['translation'] = result['words'].text student.temp_data['pronunciation'] = result['words'].pronunciation student.callback_data = ['Yes', 'No'] reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=2)) student.destination = 'Translation option' update.message.reply_text( text='Found with internet search \n' 'Word [%s] \n Pronunciation [%s]\n Translation [%s]' % (result['words'].origin, result['words'].pronunciation, result['words'].text)) update.message.reply_text(text='Add custom word translation?' + self.menu_text, reply_markup=reply_markup) if result['global_word_search'] is True: # TODO: Add multiple search results update.message.reply_text( text='Found in data base search \n' 'Word [%s] \n Pronunciation [%s]\n Translation [%s] \n Category [%s]' % (result['words'][0].name, result['words'][0].pronunciation, result['words'][0].translation, str([ cat.name for cat in result['words'][0].category_set.all() ]))) student.HQ.add_from_global_word(global_word=result['words'][0]) update.message.reply_text('Word(s) added') self.dispatch_destination(update, context, student, 'Menu')
def play_matching(self, update, context, student): reverse = False if student.destination == 'Play matching' else True game = student.HQ.play_matching(reverse=reverse) if game == 'No words to play matching': update.message.edit_text(text='No words to play matching') self.dispatch_destination(update, context, student, 'Menu') else: student.temp_data = {'answer': game['answer']} if reverse is False: student.destination = 'Play matching result' student.callback_data = [ word.translation for word in game['words'] ] text = game['answer'].name else: student.destination = 'Play reversed matching result' student.callback_data = [word.name for word in game['words']] text = game['answer'].translation reply_markup = InlineKeyboardMarkup( build_menu(make_button_list(self, update, student), n_cols=1)) # Todo Improve button length update.message.edit_text(text=text + self.menu_text, reply_markup=reply_markup)
def my_words_option(self, update, context, student): choice = student.callback_data[int(update.callback_query.data)] student.destination = choice student.callback_data = student.HQ.get_student_categories() reply_markup = InlineKeyboardMarkup(build_menu(make_button_list(self, update, student), n_cols=1)) update.message.edit_text(text='Now choose category.'+self.menu_text, reply_markup=reply_markup)
def my_words(self, update, context, student): student.callback_data = ['Look all your words', 'Look learned words'] reply_markup = InlineKeyboardMarkup(build_menu(make_button_list(self, update, student), n_cols=2)) student.destination = 'My words option' update.message.edit_text(text='My words'+self.menu_text, reply_markup=reply_markup)