def go_test(update, context): id = update.message.from_user.id if id not in test_dict.keys(): path = 'all_comands/tests/' + update.message.text + '.json' test_dict[id] = Test(read_json(path)) else: test_dict[id].check_it(update.message.text) current = test_dict[id] text = current.ask_next() if text['count'] == 10: count = current.get_result() user = session.query(User).filter(User.id == id).first() res = TEXT[user.mode]['test'] update.message.reply_text(f'{res[1]} {count}/10\n{res[2]}', reply_markup=ReplyKeyboardRemove()) del test_dict[id] return ConversationHandler.END elif text['markup'] is not None: markup = ReplyKeyboardMarkup([text['markup'] + ['❌']], one_time_keyboard=True) update.message.reply_text(text['text'], reply_markup=markup) else: markup = ReplyKeyboardMarkup([['❌']], one_time_keyboard=True) update.message.reply_text(text['text'], reply_markup=markup) return 1
def start(update, context): print('go') print(session) users = list(map(lambda x: x.id, session.query(User).all())) id = update.message.from_user.id print('go 1') if id not in users: new = User(id=id, mode='en') session.add(new) session.commit() else: new = session.query(User).filter(User.id == id).first() text = TEXT[new.mode]['start'] update.message.reply_text(text)
def send_lesson(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() update.message.reply_photo(photo=open(f'all_comands/lessons/{LESSONS[update.message.text]}', 'rb')) update.message.reply_text(TEXT[user.mode]['lessons'][1]) return 1
def ru(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() user.mode = 'ru' session.commit() update.message.reply_text('Готово!')
def en(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() user.mode = 'en' session.commit() update.message.reply_text('Done!')
def lesson(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() commands = ReplyKeyboardMarkup([COMMANDS[user.mode]['lessons'] + ['❌']], one_time_keyboard=True) text = TEXT[user.mode]['lessons'][0] update.message.reply_text(text, reply_markup=commands) return 1
def choose_tr_lang(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() markup = ReplyKeyboardMarkup([COMMANDS[user.mode]['translate'] + ['❌']], one_time_keyboard=True) update.message.reply_text(TEXT[user.mode]['translate'][0], reply_markup=markup) return 1
def test(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() text = TEXT[user.mode]['test'][0] commands = COMMANDS[user.mode]['test'] + ['❌'] markup = ReplyKeyboardMarkup([commands], one_time_keyboard=True) update.message.reply_text(text, reply_markup=markup) return 1
def get_tr_lang(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() translate_dict[id] = update.message.text text = TEXT[user.mode]['translate'][1] markup = ReplyKeyboardMarkup([['❌']], one_time_keyboard=True) update.message.reply_text(text, reply_markup=markup) return 2
def recommend(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() markup = ReplyKeyboardMarkup([COMMANDS[user.mode]['rec']], one_time_keyboard=True) text = TEXT[user.mode]['rec'][0] update.message.reply_text(text, reply_markup=markup) return 1
def get_rec(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() kind = update.message.text if kind == 'фильм' or kind == 'film': length = session.query(Film).count() rand = randint(1, length) rec = user.rec_films res = session.query(Film).filter(Film.id == rand).first() if rec is None: rec = '' while str(rand) in rec.split() or res is None: rand = randint(1, length) res = session.query(Film).filter(Film.id == rand).first() user.rec_films = rec + f' {str(rand)}' res = f'🟠{res.name}\n\n🔸{res.plot_ru}' \ if user.mode == 'ru' else f'🟠{res.name}\n\n🔸{res.plot_en}' elif kind == 'книга' or kind == 'book': length = session.query(Book).count() rand = randint(1, length) rec = user.rec_books res = session.query(Book).filter(Book.id == rand).first() if rec is None: rec = '' while str(rand) in rec.split() or res is None: rand = randint(1, length) res = session.query(Book).filter(Book.id == rand).first() user.rec_books = rec + f' {str(rand)}' res = f'🟠{res.author} - {res.name}\n\n🔸{res.plot_ru}' \ if user.mode == 'ru' else \ f'🟠{res.author} - {res.name}\n\n🔸{res.plot_en}' text = TEXT[user.mode]['rec'][1] session.commit() update.message.reply_text(text + res, reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END
def talk(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() markup = ReplyKeyboardMarkup([['❌']]) if id not in talking_now.keys(): talking_now[id] = TALKING[update.message.text] update.message.reply_text(TEXT[user.mode][talking_now[id]], reply_markup=markup) return 1 response = which_response(update.message.text, talking_now[id]) update.message.reply_text(response, reply_markup=markup) return 1
def help(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() text = TEXT[user.mode]['help'] update.message.reply_text(text)
def send_meme(update, context): id = update.message.from_user.id user = session.query(User).filter(User.id == id).first() update.message.reply_photo(photo=memes.get_url()) update.message.reply_text(TEXT[user.mode]['memes'])