Esempio n. 1
0
def handle_what_is(req, res, tokens):
    if "что" in tokens and "такой" in tokens or \
            "как" in tokens and "выглядеть" in tokens:
        filter(lambda t: t != "что" and t != "такой", tokens)
        for token in tokens:
            for d in GLOBAL_DATA['DICTIONARY']:
                for variant in d:
                    flag = False
                    if isinstance(variant, tuple):
                        flag = True
                        for word in variant:
                            if word[0] == '-':
                                if word in tokens:
                                    flag = False
                            else:
                                if word not in tokens:
                                    flag = False

                    elif variant == token:
                        flag = True

                    if flag:
                        if len(GLOBAL_DATA['DICTIONARY'][d]) == 1:
                            res['response']['text'] = GLOBAL_DATA[
                                'DICTIONARY'][d][0]
                            res['response']['buttons'] = get_suggests(
                                GLOBAL_DATA['START_SUGGEST'])
                        elif len(GLOBAL_DATA['DICTIONARY'][d]) == 2:
                            res['response']['card'] = {
                                "type":
                                "ItemsList",
                                "header": {
                                    "text":
                                    GLOBAL_DATA['DICTIONARY'][d][0]
                                    if GLOBAL_DATA['DICTIONARY'][d][0] else
                                    "Это легче показать, чем описать:",
                                },
                                "items": [{
                                    "title":
                                    "пример",
                                    "image_id":
                                    GLOBAL_DATA['DICTIONARY'][d][1]
                                }]
                            }
                            if GLOBAL_DATA['DICTIONARY'][d][0]:
                                res['response']['text'] = GLOBAL_DATA[
                                    'DICTIONARY'][d][0]
                            res['response']['buttons'] = get_suggests(
                                GLOBAL_DATA['START_SUGGEST'])
                        return True
    return False
Esempio n. 2
0
def handle_help(req, res, tokens):
    if "помощь" in tokens or ("что" in tokens and "ты" in tokens
                              and "уметь" in tokens):
        res['response']['text'] = GLOBAL_DATA['HELP_TEXT_FULL']
        res['response']['buttons'] = get_suggests(GLOBAL_DATA['START_SUGGEST'])
        return True
    return False
Esempio n. 3
0
def handle_random_recipe(req, res, tokens):
    if ("коктейль" in tokens or "рецепт"
            in tokens) and ("какой" in tokens and "нибыть" in tokens
                            or "случайный" in tokens or "рандомный" in tokens):
        res['response']['text'] = gen_text_cocktail(
            random.choice(list(GLOBAL_DATA['COCKTAILS'].keys())))
        res['response']['buttons'] = get_suggests(GLOBAL_DATA['START_SUGGEST'])
        return True
    return False
Esempio n. 4
0
def handle_how_to_drink(req, res, tokens):
    if "пить" in tokens:
        tokens.remove("пить")
        for alco in GLOBAL_DATA['ALCO']:
            a_norm = norm(alco)
            for a in a_norm:
                if a in tokens:
                    res['response']['text'] = gen_text_alco(alco)
                    res['response']['buttons'] = get_suggests(
                        ["Коктейли с " + alco])
                    return True
    return False
Esempio n. 5
0
def handle_new_session(req, res, tokens):
    if req['session']['new']:
        res['response']['card'] = {
            "type": "BigImage",
            "image_id": "997614/29e868d8ba3548bc33c8",
            "title": "Здравствуйте. Чем могу быть полезен?",
            "description":
            GLOBAL_DATA['HELP_TEXT'] + '\n\nСоздано при поддержке barclass.ru',
            "button": {
                "text": "Посетить сайт",
                "url": "http://barclass.ru",
                "payload": {}
            }
        }
        res['response']['text'] = GLOBAL_DATA['HELP_TEXT']
        res['response']['buttons'] = get_suggests(GLOBAL_DATA['START_SUGGEST'])
        return True
    return False
Esempio n. 6
0
def handle_default(req, res, tokens):
    res['response']['text'] = 'Ничего не нашлось, давайте попробуем что-нибудь другое!' \
                              ' Для вызова справки скажите "помощь"'
    res['response']['buttons'] = get_suggests(GLOBAL_DATA['START_SUGGEST'])
    return True