Пример #1
0
async def process_destination(
    message: types.Message,
    state: dispatcher.FSMContext,
):
    async with state.proxy() as data:
        string = helpers.prepare_text_input(message.text)
        suggester = suggests.StationSuggester(string)
        await suggester.suggest_station()
        if not suggester.is_exact_match:
            msg = messages.CANNOT_FIND_EXACT_MATCH
            markup = markups.build_from_list(suggester.suggestions.keys())
        else:
            await bot.bot.send_message(state.user, messages.WAIT_TRAINS_SEARCH)
            data['destination'] = suggester.match_id
            trains = await suggests.trains(
                data['departure'],
                data['destination'],
                data['date'],
            )
            if not trains:
                await bot.bot.send_message(state.user, messages.NO_TRAINS)
                await cmd_cancel(message, state)
                return
            await forms.MonitorParameters.next()
            send_function = functools.partial(
                message.reply,
                parse_mode=ParseMode.MARKDOWN,
            )
            await _send_trains(
                send_function,
                messages.AVAILABLE_TRAINS_HEADER,
                trains,
            )
            msg = messages.CHOOSE_TRAIN_NUMBER_TEMPLATE.format(
                next(iter(trains)), )
            markup = markups.build_from_list(number
                                             for number in sorted(trains))
    await message.reply(
        msg,
        reply_markup=markup,
        parse_mode=ParseMode.MARKDOWN,
    )
Пример #2
0
async def process_train(message: types.Message, state: dispatcher.FSMContext):
    async with state.proxy() as data:
        data['train'] = helpers.prepare_text_input(message.text)

    await forms.MonitorParameters.next()
    markup = markups.build_from_list(config.SUGGEST_TYPES)
    await message.reply(
        messages.QUESTION_CAR_TYPE,
        reply_markup=markup,
        parse_mode=ParseMode.MARKDOWN,
    )
Пример #3
0
async def process_car_type(
    message: types.Message,
    state: dispatcher.FSMContext,
):
    async with state.proxy() as data:
        data['car_type'] = message.text

    markup = markups.build_from_list(config.SUGGEST_COUNT)
    await forms.MonitorParameters.next()
    await message.reply(
        messages.QUESTION_TICKETS_QUANTITY,
        reply_markup=markup,
    )
Пример #4
0
async def cmd_set(message: types.Message, state: dispatcher.FSMContext):
    """
    Setting Monitor entry point
    """
    if state.user in bot.messengers and not bot.messengers[state.user].stop:
        msg = messages.ANOTHER_MONITOR_IS_RUN
        await message.reply(msg, reply_markup=markups.DEFAULT_MARKUP)
        return

    # Set state
    await forms.MonitorParameters.date.set()

    days = helpers.nearest_days_string()
    text = messages.QUESTION_DATE_TEMPLATE.format(days[0])
    markup = markups.build_from_list(days)
    await message.reply(text, reply_markup=markup)
Пример #5
0
async def process_departure(
    message: types.Message,
    state: dispatcher.FSMContext,
):
    async with state.proxy() as data:
        string = helpers.prepare_text_input(message.text)
        suggester = suggests.StationSuggester(string)
        await suggester.suggest_station()
        if not suggester.is_exact_match:
            msg = messages.CANNOT_FIND_EXACT_MATCH
            markup = markups.build_from_list(suggester.suggestions.keys())
        else:
            data['departure'] = suggester.match_id
            await forms.MonitorParameters.next()
            msg = messages.QUESTION_DESTINATION_STATION
            markup = markups.DIRECTIONS_MARKUP
    await message.reply(msg, reply_markup=markup)