def message_return(response, user_storage, text, speech, buttons, mode,
                   user_id, database):
    little_fuctions.update_mode(user_id, mode, database)
    text = text.replace('+', '')
    if not (text.endswith('.') or text.endswith('!') or text.endswith('?')):
        text += '.'
    response.set_text(text)
    response.set_tts(speech +
                     silence * little_fuctions.get_silent(user_id, database))
    user_storage["suggests"] = buttons
    database.update_entries('users_info',
                            user_id, {'last_buttons': '#'.join(buttons)},
                            update_type='rewrite')
    buttons, user_storage = little_fuctions.get_suggests(user_storage)
    if mode == "":
        user_storage["card"] = start_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == 'settings':
        user_storage["card"] = settings(
            little_fuctions.get_color(user_id, database), user_id, database)
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "yesno>main":
        user_storage["card"] = yesno_card(
            little_fuctions.get_color(user_id, database), user_id, database)
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "croco>main":
        user_storage["card"] = croco_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "Inever>main":
        user_storage["card"] = inever_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "croco>difficulty":
        user_storage["card"] = croco_diff_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    else:
        response.set_buttons(buttons)
    database.update_entries('users_info',
                            user_id, {'last_text': text},
                            update_type='rewrite')
    database.update_entries('users_info',
                            user_id, {'last_speech': speech},
                            update_type='rewrite')
    return response, user_storage
def start(input, id, database):
    import little_fuctions
    mode = little_fuctions.get_mode(id, database)
    game = 'Inever'
    if not mode.startswith(game):
        text, speech, buttons = return_start()
        mode = '{}>main'.format(game)
    elif mode == '{}>main'.format(game) and little_fuctions.isequal(
            input, 'Правила'):
        text, speech, buttons = return_rules()
        silent = (1 - little_fuctions.get_silent(id, database))
        text += '' + '\n\nНе забывайте нажимать на синюю кнопку, чтобы я не мешала вам.' * silent
        speech += '' + '\n\n - - - Не забывайте нажимать на синюю кнопку, чтобы я не мешала вам.' * silent
        mode = '{}>rules'.format(game)
    elif (mode == '{}>rules'.format(game) or mode == '{}>main'.format(game)) \
            and little_fuctions.isequal(input, 'Начать'):
        text, speech, buttons = return_riddle(0, id, database)
        mode = '{}>riddle>1>0'.format(game)
    elif (mode == '{}>rules'.format(game) or mode == '{}>main'.format(game)) \
            and little_fuctions.isequal(input, 'Играть с разработчиком'):
        text, speech, buttons = return_riddle(1, id, database)
        mode = '{}>riddle>1>1'.format(game)
    elif mode == '{}>rules'.format(game) and little_fuctions.isequal(
            input, 'Другой вариант игры'):
        text, speech, buttons = return_another_rules()
        mode = '{}>another_rules'.format(game)
    elif mode == '{}>another_rules'.format(game) and little_fuctions.isequal(
            input, 'Другой вариант игры'):
        text, speech, buttons = return_rules()
        mode = '{}>rules'.format(game)
    elif mode == '{}>another_rules'.format(game) and little_fuctions.isequal(
            input, 'Варианты действий'):
        import I_have_never_ever_biblio, random
        mediator = I_have_never_ever_biblio.questions[:]
        random.shuffle(mediator)
        text = 'У нас много вариантов, покажу случайные 20\n\n' \
               'Я никогда не...\n' + '\n'.join([ str(i + 1) + ') ' + j for i, j in enumerate(mediator[:20])])
        speech = 'Приятной игр+ы!'
        buttons = ['В начало']
        mode = '{}>another'.format(game)
    elif mode.startswith('{}>riddle>'.format(game)):
        import I_have_never_ever_biblio
        number = int(mode.split('>')[2])
        fl = int(mode.split('>')[3])
        if little_fuctions.isequal(input, 'Дальше'):
            text, speech, buttons = return_riddle(fl, id, database)
            mode = '{}>riddle>{}>{}'.format(game, number, fl)
        else:
            return False
    else:
        return False
    return text, speech, buttons, mode
def idk_return(response, user_storage, user_id, database, mode, comment=''):
    last_text, last_speech, last_buttons = little_fuctions.get_lasts(
        user_id, database)
    if comment == 'again':
        text = last_text
        speech = last_speech
    elif comment:
        text = comment
        speech = comment
    else:
        text = little_fuctions.idk() + '\n\n{}'.format(last_text)
        speech = little_fuctions.idk() + '\n\n{}'.format(last_speech)
    buttons = last_buttons
    text = text.replace('+', '')
    response.set_text(text)
    response.set_tts(speech +
                     silence * little_fuctions.get_silent(user_id, database))
    user_storage["suggests"] = buttons
    buttons, user_storage = little_fuctions.get_suggests(user_storage)
    if mode == "":
        user_storage["card"] = start_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == 'settings':
        user_storage["card"] = settings(
            little_fuctions.get_color(user_id, database), user_id, database)
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "yesno>main":
        user_storage["card"] = yesno_card(
            little_fuctions.get_color(user_id, database), user_id, database)
        response.set_card(user_storage["card"])
    elif mode == "croco>main":
        user_storage["card"] = croco_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "Inever>main":
        user_storage["card"] = inever_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    elif mode == "croco>difficulty":
        user_storage["card"] = croco_diff_card(
            little_fuctions.get_color(user_id, database))
        user_storage["card"]["header"]["text"] = text
        response.set_card(user_storage["card"])
    else:
        response.set_buttons(buttons)
    return response, user_storage
Esempio n. 4
0
def settings(color, used_id, database):
    import little_fuctions
    color = (color + default_color) % colors
    silent_on = (little_fuctions.get_silent(used_id, database) != 0)
    return {
            "type": "ItemsList",
            "header": {
                "text": "Настройки",
            },
            "items": [
                {
                    "image_id": rgb[color],
                    "title": "Сменить цвета",
                    "description": "Почему бы и нет?",
                    "button": {
                        "payload": {"name": "Сменить цвета"}
                    }
                },
                {
                    "image_id": deaf[color] if silent_on else hear[color],
                    "title": 'Тихий режим' + ('[ON]' if silent_on else '[OFF]'),
                    "description":
                        'Сейчас я не слушаю вас 2 минуты после своей фразы' if silent_on
                        else 'Сейчас я слушаю вас сразу после своей фразы.',
                    "button": {
                        "payload": {"name": "Тихий режим"}
                    }
                },
                {
                    "image_id": rate[color],
                    "title": "Оценить",
                    "description": "Поставить оценку нашему чудесному навыку",
                    "button": {
                        "url": "https://dialogs.yandex.ru/store/skills/96b7421d-igroteka-uyut-i-vesel-e-dlya-druz",
                        "payload": {"name": "url"}
                    }
                },
                {
                    "image_id": home[color],
                    "title": "В начало",
                    "description": "Вернуться к истокам.",
                    "button": {
                        "payload": {"name": "В начало"}
                    }
                }
            ],
    }
def handle_dialog(request, response, user_storage, database):
    if not database.get_entry("users_info", ['new'],
                              {'request_id': request.user_id}):
        database.add_entries("users_info", {"request_id": request.user_id})
    if not user_storage:
        user_storage = {"suggests": []}
    if "command" in request.request.keys():
        input = request.command
    else:
        input = request.payload
    user_id = request.user_id
    is_first_time = request.is_new_session
    if is_first_time:
        text = 'Вас приветствует Игротека - спутник дружеских компаний. Надеюсь, мы с вами поладим. ' \
               'Выберите игру - и мы начнем.'
        speech = text
        mode = ''
        buttons = []
        return message_return(response, user_storage, text, speech, buttons,
                              mode, user_id, database)
    else:
        mode = little_fuctions.get_mode(user_id, database)

    if little_fuctions.isequal(input, 'В начало'):
        mode = ''
        input = ''

    games = ['Данетки', 'Я никогда не', 'Крокодил']

    if little_fuctions.isequal(input, 'Помощь'):
        text = 'В этом навыке все просто! Выбери игру и скажи "начать". ' \
               'Правила ты сможешь посмотреть в меню игры. Желаю хорошо провести время!'
        speech = text
        buttons = games[:]
        mode = ''
        return message_return(response, user_storage, text, speech, buttons,
                              mode, user_id, database)
    elif little_fuctions.isequal(input, 'Еще раз'):
        return idk_return(response, user_storage, user_id, database, mode,
                          'again')
    elif mode.startswith('yesno') or (mode == '' and little_fuctions.isequal(
            input, 'Данетки')):
        import yes_no_puzzle
        succes = yes_no_puzzle.start(input, user_id, database)
        if succes:
            return message_return(response, user_storage, *succes, user_id,
                                  database)
        else:
            return idk_return(response, user_storage, user_id, database, mode)
    elif mode.startswith('Inever') or (mode == '' and little_fuctions.isequal(
            input, 'Я никогда не')):
        import I_have_never_ever
        succes = I_have_never_ever.start(input, user_id, database)
        if succes:
            return message_return(response, user_storage, *succes, user_id,
                                  database)
        else:
            return idk_return(response, user_storage, user_id, database, mode)
    elif mode.startswith('croco') or (mode == '' and little_fuctions.isequal(
            input, 'Крокодил')):
        import croco
        succes = croco.start(input, user_id, database)
        if succes:
            return message_return(response, user_storage, *succes, user_id,
                                  database)
        else:
            return idk_return(response, user_storage, user_id, database, mode)
    elif mode == 'settings' and little_fuctions.isequal(
            input, 'Сменить цвета'):
        little_fuctions.update_color(
            little_fuctions.get_color(user_id, database) + 1, user_id,
            database)
        if (little_fuctions.get_color(user_id, database) +
                default_color) % colors in blocked_colors:
            little_fuctions.update_color(
                little_fuctions.get_color(user_id, database) + 1, user_id,
                database)
        text = little_fuctions.go_color()
        speech = text
        mode = 'settings'
        buttons = []
        return message_return(response, user_storage, text, speech, buttons,
                              mode, user_id, database)
    elif mode == 'settings' and little_fuctions.isequal(input, 'Тихий режим'):
        little_fuctions.update_silent(
            1 - little_fuctions.get_silent(user_id, database), user_id,
            database)
        return idk_return(response, user_storage, user_id, database, mode,
                          'Поняла вас, Сэр!')
    elif (mode == '' and little_fuctions.isequal(
            input, 'Настройки')) or mode == 'settings':
        mode = 'settings'
        text = little_fuctions.go_settings()
        speech = text
        buttons = []
        return message_return(response, user_storage, text, speech, buttons,
                              mode, user_id, database)
    elif mode == '' and little_fuctions.isequal(input, 'Другая игра'):
        import other_games, random
        mode = ''
        used = little_fuctions.get_set(user_id, database)
        if len(used) == len(other_games.data):
            used = set()
        mediator = set(other_games.data).difference(used)
        text = random.choice(list(mediator))
        used.add(text)
        little_fuctions.update_set(used, user_id, database)
        speech = text
        buttons = []
        return message_return(response, user_storage, text, speech, buttons,
                              mode, user_id, database)
    elif mode == '':
        text = little_fuctions.hello()
        speech = text
        mode = ''
        buttons = []
        little_fuctions.update_set(set(), user_id, database)
        return message_return(response, user_storage, text, speech, buttons,
                              mode, user_id, database)
    else:
        return idk_return(response, user_storage, user_id, database, mode)