Example #1
0
def help_handler(_, update):
    help_text = service.get_property(
        BOT_HELP_TEXT,
        "Победить в нашей игре - легко!<br>Достаточно ответить на вопросы как можно быстрее, "
        "использовав при этом минимум подсказок<br>"
        "Если нужно повторить вопрос - просто поздоровайтесь с ботом")
    _reply(update, help_text)
Example #2
0
def hint_button_handler(_, callback_update):
    user = callback_update.effective_user
    overdraft = service.is_overdrafted(user)
    if overdraft:
        _release_inline_button(callback_update)
        return

    _, hint_key, question_id = json.loads(callback_update.callback_query.data)
    max_user_answered_question_id = service.get_max_passed_question_id(user)
    if max_user_answered_question_id >= question_id:
        _release_inline_button(callback_update)
        return

    hint_available = service.add_hint(user, hint_key, question_id)
    if not hint_available:
        already_used = service.get_property(BOT_HINT_UNAVAILABLE_TEXT,
                                            "Подсказка уже использована")
        _show_notification_if_possible(callback_update, already_used)
        return

    if service.FIFTY_HINT_KEY == hint_key:
        callback_answered = _handle_fifty(callback_update, user, question_id)
        if not callback_answered:
            _release_inline_button(callback_update)
        return
    if service.PUBLIC_HELP_HINT_KEY == hint_key:
        _handle_public_help(callback_update, user, question_id)
        _release_inline_button(callback_update)
Example #3
0
def _handle_lose(update, user):
    lose_text = service.get_property(
        BOT_LOSE_TEXT,
        "Вы смогли ответить на {question_id} вопросов из {question_count}"
    ).format(question_id=service.get_max_passed_question_id(user),
             question_count=service.get_question_count())
    _reply(update, lose_text)
Example #4
0
def place_handler(_, update):
    user = update.effective_user
    service.add_player(user, update.effective_message.chat_id,
                       datetime.datetime.now())
    place = service.get_user_place(user)
    if place:
        place_text = service.get_property(
            BOT_PLACE_TEXT, 'Сейчас Вы на {}м месте').format(place)
        _reply(update, place_text)
    else:
        start_handler(_, update)
Example #5
0
def _handle_fifty(update, user, question_id):
    """
    :return: if callback_query answered
    """
    message = update.effective_message
    question = service.get_question(question_id)
    variants_to_leave = len(question.variants) - int(
        len(question.variants) / 2)
    if variants_to_leave <= 1:
        text = service.get_property(BOT_FIFTY_FOR_TWO_TEXT, 'Серьезно?)')
        return _show_notification_if_possible(text, update)

    rest = [variant for variant in question.variants if variant.correct]
    rest += random.sample(
        [variant for variant in question.variants if not variant.correct],
        variants_to_leave - len(rest))
    keyboard = _build_keyboard(question.question_id,
                               {v.variant_id: v.text_value
                                for v in rest},
                               service.get_available_hints(user))
    message.edit_reply_markup(reply_markup=keyboard)
    return False
Example #6
0
def _handle_win(update):
    win_text = service.get_property(BOT_WIN_TEXT,
                                    "Вы успешно ответили на все вопросы")
    _reply(update, win_text)
Example #7
0
def _handle_retry(update):
    retry_text = service.get_property(BOT_RETRY_TEXT, "Попробуйте еще раз")
    _show_notification_if_possible(update, retry_text)