Skip to content

Commit c606f83

Browse files
committed
Remove as_copy from forward_messages (superseded by copy_message)
1 parent 7325daf commit c606f83

2 files changed

Lines changed: 30 additions & 169 deletions

File tree

pyrogram/methods/messages/forward_messages.py

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ async def forward_messages(
3030
from_chat_id: Union[int, str],
3131
message_ids: Union[int, Iterable[int]],
3232
disable_notification: bool = None,
33-
as_copy: bool = False,
34-
remove_caption: bool = False,
3533
schedule_date: int = None
3634
) -> List["types.Message"]:
3735
"""Forward messages of any kind.
@@ -47,24 +45,14 @@ async def forward_messages(
4745
For your personal cloud (Saved Messages) you can simply use "me" or "self".
4846
For a contact that exists in your Telegram address book you can use his phone number (str).
4947
50-
message_ids (``iterable``):
48+
message_ids (``int`` | List of ``int``):
5149
A list of Message identifiers in the chat specified in *from_chat_id* or a single message id.
5250
Iterators and Generators are also accepted.
5351
5452
disable_notification (``bool``, *optional*):
5553
Sends the message silently.
5654
Users will receive a notification with no sound.
5755
58-
as_copy (``bool``, *optional*):
59-
Pass True to forward messages without the forward header (i.e.: send a copy of the message content so
60-
that it appears as originally sent by you).
61-
Defaults to False.
62-
63-
remove_caption (``bool``, *optional*):
64-
If set to True and *as_copy* is enabled as well, media captions are not preserved when copying the
65-
message. Has no effect if *as_copy* is not enabled.
66-
Defaults to False.
67-
6856
schedule_date (``int``, *optional*):
6957
Date when the message will be automatically sent. Unix time.
7058
@@ -90,50 +78,31 @@ async def forward_messages(
9078
is_iterable = not isinstance(message_ids, int)
9179
message_ids = list(message_ids) if is_iterable else [message_ids]
9280

93-
if as_copy:
94-
forwarded_messages = []
95-
96-
for chunk in [message_ids[i:i + 200] for i in range(0, len(message_ids), 200)]:
97-
messages = await self.get_messages(chat_id=from_chat_id, message_ids=chunk)
98-
99-
for message in messages:
100-
forwarded_messages.append(
101-
await message.forward(
102-
chat_id,
103-
disable_notification=disable_notification,
104-
as_copy=True,
105-
remove_caption=remove_caption,
106-
schedule_date=schedule_date
107-
)
108-
)
109-
110-
return types.List(forwarded_messages) if is_iterable else forwarded_messages[0]
111-
else:
112-
r = await self.send(
113-
raw.functions.messages.ForwardMessages(
114-
to_peer=await self.resolve_peer(chat_id),
115-
from_peer=await self.resolve_peer(from_chat_id),
116-
id=message_ids,
117-
silent=disable_notification or None,
118-
random_id=[self.rnd_id() for _ in message_ids],
119-
schedule_date=schedule_date
120-
)
81+
r = await self.send(
82+
raw.functions.messages.ForwardMessages(
83+
to_peer=await self.resolve_peer(chat_id),
84+
from_peer=await self.resolve_peer(from_chat_id),
85+
id=message_ids,
86+
silent=disable_notification or None,
87+
random_id=[self.rnd_id() for _ in message_ids],
88+
schedule_date=schedule_date
12189
)
90+
)
12291

123-
forwarded_messages = []
92+
forwarded_messages = []
12493

125-
users = {i.id: i for i in r.users}
126-
chats = {i.id: i for i in r.chats}
94+
users = {i.id: i for i in r.users}
95+
chats = {i.id: i for i in r.chats}
12796

128-
for i in r.updates:
129-
if isinstance(i, (raw.types.UpdateNewMessage,
130-
raw.types.UpdateNewChannelMessage,
131-
raw.types.UpdateNewScheduledMessage)):
132-
forwarded_messages.append(
133-
await types.Message._parse(
134-
self, i.message,
135-
users, chats
136-
)
97+
for i in r.updates:
98+
if isinstance(i, (raw.types.UpdateNewMessage,
99+
raw.types.UpdateNewChannelMessage,
100+
raw.types.UpdateNewScheduledMessage)):
101+
forwarded_messages.append(
102+
await types.Message._parse(
103+
self, i.message,
104+
users, chats
137105
)
106+
)
138107

139-
return types.List(forwarded_messages) if is_iterable else forwarded_messages[0]
108+
return types.List(forwarded_messages) if is_iterable else forwarded_messages[0]

pyrogram/types/messages_and_media/message.py

Lines changed: 7 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20-
from functools import partial
2120
from typing import List, Match, Union, BinaryIO
2221

2322
import pyrogram
@@ -2706,8 +2705,6 @@ async def forward(
27062705
self,
27072706
chat_id: int or str,
27082707
disable_notification: bool = None,
2709-
as_copy: bool = False,
2710-
remove_caption: bool = False,
27112708
schedule_date: int = None
27122709
) -> Union["types.Message", List["types.Message"]]:
27132710
"""Bound method *forward* of :obj:`~pyrogram.types.Message`.
@@ -2737,15 +2734,6 @@ async def forward(
27372734
Sends the message silently.
27382735
Users will receive a notification with no sound.
27392736
2740-
as_copy (``bool``, *optional*):
2741-
Pass True to forward messages without the forward header (i.e.: send a copy of the message content).
2742-
Defaults to False.
2743-
2744-
remove_caption (``bool``, *optional*):
2745-
If set to True and *as_copy* is enabled as well, media captions are not preserved when copying the
2746-
message. Has no effect if *as_copy* is not enabled.
2747-
Defaults to False.
2748-
27492737
schedule_date (``int``, *optional*):
27502738
Date when the message will be automatically sent. Unix time.
27512739
@@ -2755,109 +2743,13 @@ async def forward(
27552743
Raises:
27562744
RPCError: In case of a Telegram RPC error.
27572745
"""
2758-
if as_copy:
2759-
if self.service:
2760-
log.warning(f"Service messages cannot be copied. "
2761-
f"chat_id: {self.chat.id}, message_id: {self.message_id}")
2762-
elif self.game and not await self._client.storage.is_bot():
2763-
log.warning(f"Users cannot send messages with Game media type. "
2764-
f"chat_id: {self.chat.id}, message_id: {self.message_id}")
2765-
elif self.text:
2766-
return await self._client.send_message(
2767-
chat_id,
2768-
text=self.text.html,
2769-
parse_mode="html",
2770-
disable_web_page_preview=not self.web_page,
2771-
disable_notification=disable_notification,
2772-
schedule_date=schedule_date
2773-
)
2774-
elif self.media:
2775-
caption = self.caption.html if self.caption and not remove_caption else ""
2776-
2777-
send_media = partial(
2778-
self._client.send_cached_media,
2779-
chat_id=chat_id,
2780-
disable_notification=disable_notification,
2781-
schedule_date=schedule_date
2782-
)
2783-
2784-
if self.photo:
2785-
file_id = self.photo.file_id
2786-
elif self.audio:
2787-
file_id = self.audio.file_id
2788-
elif self.document:
2789-
file_id = self.document.file_id
2790-
elif self.video:
2791-
file_id = self.video.file_id
2792-
elif self.animation:
2793-
file_id = self.animation.file_id
2794-
elif self.voice:
2795-
file_id = self.voice.file_id
2796-
elif self.sticker:
2797-
file_id = self.sticker.file_id
2798-
elif self.video_note:
2799-
file_id = self.video_note.file_id
2800-
elif self.contact:
2801-
return await self._client.send_contact(
2802-
chat_id,
2803-
phone_number=self.contact.phone_number,
2804-
first_name=self.contact.first_name,
2805-
last_name=self.contact.last_name,
2806-
vcard=self.contact.vcard,
2807-
disable_notification=disable_notification,
2808-
schedule_date=schedule_date
2809-
)
2810-
elif self.location:
2811-
return await self._client.send_location(
2812-
chat_id,
2813-
latitude=self.location.latitude,
2814-
longitude=self.location.longitude,
2815-
disable_notification=disable_notification,
2816-
schedule_date=schedule_date
2817-
)
2818-
elif self.venue:
2819-
return await self._client.send_venue(
2820-
chat_id,
2821-
latitude=self.venue.location.latitude,
2822-
longitude=self.venue.location.longitude,
2823-
title=self.venue.title,
2824-
address=self.venue.address,
2825-
foursquare_id=self.venue.foursquare_id,
2826-
foursquare_type=self.venue.foursquare_type,
2827-
disable_notification=disable_notification,
2828-
schedule_date=schedule_date
2829-
)
2830-
elif self.poll:
2831-
return await self._client.send_poll(
2832-
chat_id,
2833-
question=self.poll.question,
2834-
options=[opt.text for opt in self.poll.options],
2835-
disable_notification=disable_notification,
2836-
schedule_date=schedule_date
2837-
)
2838-
elif self.game:
2839-
return await self._client.send_game(
2840-
chat_id,
2841-
game_short_name=self.game.short_name,
2842-
disable_notification=disable_notification
2843-
)
2844-
else:
2845-
raise ValueError("Unknown media type")
2846-
2847-
if self.sticker or self.video_note: # Sticker and VideoNote should have no caption
2848-
return await send_media(file_id=file_id)
2849-
else:
2850-
return await send_media(file_id=file_id, caption=caption, parse_mode="html")
2851-
else:
2852-
raise ValueError("Can't copy this message")
2853-
else:
2854-
return await self._client.forward_messages(
2855-
chat_id=chat_id,
2856-
from_chat_id=self.chat.id,
2857-
message_ids=self.message_id,
2858-
disable_notification=disable_notification,
2859-
schedule_date=schedule_date
2860-
)
2746+
return await self._client.forward_messages(
2747+
chat_id=chat_id,
2748+
from_chat_id=self.chat.id,
2749+
message_ids=self.message_id,
2750+
disable_notification=disable_notification,
2751+
schedule_date=schedule_date
2752+
)
28612753

28622754
async def delete(self, revoke: bool = True):
28632755
"""Bound method *delete* of :obj:`~pyrogram.types.Message`.

0 commit comments

Comments
 (0)