예제 #1
0
def generate_random(update, context):

    # TODO: как-то по умному сделать штоле
    try:
        if not context.user_data['gender']:
            logger.info('user data not updated, trying to update...')
            update_user_data(update, context, session)
            logger.info('updated user data!')
    except Exception as e:
        logger.info('user context not initialized. updating user data...')
        update_user_data(update, context, session)
        logger.info('updated user data!')
    excuse_context = random.choice([
        'family', 'personal', 'health', 'leisure', 'work', 'study', 'official'
    ])
    for i in range(MAX_RETRY):
        try:
            text = test_constructor(words=df,
                                    morph=morph,
                                    context=excuse_context,
                                    subj_sex=context.user_data['gender'],
                                    tense=context.user_data['tense'])
            logger.info('generated text')
            update.message.reply_text(text, reply_markup=keyboard)
        except:
            logger.warning('failed to generate text')
            continue
        else:
            break
    return ConversationHandler.END
예제 #2
0
def generate_crazy(update, context):
    for i in range(MAX_RETRY):
        try:
            text = test_constructor(words=df, morph=morph)
            logger.info('generated text')
            update.message.reply_text(text, reply_markup=fun_keyboard)
        except:
            logger.warning('failed to generate text')
            continue
        else:
            break
    return IN_FUN
예제 #3
0
def generate_not_serious(update, context):
    for i in range(MAX_RETRY):
        try:
            text = test_constructor(words=df,
                                    morph=morph,
                                    max_seriousness=3,
                                    subj_sex=context.user_data['gender'],
                                    tense=context.user_data['tense'])
            logger.info('generated text')
            update.message.reply_text(text, reply_markup=keyboard)
        except:
            logger.warning('failed to generate text')
            continue
        else:
            break
예제 #4
0
def generate_leisure(update, context):
    for i in range(MAX_RETRY):
        try:
            text = test_constructor(words=df,
                                    morph=morph,
                                    context='leisure',
                                    subj_sex=context.user_data['gender'],
                                    tense=context.user_data['tense'])
            logger.info('generated text')
            update.message.reply_text(text, reply_markup=context_keyboard)
        except:
            logger.warning('failed to generate text')
            continue
        else:
            break
    return IN_CONTEXTS