def learn_word(self, message): if random.choice([True, False]): tr = GoogleTranslator(source=self.current_learning_words[ self.learning_word]["languages"]["src"], target=self.current_learning_words[ self.learning_word]["languages"]["dest"]) print(self.__get_uqicues(count=2)) self.wrong_answers = self.__get_uqicues(count=2) answers = [ f"types.InlineKeyboardButton('{tr.translate(el)}', callback_data=\"{tr.translate(el)}_answer\")" for el in self.wrong_answers ] answers.append( f"types.InlineKeyboardButton('{self.current_learning_words[self.learning_word]['values']['dest']}', callback_data=\"{self.current_learning_words[self.learning_word]['values']['dest']}_answer\")" ) answers_keyboard = types.InlineKeyboardMarkup() random.shuffle(answers) print(answers) exec(f"answers_keyboard.add({','.join(answers)})") print(answers_keyboard) bot.send_message( message.chat.id, f'choose correct translation of "**{self.current_learning_words[self.learning_word]["values"]["src"]}**"', parse_mode='Markdown', reply_markup=answers_keyboard) else: bot.send_message( message.chat.id, f'enter correct translation of "**{self.current_learning_words[self.learning_word]["values"]["src"]}**"', parse_mode='Markdown') bot.register_next_step_handler(message, self.input_truth_answer)
def send_students(self, teacher_id): students_objects = self.db.get_students(teacher_id) print(students_objects) buttons = [] temp = [] n = 'name' id = 'student_id' for i in range(len(students_objects)): buttons.append( f'types.InlineKeyboardButton("{i + 1}", callback_data="{students_objects[i][id]}_student")' ) if (i + 1) % 5 == 0: buttons.append(temp) temp = [] if temp: buttons.append(temp) print(buttons) output = [ f'{i + 1}) {students_objects[i][n]}' for i in range(len(students_objects)) ] students_keyboard = types.InlineKeyboardMarkup() exec(f'students_keyboard.add({",".join(buttons)})') students_keyboard.add( types.InlineKeyboardButton('add', callback_data='add_first_student')) bot.send_message(teacher_id, '\n'.join(output), reply_markup=students_keyboard)
def logic_alter_word(self, message): bot.send_message(message.chat.id, """ enter the destination and translation like this: ***apple - яблоко*** """, parse_mode='Markdown') bot.register_next_step_handler(message, self.alter_wrapper)
def send_full_word(self, id, word_obj): print(word_obj) bot.send_message( id, f"{word_obj['values']['src']} - {word_obj['values']['dest']}") bot.send_message( id, f'{", ".join(word_obj["syntax"]["src"]["synonyms"]) if word_obj["syntax"]["src"]["synonyms"] != None else None} - {", ".join(word_obj["syntax"]["dest"]["synonyms"]) if word_obj["syntax"]["dest"]["synonyms"] != None else None}' ) bot.send_voice(id, word_obj['audio']['src']) bot.send_voice(id, word_obj['audio']['dest'])
def send_class_statistic(self, teacher_id): output = [] students_stats = self.db.get_class_statistic(teacher_id) if students_stats is not None: for student in students_stats: output.append(f"{student['name']} - {student['total']}") bot.send_message(teacher_id, '\n'.join(output)) else: bot.send_message(teacher_id, 'error')
def get_class_statistic(self, teacher_id): stats = [] try: for student in self.classes_db[f'{teacher_id}'].find(): stats.append({'name': student['name'], 'total': [el for el in self.history_db[f"{student['student_id']}"].aggregate([{'$group': {'_id': None,'howmanylearnt': {'$sum': '$howmanylearnt'}}}])][0]['howmanylearnt']}) return stats except: bot.send_message(teacher_id, 'error') print(stats)
def logic_add_new_word_to_module(self, message): add_new_word_keyboard = types.InlineKeyboardMarkup() add_new_word_keyboard.add( types.InlineKeyboardButton( 'vocabulary', callback_data='add_new_word_from_vocabulary'), types.InlineKeyboardButton( 'enter', callback_data='add_new_word_from_input')) bot.send_message(message.chat.id, f'add word from:', reply_markup=add_new_word_keyboard)
def alter_wrapper(self, message): words = word_tokenize(message.text) if message.text == '-': bot.send_message(message.chat.id, 1) else: self.db.alter_word(message.chat.id, self.current_ten[self.current_word_index], ''.join(words)) bot.send_message( message.chat.id, f'destination changed from "***{self.current_ten[self.current_word_index]["values"]["src"]}***" to "***{words[0]}***"\nand\ntranslation was changed from "***{self.current_ten[self.current_word_index]["values"]["dest"]}***" to "***{words[-1]}***"', parse_mode='Markdown')
def rename_module(self, message): self.new_module_name = message.text if self.db.is_unique_module(message.chat.id, module=message.text): self.current_module = message.text self.db.rename_modules_with_name(message.chat.id, self.old_module_name, self.new_module_name) bot.send_message( message.chat.id, f'module "{self.old_module_name}" was renamed to "{self.new_module_name}"' ) else: bot.send_message( message.chat.id, f'module with name "{message.text}" is already exists')
def send_all_modules(self, id): modules = self.db.get_all_modules(id) print(modules) for i in range(len(modules)): options_keyboard = types.InlineKeyboardMarkup() options_keyboard.add( types.InlineKeyboardButton( 'rename', callback_data=f'{modules[i]}_rename'), types.InlineKeyboardButton('edit', callback_data=f'{modules[i]}_edit'), types.InlineKeyboardButton( 'delete', callback_data=f'{modules[i]}_delete'), ) options_keyboard.add( types.InlineKeyboardButton('try', callback_data=f'{modules[i]}_try'), types.InlineKeyboardButton('show', callback_data=f'{modules[i]}_show')) bot.send_message(id, modules[i], reply_markup=options_keyboard)
def add_to_the_module(self, query_object, word_number): print(type(word_number)) if self.db.is_word_not_in_module( query_object.message.chat.id, self.current_ten[int(word_number % 10) - 1]['values']['src']): #print(voc.current_ten[(int(query.data.split('_')[0]) % 10) - 1]) self.db.add_to_the_module( query_object.message.chat.id, self.current_ten[(int(query_object.data.split('_')[0]) % 10) - 1], module=self.module_name) bot.answer_callback_query( callback_query_id=query_object.id, text= f'"{self.current_ten[(int(query_object.data.split("_")[0]) % 10) - 1]["values"]["src"]}" added to the "{self.module_name}"' ) else: bot.send_message(query_object.message.chat.id, 'this word already in other module')
def add_from_input(self, message): add_more_from_input_first_keyboard = types.InlineKeyboardMarkup().add( types.InlineKeyboardButton( 'add more', callback_data='add_more_from_input_first')) if self.db.is_unique(message.chat.id, message.text, all=True): try: word_obj = self.tr.create_object( message.chat.id, message.text, source='ru', destination='en') if TextBlob( message.text).detect_language( ) != 'en' else self.tr.create_object(message.chat.id, message.text, source='en', destination='ru') word_obj['module'] = self.module_name self.db.words_db[f'{message.chat.id}'].insert_one(word_obj) bot.send_message( message.chat.id, f'word added', reply_markup=add_more_from_input_first_keyboard) except: bot.send_message( message.chat.id, 'unknown word', reply_markup=add_more_from_input_first_keyboard) else: bot.send_message( message.chat.id, 'word already in dictionary, you can add it from them', reply_markup=add_more_from_input_first_keyboard)
def chose_truth_answer(self, message, correct=True): if correct: self.stats['correct_count'] += 1 bot.send_message( message.chat.id, f'correct✅ {self.stats["correct_count"]}/{self.stats["whole_count"]}', reply_markup=self.view_results_keyboard if self.learning_word + 1 == len(self.current_learning_words) else self.next_learning_word_keyboard) self.learn_history.append({ 'type': 'choose', 'wrong_answers': self.wrong_answers, 'correct_answer': self.current_learning_words[self.learning_word]['values'] ['src'], 'is_correct': True }) else: bot.send_message( message.chat.id, f'wrong answer❌ {self.stats["correct_count"]}/{self.stats["whole_count"]}', reply_markup=self.view_results_keyboard if self.learning_word + 1 == len(self.current_learning_words) else self.next_learning_word_keyboard) self.learn_history.append({ 'type': 'choose', 'wrong_answers': self.wrong_answers, 'correct_answer': self.current_learning_words[self.learning_word]['values'] ['src'], 'is_correct': False, 'obj': self.current_learning_words[self.learning_word] })
def create_object(self, id, word, source='ru', destination='en'): from_src_to_dest = GoogleTranslator(source=source, target=destination) from_dest_to_src = GoogleTranslator(source=destination, target=source) print(word, self.word_checker(word)) #print(from_src_to_dest.translate(word), self.word_checker(from_src_to_dest.translate(word))) try: return { 'is_learnt': False, 'module': None, 'teacher': None, 'values': { 'src': word.lower(), 'dest': from_src_to_dest.translate(word).lower() }, 'languages': { 'src': source, 'dest': destination }, 'audio': { 'dest': self.get_binary(word, source_=source, destination_=destination) if word else None, 'src': self.get_binary(word, source_=destination, destination_=source) if word else None }, 'syntax': { 'src': { 'part of speech': None if len(word_tokenize(word)) > 1 else (parts_of_speech[nltk.pos_tag(word_tokenize(word))[-1][1]] if source == 'en' else from_dest_to_src.translate(parts_of_speech[nltk.pos_tag(word_tokenize(from_src_to_dest.translate(word)))[-1][1]])), 'synonyms': None if len(word_tokenize(word)) > 1 or (not self.word_checker(word) and not self.word_checker(from_src_to_dest.translate(word))) else (self.dictionary.synonym(word)[:3] if source == 'en' else [from_dest_to_src.translate(el) for el in self.dictionary.synonym(from_src_to_dest.translate(word))[:3]]) }, 'dest': { 'part of speech': None if len(word_tokenize(word)) > 1 else (parts_of_speech[nltk.pos_tag(word_tokenize(word))[-1][1]] if destination == 'en' else from_src_to_dest.translate(parts_of_speech[nltk.pos_tag(word_tokenize(from_dest_to_src.translate(word)))[-1][1]])), 'synonyms': None if len(word_tokenize(word)) > 1 or (not self.word_checker(word) and not self.word_checker(from_src_to_dest.translate(word))) else (self.dictionary.synonym(from_src_to_dest.translate(word))[:3] if destination == 'en' else [from_src_to_dest.translate(el) for el in self.dictionary.synonym(word)[:3]]) } } } except: bot.send_message(id, 'text length need to be between 1 and 5000 characters')
def send_word(self, message): # create inline keyboard add_to_vocab = types.InlineKeyboardMarkup() add_to_vocab.add(types.InlineKeyboardButton('add to vocabluary', callback_data='add_to_voc')) try: if TextBlob(message.text).detect_language() != 'en': print('185') #create word object word_obj = self.create_object(message.chat.id, message.text, source='ru', destination='en') print(db.is_unique(message.chat.id, message.text.lower())) self.current_word_obj = word_obj print(word_obj) # send translate bot.send_message(message.chat.id, word_obj['values']['dest']) #send pronunciation bot.send_voice(message.chat.id, word_obj['audio']['dest'], reply_markup=add_to_vocab) else: import datetime now = datetime.datetime.now() # create word object word_obj = self.create_object(message.chat.id, message.text, source='en', destination='ru') creating_time = datetime.datetime.now() - now print(creating_time) self.current_word_obj = word_obj #send translate bot.send_message(message.chat.id, word_obj['values']['dest']) #send pronunciation bot.send_voice(message.chat.id, word_obj['audio']['dest'], reply_markup=add_to_vocab) except Exception as e: print(e)
def send_applications(self, message): buttons = [ f'types.InlineKeyboardButton("{el["name"]}", callback_data="{el["name"]}_application")' for el in self.db.applications_db['applications'].find() ] for application in [ el['name'] for el in self.db.applications_db['applications'].find() ]: print(application) applications_accept_keyboard = types.InlineKeyboardMarkup() applications_accept_keyboard.add( types.InlineKeyboardButton( 'accept', callback_data=f'{application}_applicationaccept'), types.InlineKeyboardButton( 'reject', callback_data=f'{application}_applicationreject')) bot.send_message(message.chat.id, application, reply_markup=applications_accept_keyboard)
def logic_get_student_id(self, message): if self.db.is_int(message.text) and self.is_unique_student( int(message.text), message.chat.id) and self.db.is_user( int(message.text)): self.current_student_id = int(message.text) print(self.current_student_id) self.add_student(message) bot.send_message(message.chat.id, 'student added') else: if not self.db.is_int(message.text): bot.send_message(message.chat.id, 'that is not id') elif not self.db.is_user(int(message.text)): bot.send_message(message.chat.id, 'unknown id') else: bot.send_message(message.chat.id, 'student already in your class')
def get_command(message): if message.text == '/translate': pass elif message.text == '/admin': if message.chat.id not in admins: bot.send_message(message.chat.id, 'you aren\'t admin. Permission rejected') else: bot.send_message(message.chat.id, 'you are in admin display', reply_markup=admin_keyboard) elif message.text == '/start': bot.send_message(message.chat.id, 'lets learn new words!', reply_markup=main_keyboard) elif message.text == '/test': print(module.stats) elif message.text == '/forteachers': if message.chat.id not in teachers: bot.send_message(message.chat.id, 'you aren\'t teacher') else: bot.send_message(message.chat.id, 'you are in', reply_markup=teachers_keyboard)
def send_stats(self, id): output = [] print(self.learn_history) print(self.learn_history) for i in range(len(self.learn_history)): print(self.learn_history[i]['type']) if self.learn_history[i]['type'] == 'input': tr = self.learn_history[i]['obj']['values']['src'] de = self.learn_history[i]['obj']['values']['dest'] output.append( f'{i + 1}) {self.learn_history[i]["correct_answer"]} - {self.learn_history[i]["wrong_answer"]} {"✅" if self.learn_history[i]["is_correct"] else f"❌ could be {tr} - {de}"}' ) elif self.learn_history[i]['type'] == 'choose': temp = [el for el in self.learn_history[i]['wrong_answers']] temp.append('*' + self.learn_history[i]['correct_answer']) output.append( f'{i + 1}) {" ".join(temp)} {"✅" if self.learn_history[i]["is_correct"] else "❌"}' ) bot.send_message(id, '\n'.join(output))
def input_truth_answer(self, message): if message.text == self.current_learning_words[self.learning_word][ 'values']['dest'] and message.text != '\start': self.stats['correct_count'] += 1 bot.send_message( message.chat.id, f'correct✅ {self.stats["correct_count"]}/{self.stats["whole_count"]}', reply_markup=self.view_results_keyboard if self.learning_word + 1 == len(self.current_learning_words) else self.next_learning_word_keyboard) self.learn_history.append({ 'type': 'input', 'correct_answer': self.current_learning_words[self.learning_word]['values'] ['src'], 'wrong_answer': message.text, 'is_correct': True, 'obj': self.current_learning_words[self.learning_word] }) elif message.text == '\start': bot.send_message(message.chat.id, 'stoped') else: bot.send_message( message.chat.id, f'wrong answer❌ {self.stats["correct_count"]}/{self.stats["whole_count"]}', reply_markup=self.view_results_keyboard if self.learning_word + 1 == len(self.current_learning_words) else self.next_learning_word_keyboard) self.learn_history.append({ 'type': 'input', 'correct_answer': self.current_learning_words[self.learning_word]['values'] ['src'], 'wrong_answer': message.text, 'is_correct': False, 'obj': self.current_learning_words[self.learning_word] })
def send_choice(self, message): self.module_name = message.text print(self.module_name) #print(self.current_module) if message.text == 'None': bot.send_message(message.chat.id, '"None" is keyword, you can\'t use that') elif self.db.is_unique_module(message.chat.id, module=self.module_name): print( self.db.is_unique_module(message.chat.id, module=message.text)) choice = types.InlineKeyboardMarkup().add( types.InlineKeyboardButton( 'insert from vocabulary', callback_data='insert_first_word_from_voc'), types.InlineKeyboardButton('input', callback_data='input')) bot.send_message( message.chat.id, 'module must include at least 1 word, please insert from:', reply_markup=choice) else: bot.send_message(message.chat.id, 'module with this name is already created')
def send_current_ten(self, id, skip, count, module=None, option=None, all=False, edit=False): print('option', option) print('skip in "func":', skip) print('count in "func":', count) if all: self.current_ten = self.db.get_full_words(id, skip, count) print('theretheretherethere') else: self.current_ten = self.db.get_current_words(id, skip, count, m=module) to = self.current_ten print('there') for i in self.current_ten: print(i) temp = [] buttons = [] for i in range(skip, len(self.current_ten) + skip): temp.append( f'types.InlineKeyboardButton({i +1}, callback_data="{i +1}_{module}_{option}")' ) if (i + 1) % 5 == 0: buttons.append(temp) temp = [] if temp: buttons.append(temp) print(buttons) navigation_keyboard = types.InlineKeyboardMarkup() # insert keyboard for el in buttons: exec(f"navigation_keyboard.row({','.join(el)})") navigation_keyboard.add( types.InlineKeyboardButton('<', callback_data='previous_list'), types.InlineKeyboardButton('>', callback_data='next_list')) if option == 'None': navigation_keyboard.add( types.InlineKeyboardButton('clear', callback_data='clear_vocabulary')) if edit: navigation_keyboard.add( types.InlineKeyboardButton('add', callback_data='add_new_word')) nums = [i for i in range(skip, len(self.current_ten) + skip + 1)] print(nums) output = [ f'{skip + i + 1}) {self.current_ten[i]["values"]["src"]} - {self.current_ten[i]["values"]["dest"]}' for i in range(len(self.current_ten)) ] print('output', output) bot.send_message(id, '\n'.join(output), reply_markup=navigation_keyboard)
def get_text_command(message): global skip global count if message.text == 'translate': bot.send_message(message.chat.id, 'im waiting for your word:') bot.register_next_step_handler(message, trans.send_word) elif message.text == 'my vocabulary': db.auth_user(message) print(str(message.chat.id) not in db.words_db.collection_names()) if str(message.chat.id) not in db.words_db.collection_names( ) or db.words_db[f'{message.chat.id}'].count() == 0: bot.send_message(message.chat.id, 'your vocabulary is empty') else: #switch on your own vocabulary database module.current_module = None db.all = True db.current_option = 'None' skip = 0 count = 10 module.send_current_ten(message.chat.id, skip, count, module=db.current_module, option=db.current_option, all=db.all) print(db.is_unique(message.chat.id, 'carpet')) elif message.text == 'try knowledge': pass elif message.text == 'manage modules': db.auth_user(message) print(1) if not db.collection_length( message.chat.id, all=True) or db.collection_length( message.chat.id) == db.collection_length(message.chat.id, all=True): more_create_module_keyboard = types.InlineKeyboardMarkup() more_create_module_keyboard.add( types.InlineKeyboardButton('create new module', callback_data="more_create_module")) bot.send_message(message.chat.id, 'there are no new modules', reply_markup=more_create_module_keyboard) else: module.send_all_modules(message.chat.id) elif message.text == 'new module': db.auth_user(message) bot.send_message(message.chat.id, 'enter module name') bot.register_next_step_handler(message, module.send_choice) elif message.text == 'manage students': if teacher.is_class_permeability(message.chat.id): teacher.send_students(message.chat.id) else: add_first_student = types.InlineKeyboardMarkup().add( types.InlineKeyboardButton('add', callback_data='add_first_student')) bot.send_message(message.chat.id, 'you can add first student to the class', reply_markup=add_first_student) elif message.text == 'class statistic': if teacher.is_class_permeability(message.chat.id): teacher.send_class_statistic(message.chat.id) else: bot.send_message(message.chat.id, 0) elif message.text == 'become teacher': if db.is_unique_application( message.chat.id) and message.chat.id not in teachers: db.send_application_for_teaching(message) bot.send_message(message.chat.id, 'your application will be viewed') elif message.chat.id in teachers: bot.send_message(message.chat.id, 'you are already teacher') else: bot.send_message(message.chat.id, 'your application already on consideration') elif message.text == 'accept applications': print(db.applications_db['applications'].count()) print([el for el in db.client.list_databases()]) if 'application' not in [ el['name'] for el in db.client.list_databases() ] or db.applications_db['applications'].count() == 0: bot.send_message(message.chat.id, 'applications list is empty') else: admin.send_applications(message)
def get_query(query): global skip global count if query.data == 'more_create_module': bot.send_message(query.message.chat.id, 'enter module name') bot.register_next_step_handler(query.message, module.send_choice) elif query.data == 'view_student_stats': pass elif query.data == 'add_first_student': bot.send_message(query.message.chat.id, 'enter student id') bot.register_next_step_handler(query.message, teacher.logic_get_student_id) elif query.data == 'kick_student': db.kick_student(query.message.chat.id, teacher.current_student_id) bot.send_message(query.message.chat.id, f'{teacher.current_student_id} student was deleted') elif query.data.split('_')[-1] == 'student': print(query.data) teacher.current_student_id = int(query.data.split('_')[0]) student_options_keyboard = types.InlineKeyboardMarkup().add( types.InlineKeyboardButton('kick', callback_data='kick_student'), types.InlineKeyboardButton('view statistic', callback_data='view_student_stats')) bot.send_message(query.message.chat.id, '.', reply_markup=student_options_keyboard) elif query.data.split('_')[-1] == 'None': #db.current_module = query.data.split('_')[1] voc.send_full_word( query.message.chat.id, module.current_ten[(int(query.data.split('_')[0]) % 10) - 1]) elif query.data.split('_')[-1] == 'firstinsertfromvocabulary': print('what module', module.module_name) print(query.data) #print(voc.current_ten) word_number = int(query.data.split('_')[0]) module.add_to_the_module(query, word_number) elif query.data == 'add_to_voc': db.auth_user(query.message) if db.is_unique(query.message.chat.id, trans.current_word_obj['values']['src'], module=module.current_module, all=True): db.add_one_to_voc(trans.current_word_obj, query.message, module=module.current_module) bot.answer_callback_query(callback_query_id=query.id, text='word added') else: bot.send_message(query.message.chat.id, 'word already there') elif query.data == 'next_list': print('skip', skip) print('count', count) if (skip + count) > db.collection_length(query.message.chat.id, module=module.current_module, all=db.all): bot.send_message(query.message.chat.id, 'that is all') elif db.collection_length(query.message.chat.id, module=module.current_module, all=db.all) - (skip + count) < count: skip += count module.send_current_ten( query.message.chat.id, skip, db.collection_length(query.message.chat.id, module=module.current_module, all=db.all) - (skip), module=module.current_module, option=db.current_option, all=db.all) elif query.data == 'previous_list': if skip - 10 < 0: skip = 0 bot.send_message(query.message.chat.id, 'you are on already first page') else: skip -= 10 module.send_current_ten(query.message.chat.id, skip, count, module=module.current_module, option=db.current_option, all=db.all) elif query.data == 'insert_first_word_from_voc': print(db.is_vocabulary_permeability(query.message.chat.id)) print('ooooooo') if db.is_vocabulary_permeability(query.message.chat.id): #switch on mosules database #module.module_name = None db.current_option = 'firstinsertfromvocabulary' db.all = True print(db.current_module) skip = 0 count = 10 module.send_current_ten(query.message.chat.id, skip, count, module=module.current_module, option=db.current_option, all=db.all) else: bot.send_message(query.message.chat.id, 'your vocabulary is empty') elif query.data == 'input': bot.send_message(query.message.chat.id, 'enter the word:') bot.register_next_step_handler(query.message, module.add_from_input) elif query.data == 'add_more_from_input_first': bot.send_message(query.message.chat.id, 'enter the word:') bot.register_next_step_handler(query.message, module.add_from_input) elif query.data.split('_')[-1] == 'rename': module.old_module_name = query.data.split('_')[0] bot.send_message(query.message.chat.id, 'enter the new module name:') bot.register_next_step_handler(query.message, module.rename_module) elif query.data.split('_')[-1] == 'edit': module.current_module = query.data.split('_')[0] module.module_name = module.current_module db.current_option = 'editword' skip = 0 count = 10 module.send_current_ten(query.message.chat.id, skip, count, module=module.current_module, option=db.current_option, edit=True) elif query.data.split('_')[-1] == 'editword': module.current_word_index = int(query.data.split('_')[0]) - 1 functionality_keyboard = types.InlineKeyboardMarkup().add( types.InlineKeyboardButton('delete', callback_data='delete_current_word'), types.InlineKeyboardButton('alter', callback_data='alter_word')) bot.send_message(query.message.chat.id, '.', reply_markup=functionality_keyboard) elif query.data.split('_')[-1] == 'delete': db.delete_module(query.message.chat.id, query.data.split('_')[0]) bot.send_message( query.message.chat.id, f'module with name {query.data.split("_")[0]} was deleted') elif len(query.data.split("_")) == 3 and query.data.split( '_')[-1] == 'show': print(module.current_ten[(int(query.data.split('_')[0]) % 10) - 1]) voc.send_full_word( query.message.chat.id, module.current_ten[(int(query.data.split('_')[0]) % 10) - 1]) elif query.data.split('_')[-1] == 'show': print('adasdasdasd', query.data) skip = 0 count = 10 module.current_module = query.data.split('_')[0] module.send_current_ten(query.message.chat.id, skip, count, module=module.current_module, option="show") elif query.data.split('_')[-1] == 'try': module.learn_history = [] module.current_learning_module = query.data.split('_')[0] module.learning_word = 0 module.current_learning_words = db.get_all_module_words( query.message.chat.id, module.current_learning_module) module.stats['correct_count'] = 0 module.stats['whole_count'] = len(module.current_learning_words) module.learn_word(query.message) elif query.data.split('_')[-1] == 'answer': if query.data.split('_')[0] == module.current_learning_words[ module.learning_word]['values']['dest']: module.chose_truth_answer(query.message, correct=True) else: module.chose_truth_answer(query.message, correct=False) elif query.data == 'next_learning_word': module.learning_word += 1 module.learn_word(query.message) elif query.data == 'alter_word': module.logic_alter_word(query.message) elif query.data == 'delete_last_word_from_module_confident': db.delete_word_from_module( query.message.chat.id, module.current_ten[module.current_word_index]) bot.send_message( query.message.chat.id, f'word ***{module.current_ten[module.current_word_index]["values"]["src"]} - {module.current_ten[module.current_word_index]["values"]["dest"]}*** which was single in this module deleted, then was deleted this module', parse_mode='Markdown') elif query.data == 'delete_current_word': if len(module.current_ten) == 1: bot.send_message( query.message.chat.id, 'module has 1 word, so if you delete that module will be deleted', reply_markup=types.InlineKeyboardMarkup().add( types.InlineKeyboardButton( 'are you sure?', callback_data='delete_last_word_from_module_confident') )) else: db.delete_word_from_module( query.message.chat.id, module.current_ten[module.current_word_index]) bot.send_message( query.message.chat.id, f'word ***{module.current_ten[module.current_word_index]["values"]["src"]} - {module.current_ten[module.current_word_index]["values"]["dest"]}*** was deleted', parse_mode='Markdown') elif query.data == 'add_new_word': module.logic_add_new_word_to_module(query.message) elif query.data == 'view_results': db.insert_stats(query.message.chat.id, module.learn_history, module.stats['correct_count'], module.stats['whole_count']) module.send_stats(query.message.chat.id) elif query.data == 'add_new_word_from_vocabulary': if db.is_vocabulary_permeability(query.message.chat.id): db.current_option = 'add' db.all = True print(db.current_module) skip = 0 count = 10 module.send_current_ten(query.message.chat.id, skip, count, module=module.current_module, option=db.current_option, all=db.all) else: bot.send_message(query.message.chat.id, 'your vocabulary is empty') elif query.data.split('_')[-1] == 'add': print(query.data.split('_')[0]) print('asdadads', query.data) module.add_to_the_module(query, int(query.data.split('_')[0])) elif query.data == 'add_new_word_from_input': bot.send_message(query.message.chat.id, 'enter the word:') bot.register_next_step_handler(query.message, module.add_from_input) elif query.data == 'stop': bot.send_message( query.message.chat.id, 'are you sure? if you accept, your progress will be not saved', reply_markup=types.InlineKeyboardMarkup().add( types.InlineKeyboardButton('im sure', callback_data='sureness'))) elif query.data == 'sureness': bot.send_message(query.message.chat.id, 'stopped') elif query.data == 'clear_vocabulary': db.clear_vocabulary(query.message.chat.id) bot.send_message(query.message.chat.id, 'cleared') elif query.data.split('_')[-1] == 'applicationaccept': teachers.append(query.message.chat.id) db.delete_application(query.message.chat.id) bot.send_message(query.message.chat.id, 'accepted') elif query.data.split("_")[-1] == 'applicationreject': db.delete_application(query.message.chat.id) bot.send_message(query.message.chat.id, 'rejected')