Skip to content

Commit

Permalink
Fix documentation mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Jul 16, 2024
1 parent b6605d2 commit 39fe826
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/releases/changes-in-this-fork.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If you found any issue or have any suggestions, feel free to make `an issue <htt
+------------------------+

- Updated the parameter ``business_connection_id`` to the methods :meth:`~pyrogram.types.Message.edit_text`, :meth:`~pyrogram.types.Message.edit_media`, :meth:`~pyrogram.types.Message.edit_reply_markup`, :meth:`~pyrogram.types.CallbackQuery.edit_message_text`, :meth:`~pyrogram.types.CallbackQuery.edit_message_media`, :meth:`~pyrogram.types.CallbackQuery.edit_message_reply_markup`.
- Added the parameter ``business_connection_id`` to the methods :meth:`~pyrogram.Client.edit_message_text`, :meth:`~pyrogram.Client.edit_message_media`, :meth:`~pyrogram.Client.edit_message_caption` and :meth:`~pyrogram.Client.edit_message_reply_markup`, allowing the bot to edit business messages.
- Added the parameter ``business_connection_id`` to the methods :meth:`~pyrogram.Client.edit_message_text`, :meth:`~pyrogram.Client.edit_message_media`, :meth:`~pyrogram.Client.edit_cached_media`, :meth:`~pyrogram.Client.edit_message_caption` and :meth:`~pyrogram.Client.edit_message_reply_markup`, allowing the bot to edit business messages.
- Added the parameter ``business_connection_id`` to the method :meth:`~pyrogram.Client.stop_poll`, allowing the bot to stop polls it sent on behalf of a business account.
- Added support for callback queries originating from a message sent on behalf of a business account.

Expand Down
44 changes: 42 additions & 2 deletions pyrogram/methods/messages/edit_cached_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import pyrogram
from pyrogram import raw, enums, types, utils

from .inline_session import get_session

log = logging.getLogger(__name__)


Expand All @@ -38,7 +40,8 @@ async def edit_cached_media(
show_caption_above_media: bool = None,
schedule_date: datetime = None,
has_spoiler: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None
reply_markup: "types.InlineKeyboardMarkup" = None,
business_connection_id: str = None
) -> Optional["types.Message"]:
"""Edit a media stored on the Telegram servers using a file_id.
Expand Down Expand Up @@ -83,6 +86,9 @@ async def edit_cached_media(
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
business_connection_id (``str``, *optional*):
Unique identifier of the business connection on behalf of which the message to be edited was sent
Returns:
:obj:`~pyrogram.types.Message`: On success, the edited media message is returned.
Expand All @@ -101,7 +107,26 @@ async def edit_cached_media(
invert_media=show_caption_above_media,
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
)
r = await self.invoke(rpc)
session = None
business_connection = None
if business_connection_id:
business_connection = self.business_user_connection_cache[business_connection_id]
if not business_connection:
business_connection = await self.get_business_connection(business_connection_id)
session = await get_session(
self,
business_connection._raw.connection.dc_id
)
if business_connection_id:
r = await session.invoke(
raw.functions.InvokeWithBusinessConnection(
query=rpc,
connection_id=business_connection_id
)
)
# await session.stop()
else:
r = await self.invoke(rpc)

for i in r.updates:
if isinstance(
Expand All @@ -119,3 +144,18 @@ async def edit_cached_media(
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
replies=self.fetch_replies
)
elif isinstance(
i,
(
raw.types.UpdateBotEditBusinessMessage
)
):
return await types.Message._parse(
self,
i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
business_connection_id=getattr(i, "connection_id", business_connection_id),
raw_reply_to_message=i.reply_to_message,
replies=0
)
4 changes: 2 additions & 2 deletions pyrogram/methods/messages/set_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async def set_reaction(
a channel to its discussion group have the
same available reactions as messages in the channel.
You must use exactly one of ``chat_id`` OR ``story_id``.
You must use exactly one of ``message_id`` OR ``story_id``.
If you specify, ``chat_id``
If you specify, ``message_id``
.. include:: /_includes/usable-by/users-bots.rst
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/users/set_personal_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def set_personal_chat(
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str`, *optional*):
chat_id (``int`` | ``str``, *optional*):
Identifier of the new personal chat; pass None to remove the chat. Use :meth:`~pyrogram.Client.get_created_chats` with ``is_suitable_for_my_personal_chat`` to get suitable chats
Returns:
Expand Down
1 change: 1 addition & 0 deletions pyrogram/types/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def default(obj: "Object"):
if isinstance(obj, datetime):
return str(obj)

# TODO: #20
if not hasattr(obj, "__dict__"):
return obj.__class__.__name__

Expand Down

0 comments on commit 39fe826

Please sign in to comment.