async def stop_activity(message: types.Message, state: FSMContext): activity, activity_type = await activities.stop_activity(message.from_user.id, message.chat.id) # Останавливаем занятие total_today = await stats.get_today_total_activity_duration( user_id=message.from_user.id, chat_id=message.chat.id, activity_type_id=activity.activity_type, subactivity_id=activity.subactivity ) dict_total = td_to_dict(total_today) # Получаем текст сообщения и форматируем с названием занятия и продолжительностью text = messages.STOPPED_ACTIVITY.format( activity_type_name=activity_type.name, **td_to_dict(activity.duration), total_hours=dict_total['hours'], total_minutes=dict_total['minutes'], total_seconds=dict_total['seconds'] ) await update_state_and_send(message, state, state=States.MAIN_MENU, text=text)
async def status(message: types.Message, state: FSMContext): # Получаем активное занятие пользователя и его продолжительность activity_type, duration = await user.get_user_active_activity(message.from_user.id, message.chat.id) # Получаем текст сообщения и форматируем с названием занятия и продолжительностью text = messages.STATUS.format( activity_type_name=activity_type.name, **td_to_dict(duration) ) await update_state_and_send(message, state, text=text)
async def get_current_subactivity_text(message: types.Message, state: FSMContext) -> str: data = await state.get_data() # Получаем данные пользователя spent_time = await stats.get_total_user_spent_time_subactivity( user_id=message.from_user.id, chat_id=message.chat.id, subactivity_id=data.get('subactivity_id')) return messages.CURRENT_SUBACTIVITY.format( activity_type_name=data.get('current_activity_type_name'), subactivity_name=message.text, **td_to_dict(spent_time))
async def get_current_activity_text(message: types.Message, state: FSMContext) -> str: data = await state.get_data() # Получаем данные пользователя spent_time = await stats.get_total_user_spent_time( user_id=message.from_user.id, chat_id=message.chat.id, activity_type_id=data.get('current_activity_type_id')) return messages.CURRENT_ACTIVITY.format( activity_type_name=data.get('current_activity_type_name'), with_benefit='Да' if data.get('current_activity_type_with_benefit') else 'Нет', **td_to_dict(spent_time))
async def entered_penalty(message: types.Message, state: FSMContext): if message.text.isdigit(): delta = timedelta(minutes=int(message.text)) try: activity, activity_type = await activities.stop_activity(message.from_user.id, message.chat.id, delta=delta) # Останавливаем занятие except Exception as e: await update_state_and_send(message, state, text=messages.PENALTY_ERROR) return text = messages.STOPPED_ACTIVITY.format( activity_type_name=activity_type.name, **td_to_dict(activity.duration) ) await update_state_and_send(message, state, state=States.MAIN_MENU, text=text)