Skip to content

Commit

Permalink
Add BC parameters to remaining methods
Browse files Browse the repository at this point in the history
Follow-Up: fb118f9
  • Loading branch information
SpEcHiDe committed Apr 20, 2024
1 parent 511702d commit 848bc86
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 86 deletions.
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Welcome to Pyrogram
.. admonition :: A Word of Warning
:class: tip
We merge changes made to few of pyrogram forks plus changes made by us to this repository. All the features are just customized feature mostly for personal use; there is no guarantee in them being stable, __USE AT YOUR OWN RISK__.
We merge changes made to few of pyrogram forks plus changes made by us to this repository. All the features are just customized feature mostly for personal use; there is no guarantee in them being stable, **USE AT YOUR OWN RISK**.
.. raw:: html
Expand Down
18 changes: 16 additions & 2 deletions pyrogram/methods/bots/send_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ async def send_game(
"types.ReplyKeyboardMarkup",
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None
] = None,
reply_to_message_id: int = None
) -> "types.Message":
"""Send a game.
Expand Down Expand Up @@ -81,7 +82,20 @@ async def send_game(
await app.send_game(chat_id, "gamename")
"""

reply_to = await utils.get_reply_head_fm(
if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
21 changes: 19 additions & 2 deletions pyrogram/methods/bots/send_inline_bot_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from typing import Union

import pyrogram
from pyrogram import raw, utils, types

log = logging.getLogger(__name__)


class SendInlineBotResult:
async def send_inline_bot_result(
Expand All @@ -30,7 +33,8 @@ async def send_inline_bot_result(
result_id: str,
disable_notification: bool = None,
reply_parameters: "types.ReplyParameters" = None,
message_thread_id: int = None
message_thread_id: int = None,
reply_to_message_id: int = None
) -> "raw.base.Updates":
"""Send an inline bot result.
Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results`
Expand Down Expand Up @@ -68,7 +72,20 @@ async def send_inline_bot_result(
await app.send_inline_bot_result(chat_id, query_id, result_id)
"""

reply_to = await utils.get_reply_head_fm(
if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
19 changes: 18 additions & 1 deletion pyrogram/methods/messages/copy_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from datetime import datetime
from typing import Union, List

import pyrogram
from pyrogram import types, utils, raw

log = logging.getLogger(__name__)


class CopyMediaGroup:
async def copy_media_group(
Expand All @@ -34,6 +37,7 @@ async def copy_media_group(
reply_parameters: "types.ReplyParameters" = None,
message_thread_id: int = None,
schedule_date: datetime = None,
reply_to_message_id: int = None
) -> List["types.Message"]:
"""Copy a media group by providing one of the message ids.
Expand Down Expand Up @@ -90,6 +94,19 @@ async def copy_media_group(
captions=["caption 1", None, ""])
"""

if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

media_group = await self.get_media_group(from_chat_id, message_id)
multi_media = []

Expand Down Expand Up @@ -118,7 +135,7 @@ async def copy_media_group(
)
)

reply_to = await utils.get_reply_head_fm(
reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
17 changes: 16 additions & 1 deletion pyrogram/methods/messages/copy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async def copy_message(
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None,
schedule_date: datetime = None
schedule_date: datetime = None,
reply_to_message_id: int = None
) -> "types.Message":
"""Copy messages of any kind.
Expand Down Expand Up @@ -102,6 +103,20 @@ async def copy_message(
await app.copy_message(to_chat, from_chat, 123)
"""

if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

message: types.Message = await self.get_messages(
chat_id=from_chat_id,
message_ids=message_id
Expand Down
25 changes: 20 additions & 5 deletions pyrogram/methods/messages/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
import os
import re
from datetime import datetime
from typing import Union, BinaryIO, List, Optional, Callable

import pyrogram
from pyrogram import StopTransmission, enums
from pyrogram import raw
from pyrogram import types
from pyrogram import utils
from pyrogram import StopTransmission, enums, raw, types, utils
from pyrogram.errors import FilePartMissing
from pyrogram.file_id import FileType
from .inline_session import get_session

log = logging.getLogger(__name__)


class SendAnimation:
async def send_animation(
Expand Down Expand Up @@ -59,6 +59,7 @@ async def send_animation(
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None,
reply_to_message_id: int = None,
progress: Callable = None,
progress_args: tuple = ()
) -> Optional["types.Message"]:
Expand Down Expand Up @@ -191,6 +192,20 @@ async def progress(current, total):
# Send self-destructing animation message
await app.send_animation("me", "animation.gif", ttl_seconds=10)
"""

if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

file = None

try:
Expand Down Expand Up @@ -248,7 +263,7 @@ async def progress(current, total):
ttl_seconds=ttl_seconds
)

reply_to = await utils.get_reply_head_fm(
reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
17 changes: 16 additions & 1 deletion pyrogram/methods/messages/send_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async def send_audio(
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None,
reply_to_message_id: int = None,
progress: Callable = None,
progress_args: tuple = ()
) -> Optional["types.Message"]:
Expand Down Expand Up @@ -176,6 +177,20 @@ async def progress(current, total):
await app.send_audio("me", "audio.mp3", progress=progress)
"""

if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

file = None

try:
Expand Down Expand Up @@ -221,7 +236,7 @@ async def progress(current, total):
]
)

reply_to = await utils.get_reply_head_fm(
reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
25 changes: 20 additions & 5 deletions pyrogram/methods/messages/send_cached_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from datetime import datetime
from typing import Union, List, Optional

import pyrogram
from pyrogram import raw, enums
from pyrogram import types
from pyrogram import utils
from pyrogram import raw, enums, types, utils

log = logging.getLogger(__name__)


class SendCachedMedia:
Expand All @@ -45,7 +46,8 @@ async def send_cached_media(
"types.ReplyKeyboardMarkup",
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None
] = None,
reply_to_message_id: int = None
) -> Optional["types.Message"]:
"""Send any media stored on the Telegram servers using a file_id.
Expand Down Expand Up @@ -110,7 +112,20 @@ async def send_cached_media(
await app.send_cached_media("me", file_id)
"""

reply_to = await utils.get_reply_head_fm(
if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
24 changes: 20 additions & 4 deletions pyrogram/methods/messages/send_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from datetime import datetime
from typing import Union

import pyrogram
from pyrogram import raw, utils
from pyrogram import types
from pyrogram import raw, utils, types

log = logging.getLogger(__name__)


class SendContact:
Expand All @@ -43,7 +45,8 @@ async def send_contact(
"types.ReplyKeyboardMarkup",
"types.ReplyKeyboardRemove",
"types.ForceReply"
] = None
] = None,
reply_to_message_id: int = None
) -> "types.Message":
"""Send phone contacts.
Expand Down Expand Up @@ -99,7 +102,20 @@ async def send_contact(
await app.send_contact("me", "+1-123-456-7890", "Name")
"""

reply_to = await utils.get_reply_head_fm(
if reply_to_message_id and reply_parameters:
raise ValueError(
"Parameters `reply_to_message_id` and `reply_parameters` are mutually "
"exclusive."
)

if reply_to_message_id is not None:
log.warning(
"This property is deprecated. "
"Please use reply_parameters instead"
)
reply_parameters = types.ReplyParameters(message_id=reply_to_message_id)

reply_to = await utils._get_reply_message_parameters(
self,
message_thread_id,
reply_parameters
Expand Down
Loading

0 comments on commit 848bc86

Please sign in to comment.