Beispiel #1
0
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)))
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)