Exemple #1
0
def rcp_recognition(update, context):
    """Тестирование распознавания речи"""
    user = update.message.from_user
    rcp_logger.info('Пользователь {} отправил голосовое сообщение'.format(
        user.first_name))
    print(update)
    voice_file = VoiceFile(update.message.voice.file_id,
                           update.message.voice.file_unique_id,
                           update.message.voice.duration,
                           update.message.voice.mime_type,
                           update.message.voice.file_size,
                           str(appConfig['tg']['key']),
                           str(appConfig['app']['paths']['voice']))
    wav_file = voice_file.get_file()
    if os.path.isfile(wav_file):
        prediction = fire_recognition(wav_file, speech_models)
        out_msg = "Мне кажется или Вы сказали \"{}\" ?".format(prediction)
        # os.remove(wav_file)
    else:
        out_msg = "Извините, что-то пошло не так..."

    update.message.reply_text(
        out_msg + '\n\n'
        'На данный момент я могу распознать только слова: apple, banana, kiwi, lime, orange, peach, pineapple\n'
        'Убедитесь, что длина отправленного аудио-сообщения больше 2 секунд!',
        reply_markup=ReplyKeyboardRemove())
Exemple #2
0
def browse_my_rcp_category(update, context):
    RG.searchable_category = update.message.text
    user = update.message.from_user
    rcp_logger.info('Пользователь %s выбирает категорию своих рецептов %s' %
                    (user.username, update.message.text))

    return RG.response_generator('my_search_by_cat', update)
Exemple #3
0
def search_recipe(update, context):
    RG.rcp_keyword = update.message.text

    user = update.message.from_user
    rcp_logger.info('Пользователь %s пытается найти рецепт по запросу %s' %
                    (user.username, update.message.text))

    return RG.response_generator('search_by_keyword', update)
Exemple #4
0
def searchable_status(update, context):
    user = update.message.from_user
    RG.my_recipe.is_searchable = False if update.message.text == 'Нет, рецепт приватный' else True

    rcp_logger.info(
        'Пользователь %s ответил на вопрос о приватности рецепта: %s' %
        (user.username, update.message.text))

    return RG.response_generator('confirm_recipe', update)
Exemple #5
0
def choice_one(update, context):
    user = update.message.from_user
    rcp_logger.info('Пользователь %s выбрал %s' %
                    (user.username, update.message.text))
    if update.message.text == 'Добавить рецепт':
        return RG.response_generator('new_recipe', update)
    elif update.message.text == 'Посмотреть мои рецепты':
        return RG.response_generator('browse_my_recipes', update)
    else:
        return RG.response_generator('search_recipe', update)
Exemple #6
0
def new_tags(update, context):
    user = update.message.from_user
    RG.my_recipe.tag_id = get_category_by_name(update.message.text)

    rcp_logger.info('Пользователь %s выбрал категорию \"%s\"' %
                    (user.username, update.message.text))

    return RG.response_generator(
        'confirm_recipe',
        update) if RG.from_confirm else RG.response_generator(
            'search_status', update)
Exemple #7
0
def new_descriptions(update, context):
    user = update.message.from_user
    RG.my_recipe.description = update.message.text

    rcp_logger.info('Пользователь %s ввёл сам рецепт \"%s\"' %
                    (user.username, update.message.text))

    return RG.response_generator(
        'confirm_recipe',
        update) if RG.from_confirm else RG.response_generator(
            'recipe_tag', update)
Exemple #8
0
def new_components(update, context):
    user = update.message.from_user
    RG.my_recipe.ingredients = update.message.text

    rcp_logger.info('Пользователь %s ввёл список ингредиентов \"%s\"' %
                    (user.username, update.message.text))

    return RG.response_generator(
        'confirm_recipe',
        update) if RG.from_confirm else RG.response_generator(
            'recipe_description', update)
Exemple #9
0
def new_recipe_name(update, context):
    user = update.message.from_user

    RG.my_recipe.user_id = user.id
    RG.my_recipe.user_name = user.username
    RG.my_recipe.title = update.message.text

    rcp_logger.info('Пользователь %s ввёл имя рецепта %s' %
                    (user.username, update.message.text))

    return RG.response_generator(
        'confirm_recipe',
        update) if RG.from_confirm else RG.response_generator(
            'recipe_components', update)
Exemple #10
0
def choose_search_result(update, context):
    user = update.callback_query.from_user
    query = update.callback_query
    query.answer()

    RG.selected_recipe = format(query.data)

    rcp_logger.info('Пользователь %s выбирает из поиска рецепт с ID = %s' %
                    (user.username, RG.selected_recipe))

    context.bot.send_message(chat_id=update.effective_chat.id,
                             text="Спасибо, что воспользовались Рецептуарием!",
                             reply_markup=ReplyKeyboardRemove())

    return RG.response_generator('my_search_rcp_selected', update)
Exemple #11
0
def store_user_like(update, context):
    user = update.callback_query.from_user
    query = update.callback_query
    query.answer()

    user_id, recipe_id = format(query.data).split('~')
    like_recipe(user_id, recipe_id)

    rcp_logger.info('Пользователь %s лайкает рецепт с ID = %s' %
                    (user.username, recipe_id))

    context.bot.send_message(chat_id=update.effective_chat.id,
                             text="Спасибо за лайк!",
                             reply_markup=ReplyKeyboardRemove())
    query.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup([]))
    return RG.response_generator('store_user_like', update)
Exemple #12
0
def confirm_choice(update, context):
    RG.from_confirm = True

    user = update.message.from_user
    rcp_logger.info('Пользователь %s выбрал %s' %
                    (user.username, update.message.text))

    if update.message.text == 'Да, сохранить рецепт':
        RG.my_recipe.save_recipe()
        return RG.response_generator('recipe_created', update)
    elif update.message.text == 'Нет, изменить название':
        return RG.response_generator('new_recipe', update)
    elif update.message.text == 'Нет, изменить ингредиенты':
        return RG.response_generator('recipe_components', update)
    elif update.message.text == 'Нет, изменить описание':
        return RG.response_generator('recipe_description', update)
    elif update.message.text == 'Нет, изменить категорию':
        return RG.response_generator('recipe_tag', update)
    elif update.message.text == 'Нет, изменить приватность':
        return RG.response_generator('search_status', update)
Exemple #13
0
def cancel(update, context):
    user = update.message.from_user
    rcp_logger.info('Пользователь %s завершил диалог' % user.first_name)

    return RG.response_generator('cancel', update)