Example #1
0
def build_step(vk,
               event,
               upload,
               job_queue,
               step,
               player_quest,
               text="Вы победили!"):
    if step:
        print(step)
        if step.image:
            image = get_or_upload_photo(upload, step, "image", step.image)
            vk.messages.send(peer_id=event.obj.from_id,
                             random_id=get_random_id(),
                             attachment=image)

        options_temp = step.options.all()
        options = []
        changes = player_quest.changes.all()
        for option in options_temp:
            is_hidden = option.is_hidden
            if option in changes:
                is_hidden = not option.is_hidden
            if not is_hidden:
                options.append(option)

        if options:
            button_list = VkKeyboard()
            for option in options:
                button_list.add_button(option.text)
                button_list.add_line()
            button_list.add_button(quest_utils.menu_text_full("MAIN_MENU"))
            send_step_partly(vk, event, job_queue, button_list, step.delay,
                             step.description)
        else:
            # Step has no options - Lose
            button_list = VkKeyboard()
            button_list.add_button(
                quest_utils.menu_text_full("ASK_TO_RESTART"))
            button_list.add_line()
            button_list.add_button(quest_utils.menu_text_full("MAIN_MENU"))
            vk.messages.send(
                peer_id=event.obj.from_id,
                random_id=get_random_id(),
                message=step.description,
                keyboard=button_list.get_keyboard(),
            )
    else:
        button_list = VkKeyboard()
        button_list.add_button(quest_utils.menu_text_full("ASK_TO_RESTART"))
        button_list.add_line()
        button_list.add_button(quest_utils.menu_text_full("MAIN_MENU"))
        vk.messages.send(
            peer_id=event.obj.from_id,
            random_id=get_random_id(),
            message=(text + "\nНачать заново?"),
            keyboard=button_list.get_keyboard(),
        )
Example #2
0
def send_step_partly(bot, update, job_queue, description, delay_temp,
                     reply_markup):
    step_parts = description.split("_")
    step_parts_len = len(step_parts)
    start = 0
    reply_part = ReplyKeyboardMarkup(
        build_menu([quest_utils.menu_text_full("MAIN_MENU")], n_cols=1),
        resize_keyboard=True,
    )

    for i, part_temp in enumerate(step_parts):
        part = part_temp.split("~")
        delay = float(part[1]) if len(part) >= 2 else delay_temp
        if i == 0 and i == step_parts_len - 1:
            bot.send_message(update.effective_chat.id,
                             part[0],
                             reply_markup=reply_markup)
        elif i == 0:
            bot.send_message(update.effective_chat.id,
                             part[0],
                             reply_markup=reply_part)
        elif i == step_parts_len - 1:
            start += delay
            job_queue.run_once(_send_step_final,
                               start,
                               context=(update, part[0], reply_markup))
        else:
            start += delay
            job_queue.run_once(_send_step_part,
                               start,
                               context=(update, part[0], reply_part))
Example #3
0
def send_referral_input(vk, event):
    player, created = get_or_create_player(vk, event, join=True)

    if created:
        player.is_next_message_referral = True
        player.save()
        button_list = VkKeyboard()
        button_list.add_button(quest_utils.menu_text_full("START_WO_REFERRED"))
        text = (
            'Укажите ID пользователя, который вас пригласил или нажмите "' +
            quest_utils.menu_text_full("START_WO_REFERRED") +
            '", чтобы пропустить этот этап')
        vk.messages.send(
            peer_id=event.obj.user_id,
            random_id=get_random_id(),
            message=text,
            keyboard=button_list.get_keyboard(),
        )
Example #4
0
def start_main_menu(bot, update, args=None):
    player, _ = utils.get_or_create_player(bot, update, args=args)
    player_quests = player.has_quests

    if player_quests:
        button_list = [
            KeyboardButton(quest_utils.menu_text_full("MY_GAMES")),
            KeyboardButton(quest_utils.menu_text_full("ALL_GAMES")),
            KeyboardButton(quest_utils.menu_text_full("SETTINGS")),
        ]
    else:
        button_list = [
            KeyboardButton(quest_utils.menu_text_full("ALL_GAMES")),
            KeyboardButton(quest_utils.menu_text_full("SETTINGS")),
        ]

    reply_markup = ReplyKeyboardMarkup(utils.build_menu(button_list, n_cols=1),
                                       resize_keyboard=True)
    bot.send_message(update.message.chat_id,
                     config.MAIN_MENU_TEXT,
                     reply_markup=reply_markup)
Example #5
0
def send_step_partly(vk, event, job_queue, keyboard, delay_temp, description):
    step_parts = description.split("_")
    step_parts_len = len(step_parts)
    start = 0
    button_list = VkKeyboard()
    button_list.add_button(quest_utils.menu_text_full("MAIN_MENU"))
    button_list = button_list.get_keyboard()
    keyboard_temp = keyboard.get_keyboard()

    for i, part_temp in enumerate(step_parts):
        part = part_temp.split("~")
        delay = float(part[1]) if len(part) >= 2 else delay_temp
        if i == 0 and i == step_parts_len - 1:
            job_queue.run_once(
                _send_step_final,
                start,
                context=(event.obj.from_id, part[0], keyboard_temp),
            )
        elif i == 0:
            job_queue.run_once(
                _send_step_part,
                start,
                context=(event.obj.from_id, part[0], button_list),
            )
        elif i == step_parts_len - 1:
            start += delay
            job_queue.run_once(
                _send_step_final,
                start,
                context=(event.obj.from_id, part[0], keyboard_temp),
            )
        else:
            start += delay
            job_queue.run_once(
                _send_step_part,
                start,
                context=(event.obj.from_id, part[0], button_list),
            )
Example #6
0
def build_step(bot,
               update,
               step,
               job_queue,
               player_quest,
               text="Вы победили!"):
    if step:
        if step.image:
            bot.send_photo(update.message.chat_id, photo=step.image)

        options_temp = step.options.all()
        options = []
        changes = player_quest.changes.all()
        for option in options_temp:
            is_hidden = option.is_hidden
            if option in changes:
                is_hidden = not option.is_hidden
            if not is_hidden:
                options.append(option)

        if options:
            button_list = [KeyboardButton(option.text) for option in options]
            button_list.append(
                KeyboardButton(quest_utils.menu_text_full("MAIN_MENU")))
            reply_markup = ReplyKeyboardMarkup(
                build_menu(button_list, n_cols=1),
                resize_keyboard=True,
                one_time_keyboard=True,
            )
            send_step_partly(
                bot,
                update,
                job_queue,
                step.description,
                step.delay,
                reply_markup=reply_markup,
            )
        else:
            # Step has no options - Lose
            button_list = [
                KeyboardButton(quest_utils.menu_text_full("ASK_TO_RESTART")),
                KeyboardButton(quest_utils.menu_text_full("MAIN_MENU")),
            ]
            reply_markup = ReplyKeyboardMarkup(build_menu(button_list,
                                                          n_cols=1),
                                               resize_keyboard=True)
            bot.send_message(update.effective_chat.id,
                             step.description,
                             reply_markup=reply_markup)
    else:
        button_list = [
            KeyboardButton(quest_utils.menu_text_full("ASK_TO_RESTART")),
            KeyboardButton(quest_utils.menu_text_full("MAIN_MENU")),
        ]
        reply_markup = ReplyKeyboardMarkup(build_menu(button_list, n_cols=1),
                                           resize_keyboard=True)
        bot.send_message(
            update.effective_chat.id,
            text + "\nНачать заново?",
            reply_markup=reply_markup,
        )