Skip to content

Commit

Permalink
Add support for quotes and update to 130.
Browse files Browse the repository at this point in the history
Signed-off-by: Aliwoto <[email protected]>
  • Loading branch information
KurimuzonAkuma authored and Aliwoto committed Oct 30, 2023
1 parent c3cf1b5 commit 104b0a8
Show file tree
Hide file tree
Showing 26 changed files with 823 additions and 150 deletions.
1 change: 1 addition & 0 deletions compiler/errors/source/400_BAD_REQUEST.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ AUTOARCHIVE_NOT_AVAILABLE This feature is not yet enabled for your account due t
BANK_CARD_NUMBER_INVALID The credit card number is invalid
BANNED_RIGHTS_INVALID You provided a set of restrictions that is invalid
BASE_PORT_LOC_INVALID The base port location is invalid
BOOSTS_REQUIRED Boosts required
BOTS_TOO_MUCH The chat has too many bots
BOT_CHANNELS_NA Bots can't edit admin privileges
BOT_COMMAND_DESCRIPTION_INVALID The command description was empty, too long or had invalid characters
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>

__version__ = "2.0.129"
__version__ = "2.0.130"
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"

Expand Down
15 changes: 12 additions & 3 deletions pyrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def create(func: Callable, name: str = None, **kwargs) -> Filter:
Parameters:
func (``Callable``):
A function that accepts three positional arguments *(filter, client, update)* and returns a boolean: True if the
update should be handled, False otherwise.
The *filter* argument refers to the filter itself and can be used to access keyword arguments (read below).
update should be handled, False otherwise.
The *filter* argument refers to the filter itself and can be used to access keyword arguments (read below).
The *client* argument refers to the :obj:`~pyrogram.Client` that received the update.
The *update* argument type will vary depending on which `Handler <handlers>`_ is coming from.
The *update* argument type will vary depending on which `Handler <handlers>`_ is coming from.
For example, in a :obj:`~pyrogram.handlers.MessageHandler` the *update* argument will be a :obj:`~pyrogram.types.Message`; in a :obj:`~pyrogram.handlers.CallbackQueryHandler` the *update* will be a :obj:`~pyrogram.types.CallbackQuery`.
Your function body can then access the incoming update attributes and decide whether to allow it or not.
Expand Down Expand Up @@ -424,6 +424,15 @@ async def dice_filter(_, __, m: Message):
dice = create(dice_filter)
"""Filter messages that contain :obj:`~pyrogram.types.Dice` objects."""

# endregion

# region quote_filter
async def quote_filter(_, __, m: Message):
return bool(m.quote)


quote = create(quote_filter)
"""Filter quote messages."""

# endregion

Expand Down
5 changes: 4 additions & 1 deletion pyrogram/methods/bots/send_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ async def send_game(
),
message="",
silent=disable_notification or None,
reply_to=utils.get_reply_to(reply_to_message_id, message_thread_id),
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id
),
random_id=self.rnd_id(),
noforwards=protect_content,
reply_markup=await reply_markup.write(self) if reply_markup else None
Expand Down
28 changes: 24 additions & 4 deletions pyrogram/methods/bots/send_inline_bot_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union
from typing import Union, List, Optional

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


Expand All @@ -31,7 +31,10 @@ async def send_inline_bot_result(
result_id: str,
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None
reply_to_message_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = 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 @@ -61,6 +64,16 @@ async def send_inline_bot_result(
reply_to_message_id (``bool``, *optional*):
If the message is a reply, ID of the original message.
quote_text (``str``):
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`):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
Returns:
:obj:`~pyrogram.raw.base.Updates`: Currently, on success, a raw result is returned.
Expand All @@ -69,13 +82,20 @@ async def send_inline_bot_result(
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()

return await self.invoke(
raw.functions.messages.SendInlineBotResult(
peer=await self.resolve_peer(chat_id),
query_id=query_id,
id=result_id,
random_id=self.rnd_id(),
silent=disable_notification or None,
reply_to=utils.get_reply_to(reply_to_message_id, message_thread_id)
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
quote_text=quote_text,
quote_entities=quote_entities
)
)
)
7 changes: 6 additions & 1 deletion pyrogram/methods/messages/forward_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async def forward_messages(
chat_id: Union[int, str],
from_chat_id: Union[int, str],
message_ids: Union[int, Iterable[int]],
message_thread_id: int = None,
disable_notification: bool = None,
schedule_date: datetime = None,
protect_content: bool = None
Expand All @@ -52,6 +53,9 @@ async def forward_messages(
message_ids (``int`` | Iterable of ``int``):
An iterable of message identifiers in the chat specified in *from_chat_id* or a single message id.
message_thread_id (``int``, *optional*):
Unique identifier of a message thread to which the message belongs; for supergroups only
disable_notification (``bool``, *optional*):
Sends the message silently.
Users will receive a notification with no sound.
Expand Down Expand Up @@ -87,7 +91,8 @@ async def forward_messages(
silent=disable_notification or None,
random_id=[self.rnd_id() for _ in message_ids],
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content
noforwards=protect_content,
top_msg_id=message_thread_id
)
)

Expand Down
46 changes: 31 additions & 15 deletions pyrogram/methods/messages/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ async def send_animation(
thumb: Union[str, BinaryIO] = None,
file_name: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
schedule_date: datetime = None,
protect_content: bool = None,
reply_markup: Union[
Expand Down Expand Up @@ -116,11 +119,21 @@ async def send_animation(
Sends the message silently.
Users will receive a notification with no sound.
message_thread_id (``int``, *optional*):
Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
quote_text (``str``):
Text of the quote to be sent.
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the message will be automatically sent.
Expand Down Expand Up @@ -227,16 +240,24 @@ async def progress(current, total):
]
)

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()

while True:
try:
peer = await self.resolve_peer(chat_id)
r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
peer=peer,
media=media,
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=peer,
reply_to_story_id=reply_to_story_id,
quote_text=quote_text,
quote_entities=quote_entities,
),
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand All @@ -258,18 +279,13 @@ async def progress(current, total):
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage)
)

if unsave:
document = message.animation or message.document
if unsave and message.animation:
document_id = utils.get_input_media_from_file_id(
document.file_id, FileType.ANIMATION
message.animation.file_id,
FileType.ANIMATION,
).id

await self.invoke(
raw.functions.messages.SaveGif(
id=document_id,
unsave=True
)
)
await self.invoke(raw.functions.messages.SaveGif(id=document_id, unsave=True)) # type: ignore[arg-type]

return message

Expand Down
33 changes: 27 additions & 6 deletions pyrogram/methods/messages/send_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ async def send_audio(
thumb: Union[str, BinaryIO] = None,
file_name: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
schedule_date: datetime = None,
protect_content: bool = None,
reply_markup: Union[
Expand Down Expand Up @@ -109,11 +112,21 @@ async def send_audio(
Sends the message silently.
Users will receive a notification with no sound.
message_thread_id (``int``, *optional*):
Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
quote_text (``str``):
Text of the quote to be sent.
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the message will be automatically sent.
Expand Down Expand Up @@ -214,16 +227,24 @@ async def progress(current, total):
]
)

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()

while True:
try:
peer = await self.resolve_peer(chat_id)
r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
peer=peer,
media=media,
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=peer,
reply_to_story_id=reply_to_story_id,
quote_text=quote_text,
quote_entities=quote_entities,
),
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
44 changes: 34 additions & 10 deletions pyrogram/methods/messages/send_cached_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from typing import Union, List, Optional

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


Expand All @@ -34,10 +33,14 @@ async def send_cached_media(
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
schedule_date: datetime = None,
protect_content: bool = None,
invert_media: bool = None,
reply_markup: Union[
"types.InlineKeyboardMarkup",
"types.ReplyKeyboardMarkup",
Expand Down Expand Up @@ -77,18 +80,31 @@ async def send_cached_media(
Sends the message silently.
Users will receive a notification with no sound.
message_thread_id (``int``, *optional*):
Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
quote_text (``str``):
Text of the quote to be sent.
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the message will be automatically sent.
protect_content (``bool``, *optional*):
Protects the contents of the sent message from forwarding and saving.
invert_media (``bool``, *optional*):
Invert media.
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
Additional interface options. An object for an inline keyboard, custom reply keyboard,
instructions to remove reply keyboard or to force a reply from the user.
Expand All @@ -101,15 +117,23 @@ async def send_cached_media(
await app.send_cached_media("me", file_id)
"""
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)

peer = await self.resolve_peer(chat_id)
r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
peer=peer,
media=utils.get_input_media_from_file_id(file_id),
silent=disable_notification or None,
reply_to=reply_to,
invert_media=invert_media,
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
reply_to_story_id=reply_to_story_id,
quote_text=quote_text,
quote_entities=quote_entities,
),
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
Loading

0 comments on commit 104b0a8

Please sign in to comment.