import api import database from fsm import FSM from models import iso_datetime, Message, FSMContext, InputFile import keyboards import re async def start(message: Message, state: FSMContext): await state.reset_state() await state.reset_data() await message.answer( text='Здравствуйте, %s!\nЧем могу помочь?' % message.from_user.first_name, reply_markup=keyboards.start(), ) await FSM.start.set() async def select_category(message: Message, state: FSMContext): await message.answer( text='Выберете категорию.', reply_markup=await keyboards.categories(), ) await FSM.select_category.set() async def select_subcategory(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='%(name)s\n\n%(description)s\n\nВыберете подкатегорию.' % dict(data['category']), parse_mode='HTML', reply_markup=await keyboards.subcategories(data['category']), ) await FSM.select_subcategory.set() async def select_date(message: Message, state: FSMContext): data = await state.get_data() await message.answer_photo( photo=InputFile('./static/images/%d.%d.png' % ( data['subcategory'].category.id, data['subcategory'].id )), caption='%(name)s\n\n%(description)s\n\nВыберете дату.' % dict(data['subcategory']), parse_mode='HTML', reply_markup=keyboards.dates(data['free_to_order']), ) await FSM.select_date.set() async def select_time_range(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Выберете время.', parse_mode='HTML', reply_markup=keyboards.time_ranges(data['free_to_order'], data['date']), ) await FSM.select_time_range.set() async def input_email_address(message: Message, state: FSMContext): await message.answer( text='Введите адрес электронной почты для связи.', parse_mode='HTML', reply_markup=keyboards.back(), ) await FSM.input_email_address.set() async def input_phone_number(message: Message, state: FSMContext): await message.answer( text='Введите номер телефона для связи.', parse_mode='HTML', reply_markup=keyboards.back(), ) await FSM.input_phone_number.set() async def input_comment(message: Message, state: FSMContext): await message.answer( text='Опишите вашу проблему.', parse_mode='HTML', reply_markup=keyboards.back(), ) await FSM.input_comment.set() async def confirm_order(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Категория: %s - %s.\nДата: %s.\nВремя: %s.\nАдрес электронной почты: %s.\nНомер телефона: %s.\nОписание проблемы:\n%s' % ( data['category'].name, data['subcategory'].name, data['date'].strftime('%d.%m.%Y'), '%s - %s' % ( data['time_range'].start_time.strftime('%H:%M'), data['time_range'].end_time.strftime('%H:%M'), ), data['email_address'], data['phone_number'], data['comment'], ), parse_mode='HTML', reply_markup=keyboards.order_confirmation(), ) await FSM.confirm_order.set() async def success_sign_up(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Обращение %s успешно оформлено!\nВ указанное время с вами свяжется наш специалист.\nСпасибо за обращение!' % data['issue_key'], parse_mode='HTML', reply_markup=keyboards.main_menu(), ) await FSM.success_sign_up.set() async def select_order(message: Message, state: FSMContext): issues = await database.read_issues(message.from_user.id) if len(issues) > 0: await message.answer( text='Выберете обращение.', reply_markup=keyboards.issues(issues), ) return await FSM.select_order.set() await message.answer( text='У вас нет активных обращений.', reply_markup=keyboards.main_menu(), ) await FSM.no_orders.set() async def select_operation(message: Message, state: FSMContext): data = await state.get_data() issue = await api.read_issue(data['issue'].id) datetime_start = re.match(iso_datetime, issue.fields.customfield_10035) datetime_end = re.match(iso_datetime, issue.fields.customfield_10036) await message.answer( text='Категория: %s.\nДата: %s.\nВремя: %s.\nАдрес электронной почты: %s.\nНомер телефона: %s.\nОписание проблемы:\n%s' % ( issue.fields.customfield_10033, '%s.%s.%s' % ( datetime_start[3], datetime_start[2], datetime_start[1], ), '%s:%s - %s:%s' % ( datetime_start[4], datetime_start[5], datetime_end[4], datetime_end[5], ), issue.fields.customfield_10037, issue.fields.customfield_10038, issue.fields.customfield_10039, ), parse_mode='HTML', reply_markup=keyboards.operations(), ) await FSM.select_operation.set() async def reschedule_order_select_date(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Выберете дату.', parse_mode='HTML', reply_markup=keyboards.dates(data['free_to_order']), ) await FSM.reschedule_order_select_date.set() async def reschedule_order_select_time_range(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Выберете время.', parse_mode='HTML', reply_markup=keyboards.time_ranges(data['free_to_order'], data['date']), ) await FSM.reschedule_order_select_time_range.set() async def success_reschedule_order(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Обращение %s успешно изменено!\nВ указанное время с вами свяжется наш специалист.\nСпасибо за обращение!' % data['order'].id, parse_mode='HTML', reply_markup=keyboards.my_orders(), ) await FSM.success_reschedule_order.set() async def cancel_order(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Отменить обращение %s?' % data['issue'].key, parse_mode='HTML', reply_markup=keyboards.cancel_order(), ) await FSM.cancel_order.set() async def success_cancel_order(message: Message, state: FSMContext): data = await state.get_data() await message.answer( text='Обращение %s успешно отменено!' % data['issue'].key, parse_mode='HTML', reply_markup=keyboards.my_orders(), ) await FSM.success_cancel_order.set()