def select_study_level(message): from flask_app import bot, start_handler answer = "" sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT study_programs_json FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone()[0] cursor.close() sql_con.close() study_programs = json.loads(data) study_level_names = [] for study_program in study_programs: study_level_names.append(study_program["StudyLevelName"]) if message.text in study_level_names: answer += "Укажи программу:" study_program_combinations_keyboard = telebot.types.ReplyKeyboardMarkup( True, False) index = study_level_names.index(message.text) study_program_combinations = study_programs[index][ "StudyProgramCombinations"] for study_program_combination in study_program_combinations: study_program_combinations_keyboard.row( study_program_combination["Name"]) study_program_combinations_keyboard.row("Другая ступень") sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """UPDATE user_choice SET study_level_name = ? WHERE user_id = ?""", (message.text, message.chat.id)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=study_program_combinations_keyboard) set_next_step(message.chat.id, "select_study_program_combination") elif message.text == "Другое направление": start_handler(message) return else: answer += "Пожалуйста, укажи ступень:" bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, "select_study_level")
def select_division(message): from flask_app import bot answer = "" sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT divisions_json FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() divisions = json.loads(data[0]) division_names = [division["Name"] for division in divisions] aliases = [division["Alias"] for division in divisions] if message.text in division_names: answer += "Выбери ступень:" study_programs_keyboard = telebot.types.ReplyKeyboardMarkup( True, False) index = division_names.index(message.text) alias = aliases[index] url = "https://timetable.spbu.ru/api/v1/study/divisions/{0}/" \ "programs/levels".format(alias) study_programs = requests.get(url).json() for study_program in study_programs: study_programs_keyboard.row(study_program["StudyLevelName"]) study_programs_keyboard.row("Другое направление") data = json.dumps(study_programs) sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """UPDATE user_choice SET alias = ?, division_name = ?, study_programs_json = ? WHERE user_id = ?""", (alias, message.text, data, message.chat.id)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=study_programs_keyboard) set_next_step(message.chat.id, "select_study_level") else: answer += "Пожалуйста, укажи направление:" bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, "select_division")
def select_division(message): from flask_app import bot, start_handler answer = '' sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT divisions_json FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() divisions = json.loads(data[0]) aliases = [division['Alias'] for division in divisions] if message.text in const.existing_divisions: answer += 'Выбери курс:' study_programs_keyboard = types.ReplyKeyboardMarkup( True, False) index = const.existing_divisions.index(message.text) alias = aliases[index] for study_program in const.existing_courses: study_programs_keyboard.row(study_program) study_programs_keyboard.row('Другое направление') data = json.dumps(const.courses, ensure_ascii=False) sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''UPDATE user_choice SET div_alias = ?, division_name = ?, study_programs_json = ? WHERE user_id = ?''', (alias, message.text, data, message.chat.id,)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=study_programs_keyboard) set_next_step(message.chat.id, 'select_admission_year') elif message.text == 'Другой способ регистрации': start_handler(message) return else: answer += 'Пожалуйста, укажи направление:' bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, 'select_division')
def confirm_choice(message): from flask_app import bot, start_handler, main_keyboard from constants import emoji if message.text == "Все верно": sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT alias, student_group_id FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() alias = data[0] group_id = data[1] try: cursor.execute( """INSERT INTO user_data (id, alias, group_id) VALUES (?, ?, ?)""", (message.chat.id, alias, group_id)) except sqlite3.IntegrityError: sql_con.rollback() cursor.execute( """UPDATE user_data SET alias = ?, group_id = ? WHERE id = ?""", (alias, group_id, message.chat.id)) finally: sql_con.commit() cursor.execute("""DELETE FROM user_choice WHERE user_id = ?""", (message.chat.id, )) sql_con.commit() url = "https://timetable.spbu.ru/api/v1/groups/{0}/events".format( group_id) week_data = requests.get(url).json() data = json.dumps(week_data) try: cursor.execute( """INSERT INTO groups_data (id, alias, json_week_data) VALUES (?, ?, ?)""", (group_id, alias, data)) except sqlite3.IntegrityError: cursor.execute( """UPDATE groups_data SET json_week_data = ? WHERE id = ? AND alias = ?""", (data, group_id, alias)) finally: sql_con.commit() cursor.close() sql_con.close() answer = "Главное меню\n\n" \ "{0} - информация о боте\n" \ "{1} - оценить бота\n" \ "{2} - настройки\n" \ "{3} - электрички\n" \ "{4} - редактор расписания\n" \ "@Spbu4u_news - новости бота".format(emoji["info"], emoji["star"], emoji["settings"], emoji["suburban"], emoji["editor"]) bot.send_message(message.chat.id, answer, reply_markup=main_keyboard, parse_mode="HTML") elif message.text == "Другая группа": sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT admission_year_name FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() message.text = data[0] select_admission_year(message) return elif message.text == "Другой год": select_student_group(message) return elif message.text == "Другая программа": select_admission_year(message) return elif message.text == "Другая ступень": select_study_program_combination(message) return elif message.text == "Другое направление": start_handler(message) return
def select_student_group(message): from flask_app import bot answer = "" sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT student_groups_json FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone()[0] cursor.close() sql_con.close() student_groups = json.loads(data) student_group_names = [] for student_group in student_groups["Groups"]: student_group_names.append(student_group["StudentGroupName"]) if message.text in student_group_names: index = student_group_names.index(message.text) student_group_id = student_groups["Groups"][index]["StudentGroupId"] sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """UPDATE user_choice SET student_group_name = ?, student_group_id = ? WHERE user_id = ?""", (message.text, student_group_id, message.chat.id)) sql_con.commit() cursor.execute( """SELECT division_name, study_level_name, study_program_combination_name, admission_year_name, student_group_name FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() text = ">> " + "\n>> ".join(data) answer += "Подтверди выбор:\n" + "<b>" + text + "</b>" choice_keyboard = telebot.types.ReplyKeyboardMarkup(True, False) buttons = [ "Все верно", "Другая группа", "Другой год", "Другая программа", "Другая ступень", "Другое направление" ] for button in buttons: choice_keyboard.row(button) bot.send_message(message.chat.id, answer, parse_mode="HTML", reply_markup=choice_keyboard) set_next_step(message.chat.id, "confirm_choice") elif message.text == "Другой год": sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT study_program_combination_name FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() message.text = data[0] select_study_program_combination(message) return else: answer += "Пожалуйста, укажи группу:" bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, "select_student_group")
def select_admission_year(message): from flask_app import bot answer = "" sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT study_programs_json, study_level_name, study_program_combination_name FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() study_programs = json.loads(data[0]) study_level_name = data[1] study_program_combination_name = data[2] study_level_names = [] for study_program in study_programs: study_level_names.append(study_program["StudyLevelName"]) index = study_level_names.index(study_level_name) study_program_combinations = study_programs[index][ "StudyProgramCombinations"] study_program_combination_names = [] for study_program_combination in study_program_combinations: study_program_combination_names.append( study_program_combination["Name"]) index = study_program_combination_names.index( study_program_combination_name) admission_years = study_program_combinations[index]["AdmissionYears"] admission_year_names = [] for admission_year in admission_years: admission_year_names.append(admission_year["YearName"]) if message.text in admission_year_names: answer += "Укажи группу:" index = admission_year_names.index(message.text) study_program_id = admission_years[index]["StudyProgramId"] url = "https://timetable.spbu.ru/api/v1/progams/{0}/groups".format( study_program_id) student_groups = requests.get(url).json() student_group_names = [] for student_group in student_groups["Groups"]: student_group_names.append(student_group["StudentGroupName"]) student_groups_keyboard = telebot.types.ReplyKeyboardMarkup( True, False) for student_group_name in student_group_names: student_groups_keyboard.row(student_group_name) student_groups_keyboard.row("Другой год") data = json.dumps(student_groups) sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """UPDATE user_choice SET admission_year_name = ?, student_groups_json = ? WHERE user_id = ?""", (message.text, data, message.chat.id)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=student_groups_keyboard) set_next_step(message.chat.id, "select_student_group") elif message.text == "Другая программа": sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT study_level_name FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() message.text = data[0] select_study_level(message) return else: answer += "Пожалуйста, укажи год:" bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, "select_admission_year")
def select_study_program_combination(message): from flask_app import bot answer = "" sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT study_level_name, study_programs_json FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() study_level_name, study_programs = data[0], json.loads(data[1]) study_level_names = [] for study_program in study_programs: study_level_names.append(study_program["StudyLevelName"]) index = study_level_names.index(study_level_name) study_program_combinations = study_programs[index][ "StudyProgramCombinations"] study_program_combination_names = [] for study_program_combination in study_program_combinations: study_program_combination_names.append( study_program_combination["Name"]) if message.text in study_program_combination_names: answer += "Укажи год поступления:" admission_years_keyboard = telebot.types.ReplyKeyboardMarkup( True, False) index = study_program_combination_names.index(message.text) admission_years = study_program_combinations[index]["AdmissionYears"] for admission_year in admission_years: admission_years_keyboard.row(admission_year["YearName"]) admission_years_keyboard.row("Другая программа") sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """UPDATE user_choice SET study_program_combination_name = ? WHERE user_id = ?""", (message.text, message.chat.id)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=admission_years_keyboard) set_next_step(message.chat.id, "select_admission_year") elif message.text == "Другая ступень": sql_con = sqlite3.connect("Bot_db") cursor = sql_con.cursor() cursor.execute( """SELECT division_name FROM user_choice WHERE user_id = ?""", (message.chat.id, )) data = cursor.fetchone() cursor.close() sql_con.close() message.text = data[0] select_division(message) return else: answer += "Пожалуйста, укажи программу:" bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, "select_study_program_combination")
def confirm_choice(message): from flask_app import bot, start_handler, main_keyboard_btn answer = '' if message.text == 'Все верно': sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT alias, student_group_name FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() alias = data[0] group_name = data[1] cursor.execute('''DELETE FROM banned_users WHERE id_not_banned = ?''', (message.chat.id,)) sql_con.commit() cursor.execute('''INSERT INTO banned_users (id_not_banned) VALUES (?)''', (message.chat.id,)) sql_con.commit() try: cursor.execute('''INSERT INTO user_data (id, first_name, last_name, username, alias, group_name, date_of_registrations) VALUES (?, ?, ?, ?, ?, ?, ?)''', (message.chat.id, message.chat.first_name, message.chat.last_name, message.chat.username, alias, group_name, str(datetime.now())[:-7],)) except sl3.IntegrityError: sql_con.rollback() cursor.execute('''UPDATE user_data SET alias = ?, group_name = ? WHERE id = ?''', (alias, group_name, message.chat.id,)) finally: sql_con.commit() cursor.execute('''DELETE FROM user_choice WHERE user_id = ?''', (message.chat.id,)) sql_con.commit() cursor.close() sql_con.close() answer = ('Главное меню\n\n' '{0} – информация о боте\n' '{1} – оценить бота\n' '{2} – настройки\n' '{3} – параметры уведомлений\n' '{4} – расписание звонков'.format(const.emoji['info'], const.emoji['star'], const.emoji['settings'], const.emoji['alarm_clock'], const.emoji['bell'])) bot.send_message(message.chat.id, answer, reply_markup=main_keyboard_btn, parse_mode='HTML') elif message.text == 'Другая группа': sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT admission_year_name FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() message.text = data[0] select_admission_year(message) return elif message.text == 'Другой курс': select_student_group(message) return elif message.text == 'Другое направление': select_admission_year(message) return elif message.text == 'Другой способ регистрации': start_handler(message) return else: answer += ('Пожалуйста, проверь правильно ли ты всё указал и ' 'подтверди свой выбор:') bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, 'confirm_choice')
def select_student_group(message): from flask_app import bot answer = '' sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT student_groups_json, alias FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() student_groups = json.loads(data[0]) alias = data[1] student_group_names = [] for i in student_groups: if alias in i: gr = i[alias] for student_group in gr: student_group_names.append(student_group['StudentGroupName']) if message.text in student_group_names: edit_msg = bot.send_message(message.chat.id, 'Почти готово! ' 'Запоминаю твой выбор\U00002026') sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''UPDATE user_choice SET student_group_name = ? WHERE user_id = ?''', (message.text, message.chat.id,)) sql_con.commit() cursor.execute('''SELECT division_name, admission_year_name, student_group_name FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() text = '>> ' + '\n>> '.join(data) answer += 'Подтверди выбор:\n' + '<b>' + text + '</b>' choice_keyboard = types.ReplyKeyboardMarkup(True, False) buttons = ['Все верно', 'Другая группа', 'Другой курс', 'Другое направление', 'Другой способ регистрации'] for button in buttons: choice_keyboard.row(button) bot.edit_message_text('Готово!', message.chat.id, edit_msg.message_id) bot.send_message(message.chat.id, answer, parse_mode='HTML', reply_markup=choice_keyboard) set_next_step(message.chat.id, 'confirm_choice') elif message.text == 'Другой курс': sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT division_name FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() message.text = data[0] select_division(message) return else: answer += 'Пожалуйста, укажи группу:' bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, 'select_student_group')
def select_admission_year(message): from flask_app import bot answer = '' sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT study_programs_json, div_alias FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() courses = json.loads(data[0]) div_alias = data[1] aliases = [course['Alias'] for course in courses] if message.text in const.existing_courses: answer += 'Укажи группу:' student_groups_keyboard = types.ReplyKeyboardMarkup(True, False) index = const.existing_courses.index(message.text) course_alias = aliases[index] alias = div_alias + course_alias student_group_names = [] for i in const.student_groups: if alias in i: gr = i[alias] for student_group in gr: student_group_names.append( student_group['StudentGroupName']) student_groups_keyboard = types.ReplyKeyboardMarkup( True, False) for student_group_name in student_group_names: student_groups_keyboard.row(student_group_name) student_groups_keyboard.row('Другой курс') data = json.dumps(const.student_groups, ensure_ascii=False) sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''UPDATE user_choice SET alias = ?, admission_year_name = ?, student_groups_json = ? WHERE user_id = ?''', (alias, message.text, data, message.chat.id,)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=student_groups_keyboard) set_next_step(message.chat.id, 'select_student_group') elif message.text == 'Другое направление': sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT types_json FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone()[0] cursor.close() sql_con.close() message.text = json.loads(data)[0]['Type'] select_status(message) return else: answer += 'Пожалуйста, укажи курс:' bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, 'select_admission_year')
def select_teacher(message): from flask_app import bot answer = '' if message.text in const.cap_teachers: sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''UPDATE user_choice SET student_group_name = ? WHERE user_id = ?''', (message.text, message.chat.id,)) sql_con.commit() cursor.close() sql_con.close() text = '>> ' + message.text answer += 'Подтверди выбор преподавателя:\n' + '<b>' + text + '</b>' choice_keyboard = types.ReplyKeyboardMarkup(True, False) buttons = ['Все верно', 'Другой преподаватель', 'Другой способ регистрации'] for button in buttons: choice_keyboard.row(button) bot.send_message(message.chat.id, answer, parse_mode='HTML', reply_markup=choice_keyboard) set_next_step(message.chat.id, 'confirm_choice_teacher') else: teachers = search_teacher(message.text) if len(teachers) == 0: answer += ('Преподаватель "<b>' + message.text + '</b>" ' 'не найден.\nЕсли по какой-то причине отсусвует ' 'какой либо преподаватель, просьба сразу сообщить ' '<a href="https://t.me/lee_kei">разработчику</a>.') bot.send_message(message.chat.id, answer, True, parse_mode='HTML') return if teachers[0] and len(teachers[0]) <= 10: short_teachers = [] if len(teachers[0]) > 1: for teacher in teachers[0]: sp_te = teacher.split() short_teachers.append(sp_te[0] + ' ' + sp_te[1][0] + '. ' + sp_te[2][0] + '.') duplicate = [item for item, count in Counter( short_teachers).items() if count > 1] if duplicate: seen = set() result = [] for idx, item in enumerate(short_teachers): if item not in seen: seen.add(item) else: result.append(idx) for i in duplicate: index = short_teachers.index(i) for ind in result: if short_teachers[index] == short_teachers[ind]: sp_te = teachers[0][ind].split() short_teachers[ind] = ( sp_te[0] + ' ' + sp_te[1][:2] + '. ' + sp_te[2][:2] + '.') sp_te = teachers[0][index].split() short_teachers[index] = ( sp_te[0] + ' ' + sp_te[1][:2] + '. ' + sp_te[2][:2] + '.') else: short_teachers = teachers[0] educators_keyboard = types.InlineKeyboardMarkup( row_width=2) if len(short_teachers) == 1: answer += (const.emoji['mag_right'] + ' Найденный преподаватель:') if len(short_teachers[0].encode('utf-8')) >= 48: if short_teachers[0] in const.teacher_name: index = const.teacher_name.index(short_teachers[0]) elif short_teachers[0] in const.sht_teachers: index = const.sht_teachers.index(short_teachers[0]) elif short_teachers[0] in const.cap_teachers: index = const.cap_teachers.index(short_teachers[0]) short_teachers[0] = const.teacher_name[index] else: answer += (const.emoji['mag_right'] + ' Найденные преподаватели:') educators = [] i = 0 for teacher in short_teachers: try: educators.append(types.InlineKeyboardButton( text=teacher, callback_data=teacher + '|' + str(teachers[1][i]))) i += 1 except: continue educators_keyboard.add(*educators) educators_keyboard.row(types.InlineKeyboardButton( text='« Назад', callback_data='back_reg')) bot.send_message(message.chat.id, answer, reply_markup=educators_keyboard) elif len(teachers[0]) > 10: answer += ('Слишком много преподавателей\n' 'Пожалуйста, <b>уточни</b>') bot.send_message(message.chat.id, answer, parse_mode='HTML') else: if ('Никого не найдено' not in message.text and 'Введи ФИО преподавателя' not in message.text and 'Слишком много преподавателей' not in message.text): answer += ('Преподаватель "<b>' + message.text + '</b>" ' 'не найден.\nЕсли по какой-то причине отсусвует ' 'какой либо преподаватель, просьба сразу сообщить ' '<a href="https://t.me/lee_kei">разработчику</a>.') bot.send_message(message.chat.id, answer, True, parse_mode='HTML')
def select_status(message, change_group=False): from flask_app import bot answer = '' sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''SELECT types_json FROM user_choice WHERE user_id = ?''', (message.chat.id,)) data = cursor.fetchone() cursor.close() sql_con.close() types_of_reg = json.loads(data[0]) type_names = [type['Type'] for type in types_of_reg] aliases = [type['Alias'] for type in types_of_reg] if message.text == type_names[0]: answer = '' answer += 'Укажи свое направление:' divisions_keyboard = types.ReplyKeyboardMarkup(True, False) for division_name in const.existing_divisions: divisions_keyboard.row(division_name) if change_group: divisions_keyboard.row('« Назад') else: divisions_keyboard.row('Другой способ регистрации') data = json.dumps(const.divisions, ensure_ascii=False) sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''UPDATE user_choice SET divisions_json = ? WHERE user_id = ?''', (data, message.chat.id,)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=divisions_keyboard) set_next_step(message.chat.id, 'select_division') elif message.text == type_names[1]: if change_group: back_command = '' else: back_command = '\n\nДля отмены используй /home' answer += ('Введи <i>Фамилию</i> преподавателя (и <i>И. О.</i>)\n' 'Это можно сделать <b>двумя</b> способами:\n' '{0} <b>Прислать ФИО преподавателя (бот поддерживает 3 вида):</b>\n' ' 1) <i>Фамилия</i>\n' ' 2) <i>Фамилия И. О.</i>\n' ' 3) <i>Фамилия Имя Отчество</i>\n' '{1} <b>Воспользоваться динамичным поиском:</b>\n' ' Для этого введи "<code>@BGPK_bot </code>" и следуй дальнейшим ' 'инструкциям.{2}'.format(const.emoji['bullet'], const.emoji['bullet'], back_command)) remove_keyboard = types.ReplyKeyboardRemove() sql_con = sl3.connect(const.path + 'Bot.db') cursor = sql_con.cursor() cursor.execute('''UPDATE user_choice SET alias = ? WHERE user_id = ?''', (aliases[1], message.chat.id,)) sql_con.commit() cursor.close() sql_con.close() bot.send_message(message.chat.id, answer, reply_markup=remove_keyboard, parse_mode='HTML') set_next_step(message.chat.id, 'select_teacher') else: answer += 'Пожалуйста, выбери в качестве кого ты хочешь зайти:' bot.send_message(message.chat.id, answer) set_next_step(message.chat.id, 'select_status')