33
44import aiomax
55
6- from pathlib import Path
7-
8- from aiomax .buttons import CallbackButton , KeyboardBuilder
9-
10- from database .models import PLATFORM_MAX , STATUS_COMPLETED , is_owner
11- from database .queries import get_recent_transcriptions , get_transcription
12- from utils .s3 import download_text , object_name_from_url
6+ from database .models import PLATFORM_MAX
7+ from database .queries import get_recent_transcriptions
138from utils .utils import format_duration , MoscowTimezone
149from utils .tg import STATUS_EMOJI , fmt_price
1510from utils .sentry import sentry_bind_user_max , sentry_transaction
16- from messengers .max import safe_callback_answer , safe_send_document , safe_send_message
11+ from messengers .max import safe_send_message
1712
1813
1914@sentry_bind_user_max
@@ -36,7 +31,6 @@ async def handle_max_history(message: aiomax.Message, bot: aiomax.Bot) -> None:
3631 return
3732
3833 lines : list [str ] = []
39- doc_buttons : list [CallbackButton ] = []
4034 for r in items :
4135 status = r .status if isinstance (r .status , str ) else ""
4236 emoji = STATUS_EMOJI [status ] if status in STATUS_EMOJI else "•"
@@ -47,51 +41,11 @@ async def handle_max_history(message: aiomax.Message, bot: aiomax.Bot) -> None:
4741 dur = format_duration (r .duration_seconds )
4842 price_for_user = fmt_price (r .price_for_user )
4943 lines .append (f"{ emoji } { dt_str } МСК • { dur } • { price_for_user } " )
50- if status == STATUS_COMPLETED and r .result_s3_path :
51- doc_buttons .append (CallbackButton (f"📄 { dt_str } • { dur } " , f"history_doc:{ r .id } " ))
5244
5345 msg = (
5446 "Последние 10 распознаваний:\n "
5547 + "\n " .join (lines )
5648 + "\n \n Статусы: 🕓 ожидание • ⏳ в работе • ✅ готово • ❌ ошибка • 🚫 отменено"
5749 )
5850
59- keyboard = None
60- if doc_buttons :
61- msg += "\n \n Готовые тексты можно получить ещё раз:"
62- keyboard = KeyboardBuilder ()
63- for btn in doc_buttons :
64- keyboard = keyboard .row (btn )
65-
66- await safe_send_message (bot , msg , chat_id = message .recipient .chat_id , keyboard = keyboard )
67-
68-
69- @sentry_bind_user_max
70- @sentry_transaction (name = "history.document" , op = "max.callback" )
71- async def handle_max_history_doc (callback : aiomax .Callback , bot : aiomax .Bot ) -> None :
72- """Re-send a finished transcription document from S3."""
73- await safe_callback_answer (callback , notification = "" )
74-
75- try :
76- transcription_id = int (callback .payload .split (":" , 1 )[1 ])
77- user_id = int (callback .user .user_id )
78- except (IndexError , ValueError , TypeError , AttributeError ):
79- return
80-
81- transcription = get_transcription (transcription_id )
82- if not is_owner (transcription , user_id , PLATFORM_MAX ):
83- return
84- if not transcription .result_s3_path :
85- return
86-
87- object_name = object_name_from_url (transcription .result_s3_path )
88- text = await download_text (object_name )
89- if not text :
90- await safe_send_message (bot ,
91- "❌ Не удалось получить текст\n \n "
92- "Попробуйте ещё раз чуть позже" ,
93- chat_id = callback .message .recipient .chat_id ,
94- )
95- return
96-
97- await safe_send_document (bot , user_id , text .encode ("utf-8" ), Path (object_name ).name , "" )
51+ await safe_send_message (bot , msg , chat_id = message .recipient .chat_id )
0 commit comments