|
16 | 16 | # You should have received a copy of the GNU Lesser General Public License |
17 | 17 | # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
|
19 | | -import logging |
20 | 19 | import os |
21 | 20 | import re |
22 | 21 | from datetime import datetime |
23 | 22 | from typing import BinaryIO, Callable, List, Optional, Union |
24 | 23 |
|
25 | 24 | import pyrogram |
26 | 25 | from pyrogram import StopTransmission, enums, raw, types, utils |
27 | | -from pyrogram.errors import FilePartMissing |
28 | 26 | from pyrogram.file_id import FileType |
| 27 | +from pyrogram.utils import handle_deprecated_reply_parameters, send_media |
29 | 28 |
|
30 | | -log = logging.getLogger(__name__) |
31 | 29 |
|
32 | 30 | class SendAnimation: |
33 | 31 | async def send_animation( |
@@ -217,55 +215,16 @@ async def progress(current, total): |
217 | 215 |
|
218 | 216 | await app.send_animation("me", "animation.gif", progress=progress) |
219 | 217 | """ |
220 | | - if any( |
221 | | - ( |
222 | | - reply_to_message_id is not None, |
223 | | - reply_to_chat_id is not None, |
224 | | - reply_to_story_id is not None, |
225 | | - quote_text is not None, |
226 | | - quote_entities is not None, |
227 | | - quote_offset is not None, |
228 | | - ) |
229 | | - ): |
230 | | - if reply_to_message_id is not None: |
231 | | - log.warning( |
232 | | - "`reply_to_message_id` is deprecated and will be removed in future updates. Use `reply_parameters` instead." |
233 | | - ) |
234 | | - |
235 | | - if reply_to_chat_id is not None: |
236 | | - log.warning( |
237 | | - "`reply_to_chat_id` is deprecated and will be removed in future updates. Use `reply_parameters` instead." |
238 | | - ) |
239 | | - |
240 | | - if reply_to_story_id is not None: |
241 | | - log.warning( |
242 | | - "`reply_to_story_id` is deprecated and will be removed in future updates. Use `reply_parameters` instead." |
243 | | - ) |
244 | | - |
245 | | - if quote_text is not None: |
246 | | - log.warning( |
247 | | - "`quote_text` is deprecated and will be removed in future updates. Use `reply_parameters` instead." |
248 | | - ) |
249 | | - |
250 | | - if quote_entities is not None: |
251 | | - log.warning( |
252 | | - "`quote_entities` is deprecated and will be removed in future updates. Use `reply_parameters` instead." |
253 | | - ) |
254 | | - |
255 | | - if quote_offset is not None: |
256 | | - log.warning( |
257 | | - "`quote_offset` is deprecated and will be removed in future updates. Use `reply_parameters` instead." |
258 | | - ) |
259 | | - |
260 | | - reply_parameters = types.ReplyParameters( |
261 | | - message_id=reply_to_message_id, |
262 | | - chat_id=reply_to_chat_id, |
263 | | - story_id=reply_to_story_id, |
264 | | - quote=quote_text, |
265 | | - quote_parse_mode=parse_mode, |
266 | | - quote_entities=quote_entities, |
267 | | - quote_position=quote_offset |
268 | | - ) |
| 218 | + reply_parameters = handle_deprecated_reply_parameters( |
| 219 | + reply_to_message_id=reply_to_message_id, |
| 220 | + reply_to_chat_id=reply_to_chat_id, |
| 221 | + reply_to_story_id=reply_to_story_id, |
| 222 | + quote_text=quote_text, |
| 223 | + quote_entities=quote_entities, |
| 224 | + quote_offset=quote_offset, |
| 225 | + parse_mode=parse_mode, |
| 226 | + reply_parameters=reply_parameters |
| 227 | + ) |
269 | 228 |
|
270 | 229 | file = None |
271 | 230 |
|
@@ -317,58 +276,39 @@ async def progress(current, total): |
317 | 276 | ] |
318 | 277 | ) |
319 | 278 |
|
320 | | - while True: |
321 | | - try: |
322 | | - peer = await self.resolve_peer(chat_id) |
323 | | - r = await self.invoke( |
324 | | - raw.functions.messages.SendMedia( |
325 | | - peer=peer, |
326 | | - media=media, |
327 | | - silent=disable_notification or None, |
328 | | - invert_media=show_caption_above_media, |
329 | | - reply_to=await utils.get_reply_to( |
330 | | - self, |
331 | | - reply_parameters, |
332 | | - message_thread_id, |
333 | | - direct_messages_topic_id |
334 | | - ), |
335 | | - random_id=self.rnd_id(), |
336 | | - schedule_date=utils.datetime_to_timestamp(schedule_date), |
337 | | - noforwards=protect_content, |
338 | | - allow_paid_floodskip=allow_paid_broadcast, |
339 | | - reply_markup=await reply_markup.write(self) if reply_markup else None, |
340 | | - effect=effect_id, |
341 | | - allow_paid_stars=paid_message_star_count, |
342 | | - suggested_post=suggested_post_parameters.write() if suggested_post_parameters else None, |
343 | | - **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) |
344 | | - ), |
345 | | - business_connection_id=business_connection_id |
346 | | - ) |
347 | | - except FilePartMissing as e: |
348 | | - await self.save_file(animation, file_id=file.id, file_part=e.value) |
349 | | - else: |
350 | | - for i in r.updates: |
351 | | - if isinstance(i, (raw.types.UpdateNewMessage, |
352 | | - raw.types.UpdateNewChannelMessage, |
353 | | - raw.types.UpdateNewScheduledMessage, |
354 | | - raw.types.UpdateBotNewBusinessMessage)): |
355 | | - message = await types.Message._parse( |
356 | | - self, i.message, |
357 | | - {i.id: i for i in r.users}, |
358 | | - {i.id: i for i in r.chats}, |
359 | | - is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage), |
360 | | - business_connection_id=getattr(i, "connection_id", None), |
361 | | - ) |
362 | | - |
363 | | - if unsave and message.animation: |
364 | | - document_id = utils.get_input_media_from_file_id( |
365 | | - message.animation.file_id, |
366 | | - FileType.ANIMATION, |
367 | | - ).id |
368 | | - |
369 | | - await self.invoke(raw.functions.messages.SaveGif(id=document_id, unsave=True)) # type: ignore[arg-type] |
370 | | - |
371 | | - return message |
372 | | - |
| 279 | + # Функция для обработки unsave после отправки |
| 280 | + async def post_process(client, message): |
| 281 | + if unsave and message.animation: |
| 282 | + document_id = utils.get_input_media_from_file_id( |
| 283 | + message.animation.file_id, |
| 284 | + FileType.ANIMATION, |
| 285 | + ).id |
| 286 | + await client.invoke(raw.functions.messages.SaveGif(id=document_id, unsave=True)) |
| 287 | + |
| 288 | + return await send_media( |
| 289 | + client=self, |
| 290 | + chat_id=chat_id, |
| 291 | + media=media, |
| 292 | + caption=caption, |
| 293 | + parse_mode=parse_mode, |
| 294 | + caption_entities=caption_entities, |
| 295 | + disable_notification=disable_notification, |
| 296 | + message_thread_id=message_thread_id, |
| 297 | + direct_messages_topic_id=direct_messages_topic_id, |
| 298 | + effect_id=effect_id, |
| 299 | + show_caption_above_media=show_caption_above_media, |
| 300 | + reply_parameters=reply_parameters, |
| 301 | + schedule_date=schedule_date, |
| 302 | + protect_content=protect_content, |
| 303 | + business_connection_id=business_connection_id, |
| 304 | + allow_paid_broadcast=allow_paid_broadcast, |
| 305 | + paid_message_star_count=paid_message_star_count, |
| 306 | + suggested_post_parameters=suggested_post_parameters, |
| 307 | + reply_markup=reply_markup, |
| 308 | + file_reference=animation, |
| 309 | + file_part_callback=lambda ref, part: self.save_file(ref, file_id=file.id, file_part=part), |
| 310 | + use_parse_messages=False, # Используем ручной парсинг для совместимости с unsave |
| 311 | + post_process_callback=post_process if unsave else None, |
| 312 | + ) |
373 | 313 | except StopTransmission: |
374 | 314 | return None |
0 commit comments