mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 15:34:52 +00:00
pyrofork: Add reply_to_story_id to copy_media_group and send_inline_bot_result method
Signed-off-by: Yasir Aris <git@yasir.id>
This commit is contained in:
parent
2bb299c163
commit
1955de7a20
2 changed files with 109 additions and 44 deletions
|
|
@ -17,10 +17,11 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import List, Union, Optional
|
from datetime import datetime
|
||||||
|
from typing import Union, List, Optional
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram import enums, raw, types, utils
|
from pyrogram import raw, enums, types, utils
|
||||||
|
|
||||||
|
|
||||||
class SendInlineBotResult:
|
class SendInlineBotResult:
|
||||||
|
|
@ -29,12 +30,16 @@ class SendInlineBotResult:
|
||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
query_id: int,
|
query_id: int,
|
||||||
result_id: str,
|
result_id: str,
|
||||||
disable_notification: bool = None,
|
disable_notification: Optional[bool] = None,
|
||||||
message_thread_id: int = None,
|
message_thread_id: Optional[int] = None,
|
||||||
reply_to_message_id: int = None,
|
reply_to_message_id: Optional[int] = None,
|
||||||
quote_text: str = None,
|
reply_to_chat_id: Union[int, str] = None,
|
||||||
quote_entities: List["types.MessageEntity"] = None,
|
reply_to_story_id: Optional[int] = None,
|
||||||
parse_mode: Optional["enums.ParseMode"] = None
|
quote_text: Optional[str] = None,
|
||||||
|
parse_mode: Optional["enums.ParseMode"] = None,
|
||||||
|
quote_entities: Optional[List["types.MessageEntity"]] = None,
|
||||||
|
quote_offset: Optional[int] = None,
|
||||||
|
schedule_date: datetime = None,
|
||||||
) -> "types.Message":
|
) -> "types.Message":
|
||||||
"""Send an inline bot result.
|
"""Send an inline bot result.
|
||||||
Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results`
|
Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results`
|
||||||
|
|
@ -60,42 +65,42 @@ class SendInlineBotResult:
|
||||||
|
|
||||||
message_thread_id (``int``, *optional*):
|
message_thread_id (``int``, *optional*):
|
||||||
Unique identifier of a message thread to which the message belongs.
|
Unique identifier of a message thread to which the message belongs.
|
||||||
for supergroups only
|
For supergroups only.
|
||||||
|
|
||||||
reply_to_message_id (``bool``, *optional*):
|
reply_to_message_id (``bool``, *optional*):
|
||||||
If the message is a reply, ID of the original message.
|
If the message is a reply, ID of the original message.
|
||||||
|
|
||||||
quote_text (``str``, *optional*):
|
reply_to_chat_id (``int``, *optional*):
|
||||||
Text to quote.
|
If the message is a reply, ID of the original chat.
|
||||||
for reply_to_message only.
|
|
||||||
|
|
||||||
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
|
reply_to_story_id (``int``, *optional*):
|
||||||
List of special entities that appear in quote_text, which can be specified instead of *parse_mode*.
|
If the message is a reply, ID of the target story.
|
||||||
for reply_to_message only.
|
|
||||||
|
quote_text (``str``, *optional*):
|
||||||
|
Text of the quote to be sent.
|
||||||
|
|
||||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||||
By default, quote_text are parsed using both Markdown and HTML styles.
|
By default, texts are parsed using both Markdown and HTML styles.
|
||||||
You can combine both syntaxes together.
|
You can combine both syntaxes together.
|
||||||
For quote_text.
|
|
||||||
|
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
|
||||||
|
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
|
||||||
|
|
||||||
|
quote_offset (``int``, *optional*):
|
||||||
|
Offset for quote in original message.
|
||||||
|
|
||||||
|
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
|
||||||
|
Date when the message will be automatically sent.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`~pyrogram.types.Message`: On success, the sent message is returned.
|
:obj:`~pyrogram.types.Message`: On success, the sent message is returned or False if no message was sent.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
await app.send_inline_bot_result(chat_id, query_id, result_id)
|
await app.send_inline_bot_result(chat_id, query_id, result_id)
|
||||||
"""
|
"""
|
||||||
|
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()
|
||||||
reply_to = await utils.get_reply_to(
|
|
||||||
client=self,
|
|
||||||
chat_id=chat_id,
|
|
||||||
reply_to_message_id=reply_to_message_id,
|
|
||||||
message_thread_id=message_thread_id,
|
|
||||||
quote_text=quote_text,
|
|
||||||
quote_entities=quote_entities,
|
|
||||||
parse_mode=parse_mode
|
|
||||||
)
|
|
||||||
|
|
||||||
r = await self.invoke(
|
r = await self.invoke(
|
||||||
raw.functions.messages.SendInlineBotResult(
|
raw.functions.messages.SendInlineBotResult(
|
||||||
|
|
@ -104,15 +109,27 @@ class SendInlineBotResult:
|
||||||
id=result_id,
|
id=result_id,
|
||||||
random_id=self.rnd_id(),
|
random_id=self.rnd_id(),
|
||||||
silent=disable_notification or None,
|
silent=disable_notification or None,
|
||||||
reply_to=reply_to
|
reply_to=utils.get_reply_to(
|
||||||
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
|
||||||
|
reply_to_story_id=reply_to_story_id,
|
||||||
|
message_thread_id=message_thread_id,
|
||||||
|
quote_text=quote_text,
|
||||||
|
quote_entities=quote_entities,
|
||||||
|
quote_offset=quote_offset,
|
||||||
|
),
|
||||||
|
schedule_date=utils.datetime_to_timestamp(schedule_date),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for i in r.updates:
|
for i in r.updates:
|
||||||
if isinstance(i, (raw.types.UpdateNewMessage,
|
if isinstance(i, (raw.types.UpdateNewMessage,
|
||||||
raw.types.UpdateNewChannelMessage)):
|
raw.types.UpdateNewChannelMessage,
|
||||||
|
raw.types.UpdateNewScheduledMessage)):
|
||||||
return await types.Message._parse(
|
return await types.Message._parse(
|
||||||
self, i.message,
|
self, i.message,
|
||||||
{i.id: i for i in r.users},
|
{i.id: i for i in r.users},
|
||||||
{i.id: i for i in r.chats},
|
{i.id: i for i in r.chats},
|
||||||
|
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
|
||||||
|
business_connection_id=getattr(i, "connection_id", None)
|
||||||
)
|
)
|
||||||
|
|
@ -18,10 +18,10 @@
|
||||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Union, List
|
from typing import Union, List, Optional
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram import types, utils, raw
|
from pyrogram import types, utils, raw, enums
|
||||||
|
|
||||||
|
|
||||||
class CopyMediaGroup:
|
class CopyMediaGroup:
|
||||||
|
|
@ -31,10 +31,18 @@ class CopyMediaGroup:
|
||||||
from_chat_id: Union[int, str],
|
from_chat_id: Union[int, str],
|
||||||
message_id: int,
|
message_id: int,
|
||||||
captions: Union[List[str], str] = None,
|
captions: Union[List[str], str] = None,
|
||||||
|
has_spoilers: Union[List[bool], bool] = None,
|
||||||
disable_notification: bool = None,
|
disable_notification: bool = None,
|
||||||
message_thread_id: int = None,
|
message_thread_id: int = None,
|
||||||
reply_to_message_id: int = None,
|
reply_to_message_id: int = None,
|
||||||
|
reply_to_chat_id: Union[int, str] = None,
|
||||||
|
reply_to_story_id: int = None,
|
||||||
|
quote_text: str = None,
|
||||||
|
parse_mode: Optional["enums.ParseMode"] = None,
|
||||||
|
quote_entities: List["types.MessageEntity"] = None,
|
||||||
|
quote_offset: int = None,
|
||||||
schedule_date: datetime = None,
|
schedule_date: datetime = None,
|
||||||
|
invert_media: bool = None,
|
||||||
protect_content: bool = None,
|
protect_content: bool = None,
|
||||||
) -> List["types.Message"]:
|
) -> List["types.Message"]:
|
||||||
"""Copy a media group by providing one of the message ids.
|
"""Copy a media group by providing one of the message ids.
|
||||||
|
|
@ -72,14 +80,36 @@ class CopyMediaGroup:
|
||||||
|
|
||||||
message_thread_id (``int``, *optional*):
|
message_thread_id (``int``, *optional*):
|
||||||
Unique identifier for the target message thread (topic) of the forum.
|
Unique identifier for the target message thread (topic) of the forum.
|
||||||
for forum supergroups only.
|
For supergroups only.
|
||||||
|
|
||||||
reply_to_message_id (``int``, *optional*):
|
reply_to_message_id (``int``, *optional*):
|
||||||
If the message is a reply, ID of the original message.
|
If the message is a reply, ID of the original message.
|
||||||
|
|
||||||
|
reply_to_chat_id (``int``, *optional*):
|
||||||
|
If the message is a reply, ID of the original chat.
|
||||||
|
|
||||||
|
reply_to_story_id (``int``, *optional*):
|
||||||
|
If the message is a reply, ID of the target story.
|
||||||
|
|
||||||
|
quote_text (``str``, *optional*):
|
||||||
|
Text of the quote to be sent.
|
||||||
|
|
||||||
|
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||||
|
By default, texts are parsed using both Markdown and HTML styles.
|
||||||
|
You can combine both syntaxes together.
|
||||||
|
|
||||||
|
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
|
||||||
|
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
|
||||||
|
|
||||||
|
quote_offset (``int``, *optional*):
|
||||||
|
Offset for quote in original message.
|
||||||
|
|
||||||
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
|
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
|
||||||
Date when the message will be automatically sent.
|
Date when the message will be automatically sent.
|
||||||
|
|
||||||
|
invert_media (``bool``, *optional*):
|
||||||
|
Pass True, if the caption must be shown above the message media.
|
||||||
|
|
||||||
protect_content (``bool``, *optional*):
|
protect_content (``bool``, *optional*):
|
||||||
Protects the contents of the sent message from forwarding and saving
|
Protects the contents of the sent message from forwarding and saving
|
||||||
|
|
||||||
|
|
@ -97,14 +127,11 @@ class CopyMediaGroup:
|
||||||
await app.copy_media_group(to_chat, from_chat, 123,
|
await app.copy_media_group(to_chat, from_chat, 123,
|
||||||
captions=["caption 1", None, ""])
|
captions=["caption 1", None, ""])
|
||||||
"""
|
"""
|
||||||
|
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()
|
||||||
|
|
||||||
media_group = await self.get_media_group(from_chat_id, message_id)
|
media_group = await self.get_media_group(from_chat_id, message_id)
|
||||||
multi_media = []
|
multi_media = []
|
||||||
|
|
||||||
reply_to = None
|
|
||||||
if reply_to_message_id or message_thread_id:
|
|
||||||
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id)
|
|
||||||
|
|
||||||
for i, message in enumerate(media_group):
|
for i, message in enumerate(media_group):
|
||||||
if message.photo:
|
if message.photo:
|
||||||
file_id = message.photo.file_id
|
file_id = message.photo.file_id
|
||||||
|
|
@ -117,7 +144,19 @@ class CopyMediaGroup:
|
||||||
else:
|
else:
|
||||||
raise ValueError("Message with this type can't be copied.")
|
raise ValueError("Message with this type can't be copied.")
|
||||||
|
|
||||||
media = utils.get_input_media_from_file_id(file_id=file_id)
|
media = utils.get_input_media_from_file_id(
|
||||||
|
file_id=file_id,
|
||||||
|
has_spoiler=(
|
||||||
|
has_spoilers[i]
|
||||||
|
if isinstance(has_spoilers, list)
|
||||||
|
and i < len(has_spoilers)
|
||||||
|
else (
|
||||||
|
has_spoilers
|
||||||
|
if isinstance(has_spoilers, bool)
|
||||||
|
else message.has_media_spoiler
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
multi_media.append(
|
multi_media.append(
|
||||||
raw.types.InputSingleMedia(
|
raw.types.InputSingleMedia(
|
||||||
media=media,
|
media=media,
|
||||||
|
|
@ -135,9 +174,18 @@ class CopyMediaGroup:
|
||||||
peer=await self.resolve_peer(chat_id),
|
peer=await self.resolve_peer(chat_id),
|
||||||
multi_media=multi_media,
|
multi_media=multi_media,
|
||||||
silent=disable_notification or None,
|
silent=disable_notification or None,
|
||||||
reply_to=reply_to,
|
reply_to=utils.get_reply_to(
|
||||||
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
message_thread_id=message_thread_id,
|
||||||
|
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
|
||||||
|
reply_to_story_id=reply_to_story_id,
|
||||||
|
quote_text=quote_text,
|
||||||
|
quote_entities=quote_entities,
|
||||||
|
quote_offset=quote_offset,
|
||||||
|
),
|
||||||
|
schedule_date=utils.datetime_to_timestamp(schedule_date),
|
||||||
noforwards=protect_content,
|
noforwards=protect_content,
|
||||||
schedule_date=utils.datetime_to_timestamp(schedule_date)
|
invert_media=invert_media
|
||||||
),
|
),
|
||||||
sleep_threshold=60
|
sleep_threshold=60
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue