@@ -13,12 +13,13 @@ def get_media_label(msg) -> str:
1313 msg.message but the media stays in msg.media).
1414 """
1515 try :
16- # Веб-превью ссылки — НЕ вложение. Проверяем ПЕРВЫМ: у сообщения со
17- # ссылкой Telethon отдаёт картинку превью через msg.photo, иначе она
18- # ложно пометилась бы как "photo".
16+ # Link web preview is NOT an attachment. Check it FIRST: for a message with a
17+ # link, Telethon returns the preview image via msg.photo; otherwise it would
18+ # be incorrectly classified as a "photo".
1919 if getattr (msg , "web_preview" , None ) is not None :
2020 return ""
21- # Стикер/голос/видео/аудио/гиф — это тоже document, проверяем РАНЬШЕ document.
21+ # Sticker/voice/video/audio/GIF are also represented as documents, so check
22+ # them BEFORE the generic document handler.
2223 sticker = getattr (msg , "sticker" , None )
2324 if sticker is not None :
2425 alt = ""
@@ -60,10 +61,10 @@ def get_media_label(msg) -> str:
6061
6162
6263def _inline_button_texts (msg ):
63- """Тексты inline-кнопок сообщения (плоским списком ), [] если нет ."""
64+ """Inline button texts of the message (flat list ), [] if none ."""
6465 out = []
6566 try :
66- for row in ( getattr (msg , "buttons" , None ) or []) :
67+ for row in getattr (msg , "buttons" , None ) or []:
6768 for b in row :
6869 t = getattr (b , "text" , None )
6970 if t :
@@ -74,10 +75,10 @@ def _inline_button_texts(msg):
7475
7576
7677def _link_urls (msg ):
77- """Явные URL из entities (скрытые за текстом ссылки ), [] если нет ."""
78+ """Explicit URLs from entities (links hidden behind text ), [] if none ."""
7879 out = []
7980 try :
80- for e in ( getattr (msg , "entities" , None ) or []) :
81+ for e in getattr (msg , "entities" , None ) or []:
8182 u = getattr (e , "url" , None )
8283 if u :
8384 out .append (u )
@@ -87,11 +88,12 @@ def _link_urls(msg):
8788
8889
8990def message_to_dict (msg ) -> dict :
90- """API-полный, но компактный вид сообщения Telethon (пустые поля опускаем ).
91+ """API-complete but compact Telethon message view (omit empty fields ).
9192
92- Цель — чтобы вывод MCP по полноте соответствовал объекту API, а не терял
93- данные (медиа, альбомы, пересылки, правки, кнопки, реакции и т.п.).
94- Все эти поля уже приходят в объекте сообщения тем же запросом get_messages.
93+ The goal is for the MCP output to match the API object in completeness, rather
94+ than losing data such as media, albums, forwards, edits, buttons, reactions,
95+ and so on. All these fields are already present in the message object returned
96+ by the same get_messages request.
9597 """
9698 d = {"id" : msg .id , "sender" : get_sender_name (msg ), "date" : msg .date }
9799
@@ -111,9 +113,11 @@ def message_to_dict(msg) -> dict:
111113
112114 grouped_id = getattr (msg , "grouped_id" , None )
113115 if grouped_id :
114- d ["grouped_id" ] = grouped_id # альбом: сообщения с одним grouped_id — одна группа
116+ d ["grouped_id" ] = grouped_id # album: messages sharing one grouped_id form a single group
115117
116- reply_to_id = getattr (msg .reply_to , "reply_to_msg_id" , None ) if getattr (msg , "reply_to" , None ) else None
118+ reply_to_id = (
119+ getattr (msg .reply_to , "reply_to_msg_id" , None ) if getattr (msg , "reply_to" , None ) else None
120+ )
117121 if reply_to_id :
118122 d ["reply_to" ] = reply_to_id
119123
@@ -159,7 +163,7 @@ def message_to_dict(msg) -> dict:
159163
160164 action = getattr (msg , "action" , None )
161165 if action is not None :
162- d ["action" ] = type (action ).__name__ # сервисное сообщение (вступил/закрепил /…)
166+ d ["action" ] = type (action ).__name__ # service message (joined/pinned /…)
163167
164168 ttl = getattr (msg , "ttl_period" , None )
165169 if ttl :
@@ -169,10 +173,12 @@ def message_to_dict(msg) -> dict:
169173
170174
171175def format_message_line (msg ) -> str :
172- """Однострочный человекочитаемый вид сообщения со ВСЕМИ ключевыми флагами ."""
176+ """Single-line human-readable message representation with ALL key flags ."""
173177 parts = [f"ID: { msg .id } " , get_sender_name (msg ), f"Date: { msg .date } " ]
174178
175- reply_to_id = getattr (msg .reply_to , "reply_to_msg_id" , None ) if getattr (msg , "reply_to" , None ) else None
179+ reply_to_id = (
180+ getattr (msg .reply_to , "reply_to_msg_id" , None ) if getattr (msg , "reply_to" , None ) else None
181+ )
176182 if reply_to_id :
177183 parts .append (f"reply to { reply_to_id } " )
178184
0 commit comments