Example #1
0
def manage_routes(update, context):

    context.user_data.clear()
    user_id = update.effective_user.id

    routes, error = services.list_routes(user_id)
    if error and routes is None:
        update.effective_message.reply_text(error)
        return

    keyboard = []
    if routes:
        for i, route in enumerate(routes, start=1):
            keyboard.append([
                button(text=f'{i}->', callback_data=f'{i}_there'),
                button(text=f'<-{i}', callback_data=f'{i}_back')
            ])
        keyboard.append([button(text='Добавить маршрут', callback_data='add')])
        keyboard.append([button(text='Удалить маршрут', callback_data='del')])
        update.effective_message.reply_text('Выберите маршрут')
        reply_markup = InlineKeyboardMarkup(keyboard)
        update.effective_message.reply_text('\n'.join(routes_to_list(routes)),
                                            reply_markup=reply_markup)
    else:
        keyboard.append([button(text='Добавить маршрут', callback_data='add')])
        reply_markup = InlineKeyboardMarkup(keyboard)
        update.effective_message.reply_text(
            'Нет сохраненных маршрутов. Добавить?', reply_markup=reply_markup)
    return CHOOSE_ROUTE
Example #2
0
def choose_route_to_del(update, context):
    user_id = update.effective_user.id

    routes, error = services.list_routes(user_id)
    if error:
        update.effective_message.reply_text(error)
        return
    keyboard = [[button(text=f'Удалить! {i} ', callback_data=f'{i}_del')]
                for i, route in enumerate(routes, start=1)]
    keyboard.append([button(text='Отмена', callback_data='cancel')])
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.effective_message.reply_text('Какой маршрут удалить?\n' +
                                        '\n'.join(routes_to_list(routes)),
                                        reply_markup=reply_markup)
    return DELETE_ROUTE
Example #3
0
def add_from_alias(update, context):
    context.user_data['from_alias'] = safe(update.effective_message.text)
    keyboard = [[button(text='Отмена', callback_data='cancel')]]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text('Введите адрес назначения',
                              reply_markup=reply_markup)
    return ADD_TO
Example #4
0
def add_to_address(update, context):
    context.user_data['to_address'] = safe(update.effective_message.text)
    keyboard = [[button(text='Отмена', callback_data='cancel')]]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text(
        'Введите короткое название, например: Работа или 🏢',
        reply_markup=reply_markup)
    return ALIAS_TO
Example #5
0
def add_route(update, context):
    keyboard = [[button(text='Отмена', callback_data='cancel')]]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.effective_message.reply_text('Введите адрес отправления',
                                        reply_markup=reply_markup)
    return ADD_FROM