Ejemplo n.º 1
0
def handler_gasto(bot, update):
    username = telegram_helper.get_username_from_update(update)
    auth = GoogleAuth(username)
    logging.info("User %s starting conversation.", username)

    if not auth.is_authorized():
        logging.info(
            "User %s needs to authorize this bot in its Google Account",
            username)
        update.message.reply_text(
            'Necesitas autorizar el bot antes. Corré el comando /autorizar')
        return

    if username not in get_enabled_usernames():
        update.message.reply_text('No estás habilitado para usar esto!')
        return

    if username in CURRENT_EXPENDITURES:
        update.message.reply_text(
            'Tenías un gasto a medio cargar, se descarta el gasto anterior')

    CURRENT_EXPENDITURES[username] = {}

    keyboard_opts = get_categories_keyboard()

    reply_markup = InlineKeyboardMarkup(keyboard_opts)
    update.message.reply_text('Categoria?', reply_markup=reply_markup)
    return CATEGORY
Ejemplo n.º 2
0
def handler_amount(bot, update):
    #TODO validar que esto sea algo numérico
    amount = update.message.text

    CURRENT_EXPENDITURES[telegram_helper.get_username_from_update(update)]['amount'] = amount
    update.message.reply_text("Ingresá descripción")

    return DESCRIPTION
Ejemplo n.º 3
0
def handler_description(bot, update):
    description = update.message.text
    username = telegram_helper.get_username_from_update(update)

    CURRENT_EXPENDITURES[username]['description'] = description
    update_sheet(username, CURRENT_EXPENDITURES)
    del CURRENT_EXPENDITURES[username]
    update.message.reply_text("Gasto cargado!")

    return ConversationHandler.END
Ejemplo n.º 4
0
def handler_category(bot, update):
    query = update.callback_query
    category = query.data
    username = telegram_helper.get_username_from_update(update)
    CURRENT_EXPENDITURES[username]['category'] = category

    bot.send_message(text="Monto?",
                     chat_id=query.message.chat_id,
                     message_id=query.message.message_id)
    return AMOUNT
Ejemplo n.º 5
0
def handler_auth(bot, update):
    username = telegram_helper.get_username_from_update(update)
    logging.info("User %s starting auth.", username)
    auth = GoogleAuth(username)
    if auth.is_authorized():
        update.message.reply_text('El bot ya está autorizado!')
        return ConversationHandler.END
    url = auth.get_credential()
    update.message.reply_html(
        'Si estás de acuerdo, por favor visita el <a href="' + url +
        '">enlace</a> y copia el código que te da Google')
    return ENTER_CODE
Ejemplo n.º 6
0
def handler_auth_code(bot, update):
    username = telegram_helper.get_username_from_update(update)
    auth = GoogleAuth(username)
    code = update.message.text
    logging.info("user %s sent code %s", username, code)
    auth.get_credential(code=code)
    response_text = 'Autorización exitosa!'
    if not auth.is_authorized():
        response_text = 'Problemas con la autorización'
        logging.info('Problemas con la autorización de ' + username)

    update.message.reply_text(response_text)
    return ConversationHandler.END
Ejemplo n.º 7
0
def handler_amount(bot, update):
    amount = update.message.text
    # reemplazamos , por ., para validar el float. Si, no es la mejor manera de trabajar con formatos numéricos, pero...
    amount_to_validate = amount.replace(",", ".")
    if not telegram_helper.is_float(amount_to_validate):
        update.message.reply_text(
            "El valor no parece numérico. Ponete los lentes 🤓")
        return AMOUNT
    CURRENT_EXPENDITURES[telegram_helper.get_username_from_update(
        update)]['amount'] = amount
    update.message.reply_text("Ingresá descripción")

    return DESCRIPTION
Ejemplo n.º 8
0
def handler_gasto(bot, update):
    username = telegram_helper.get_username_from_update(update)
    auth = GoogleAuth(username)
    logging.info("User %s starting conversation.", username)

    if not auth.is_authorized():
        logging.info("User %s needs to authorize this bot in its Google Account", username)
        update.message.reply_text('Necesitas autorizar el bot antes. Corré el comando /autorizar')
        return

    if username not in get_enabled_usernames():
        update.message.reply_text('No estás habilitado para usar esto!')
        return

    if username in CURRENT_EXPENDITURES:
        update.message.reply_text('Tenías un gasto a medio cargar, se descarta el gasto anterior')

    CURRENT_EXPENDITURES[username] = {}

    keyboard_opts = []
    keyboard_opt_row = []
    idx = 0
    for category in config.CATEGORIES:
        keyboard_opt_row.append(InlineKeyboardButton(category, callback_data=category))
        idx = idx + 1
        if idx == CATEGORY_COLUMNS:
            keyboard_opts.append(keyboard_opt_row)
            keyboard_opt_row = []
            idx = 0

    if idx != CATEGORY_COLUMNS:
        keyboard_opts.append(keyboard_opt_row)

    reply_markup = InlineKeyboardMarkup(keyboard_opts)
    update.message.reply_text('Categoria?', reply_markup=reply_markup)
    return CATEGORY
Ejemplo n.º 9
0
def cancel_auth(bot, update):
    username = telegram_helper.get_username_from_update(update)
    logging.info("User %s canceled the auth.", username)
Ejemplo n.º 10
0
def cancel(bot, update):
    username = telegram_helper.get_username_from_update(update)
    logging.info("User %s canceled the conversation.", username)
    del CURRENT_EXPENDITURES[username]
    update.message.reply_text("Carga cancelada")
    return ConversationHandler.END