def stop(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [stop()]: user is None') start(message) return if user['game_in_process'] == 0: bot_say(chat_id, 'Раунд еще не начат. /help') return temp_count = user['count'] game_in_process = 0 count = 0 current_q = '()' mongotools.update_user(db, chat_id, game_in_process=game_in_process, count=count, current_q=current_q) reply = f"Раунд закончен.\nВы ответили на {temp_count} {pluralForm(temp_count, 'вопрос', 'вопроса', 'вопросов')}" + \ f" подряд. Неплохо!\nЧтобы начать заново, напишите /go" bot_say_with_exit(chat_id, reply)
def ask_q(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [ask_q()]: user is None') start(message) return words, ans = get_random_ask() random.shuffle(words) markup = types.ReplyKeyboardMarkup(row_width=3) i1 = types.KeyboardButton(words[0]) i2 = types.KeyboardButton(words[1]) i3 = types.KeyboardButton(words[2]) i4 = types.KeyboardButton(words[3]) i5 = types.KeyboardButton(words[4]) markup.add(i1, i2, i3, i4, i5) reply = f"_Вопрос #{user['count'] + 1}_. Выберите слово, где ударение указано *неверно*:" for word in words: reply += f'\n{word}' bot_say(chat_id, reply, parse_mode='Markdown', reply_markup=markup) # m = bot.send_message(chat_id, reply, reply_markup=markup, parse_mode="Markdown") # message_to_log(m) mongotools.update_user(db, chat_id, current_q=str((words, ans)))
def go(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: start(message) return if user['game_in_process'] == 1: bot_say(chat_id, 'Раунд уже идет!') return mongotools.update_user(db, chat_id, game_in_process=1) ask_q(message)
def about_me(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [about_me()]: user is None') start(message) return score = user['score'] questions = user['questions'] if user['name'] == 'None' or user['name'] == None: name = user['realname'] else: name = '@' + user['name'] reply = f'Ваше имя: {name}\nКоличество правильных ответов: {score}\nКоличество неправильных ответов: {questions - score}' bot_say(chat_id, reply)
def offer(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [delete()]: user is None') start(message) return text = message.text name = user['name'] realname = user['realname'] try: words = text.replace('/offer ', '') assert words.__len__() > 0 assert '/' not in words bot_say(OWNER_ID, f'@{name}/{realname}/{chat_id} предложил: {words}') bot_say(chat_id, 'Заявка отправлена') except: bot_say(chat_id, offer_message, parse_mode='Markdown')
def delete(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [delete()]: user is None') start(message) return name = user['name'] realname = user['realname'] mongotools.update_user(db, chat_id, game_in_process=0, current_q='()', count=0, name=name, score=0, questions=0, realname=realname) bot_say_with_exit(chat_id, 'Данные успешно удалены.') about_me(message)
def top(message: Message): chat_id = message.chat.id user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [top()]: user is None') start(message) return top_list = mongotools.get_top_users(db, amount=5) reply = 'Топ игроков:' for user in top_list: if user['name'] == 'None' or user['name'] == None: name = user['realname'] else: name = '@' + user['name'] score = user['score'] reply += f"\n{name}: {score} {pluralForm(score, 'правильный', 'правильных', 'правильных')} " \ f"{pluralForm(score, 'ответ', 'ответа', 'ответов')}" bot_say(chat_id, reply)
def answer_by_text(message: Message): chat_id = message.chat.id username = message.from_user.username realname = get_real_name(message) text = message.text user = mongotools.get_user(db, chat_id) if user is None: print('ошибка [answer_by_text()]: user is None') start(message) return game_in_process = user['game_in_process'] current_q = user['current_q'] count = user['count'] score = user['score'] questions = user['questions'] if game_in_process == 0: bot_say(chat_id, 'Раунд еще не начат. /help') return words, ans = eval(current_q) if text.lower() not in map(lambda x: x.lower(), words): bot_say( chat_id, 'Пожалуйста, выберите один из вариантов ответа. Если что-то пошло не так, закончи раунд /stop' ) return if text.lower() == ans.lower(): count += 1 score += 1 questions += 1 mongotools.update_user(db, chat_id, count=count, score=score, questions=questions, name=username, realname=realname) bot_say(chat_id, 'Отлично! Следующий вопрос.') ask_q(message) else: temp_count = count count = 0 current_q = '()' game_in_process = 0 questions += 1 mongotools.update_user(db, chat_id, game_in_process=game_in_process, count=count, questions=questions, current_q=current_q, name=username, realname=realname) reply = f"Неверно :( Правильный ответ был «{ans.lower()}».\nВы ответили на {temp_count} " + \ f"{pluralForm(temp_count, 'вопрос', 'вопроса', 'вопросов')}" + \ f" подряд. Неплохо!\nЧтобы начать заново, напишите /go" bot_say_with_exit(chat_id, reply)