Skip to content

Commit 81b2853

Browse files
bugs squashed commit message (#163)
* Add media in ExternalReplyInfo * Add MessageOriginType as enum instead of str, As opposed to writing hard-coded values which are prone to errors, enumerations will help to deal with these values in a type-safe way and also enable code completion so that can be sure to apply only a valid value among the expected ones. * (fix): typings (KurimuzonAkuma/kurigram@9009474) * (chore): Update documentation (#161) * Add 1 unknown error * Make User.block/unblock/get_common_chats async Fix examples (KurimuzonAkuma/kurigram@f7f83de) * Fix docs (KurimuzonAkuma/kurigram@f98b927) * Raise instead of log in copy_message * Fix for TextQuote parsing (#162) --------- Co-authored-by: KurimuzonAkuma <[email protected]>
1 parent d0aee73 commit 81b2853

File tree

18 files changed

+119
-49
lines changed

18 files changed

+119
-49
lines changed

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ def get_title_list(s: str) -> list:
874874
ClientPlatform
875875
MessageEntityType
876876
MessageMediaType
877+
MessageOriginType
877878
MessageServiceType
878879
MessagesFilter
879880
ParseMode

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ STARREF_HASH_REVOKED The specified affiliate link was already revoked.
455455
STARREF_MONTHS_TOO_LOW The ``duration_months`` parameter must be between 0 and 36
456456
STARREF_PERMILLE_INVALID The specified commission_permille is invalid: the minimum and maximum values for this parameter are contained in the [starref_min_commission_permille](https://core.telegram.org/api/config#starref-min-commission-permille) and [starref_max_commission_permille](https://core.telegram.org/api/config#starref-max-commission-permille) client configuration parameters.
457457
STARREF_PERMILLE_TOO_LOW The specified commission_permille is too low: the minimum and maximum values for this parameter are contained in the [starref_min_commission_permille](https://core.telegram.org/api/config#starref-min-commission-permille) and [starref_max_commission_permille](https://core.telegram.org/api/config#starref-max-commission-permille) client configuration parameters.
458+
STARS_AMOUNT_INVALID The specified ``paid_stars`` amount is invalid.
458459
STARS_INVOICE_INVALID The specified Telegram Star invoice is invalid.
459460
STARS_PAYMENT_REQUIRED To import this chat invite link, you must first [pay for the associated Telegram Star subscription](https://core.telegram.org/api/subscriptions#channel-subscriptions).
460461
START_PARAM_EMPTY The start parameter is empty.

docs/source/releases/changes-in-this-fork.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you found any issue or have any suggestions, feel free to make `an issue <htt
2020
Breaking Changes in this Fork
2121
==============================
2222

23+
- In :meth:`~pyrogram.Client.copy_message`, ``ValueError`` is raised instead of ``logging`` it.
2324
- In :meth:`~pyrogram.Client.download_media`, if the message is a :obj:`~pyrogram.types.PaidMediaInfo` with more than one ``paid_media`` **and** ``idx`` was not specified, then a list of paths or binary file-like objects is returned.
2425
- PR `#115 <https://github.com/TelegramPlayGround/pyrogram/pull/115>`_ This `change <https://github.com/pyrogram/pyrogram/pull/966#issuecomment-1108858881>`_ breaks some usages with offset-naive and offset-aware datetimes.
2526
- PR from upstream: `#1411 <https://github.com/pyrogram/pyrogram/pull/1411>`_ without attribution.
@@ -33,6 +34,10 @@ Changes in this Fork
3334
| Scheme layer used: 200 |
3435
+------------------------+
3536

37+
- Add ``media`` in :obj:`~pyrogram.types.ExternalReplyInfo`.
38+
- Add :obj:`~pyrogram.enums.MessageOriginType` as enum instead of str, and updated the appropriate filters.
39+
- Document about `the issue #161 <https://github.com/TelegramPlayGround/pyrogram/issues/161>`__.
40+
- Make `User.block/unblock/get_common_chats async <https://github.com/KurimuzonAkuma/pyrogram/commit/7cab86a9eee4bd57ac96a1713f9bd37a7fc0ac09>`__, `Fix examples <https://github.com/KurimuzonAkuma/pyrogram/commit/f7f83de4331d6358332dbd0458755e28d59ec0f0>`__ and `Fix docs <https://github.com/KurimuzonAkuma/pyrogram/commit/f98b92765634f862310b21783b186fce66877a24>`__.
3641
- Try to return the service message (when applicable) in the method :meth:`~pyrogram.Client.set_chat_title`.
3742
- Added :meth:`~pyrogram.Client.delete_chat_history`.
3843
- Rename ``UserGift`` to :obj:`~pyrogram.types.ReceivedGift`, ``get_user_gifts`` to :meth:`~pyrogram.Client.get_received_gifts` and the corresponding fields appropriately.

pyrogram/enums/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .chat_type import ChatType
2525
from .message_entity_type import MessageEntityType
2626
from .message_media_type import MessageMediaType
27+
from .message_origin_type import MessageOriginType
2728
from .message_service_type import MessageServiceType
2829
from .messages_filter import MessagesFilter
2930
from .next_code_type import NextCodeType
@@ -43,7 +44,8 @@
4344
'ChatMembersFilter',
4445
'ChatType',
4546
'MessageEntityType',
46-
'MessageMediaType',
47+
'MessageMediaType',
48+
'MessageOriginType',
4749
'MessageServiceType',
4850
'MessagesFilter',
4951
'NextCodeType',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present <https://github.com/KurimuzonAkuma>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from enum import auto
20+
21+
from .auto_name import AutoName
22+
23+
24+
class MessageOriginType(AutoName):
25+
"""Message origin type enumeration used in :obj:`~pyrogram.types.MessageOrigin`."""
26+
27+
CHANNEL = auto()
28+
"The message was originally a post in a channel"
29+
30+
CHAT = auto()
31+
"The message was originally sent on behalf of a chat"
32+
33+
HIDDEN_USER = auto()
34+
"The message was originally sent by a user, which is hidden by their privacy settings"
35+
36+
IMPORT_INFO = auto()
37+
"The message was imported with `importMessages <https://t.me/telegram/142>`_"
38+
39+
USER = auto()
40+
"The message was originally sent by a known user"

pyrogram/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ async def from_scheduled_filter(_, __, m: Message) -> bool:
903903
async def linked_channel_filter(_, __, m: Message) -> bool:
904904
return bool(
905905
m.forward_origin and
906-
m.forward_origin.type == "channel" and
906+
m.forward_origin.type == enums.MessageOriginType.CHANNEL and
907907
m.forward_origin.chat == m.sender_chat
908908
)
909909

pyrogram/methods/messages/copy_message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ async def copy_message(
130130
Returns:
131131
:obj:`~pyrogram.types.Message`: On success, the copied message is returned.
132132
133+
Raises:
134+
RPCError: In case of a Telegram RPC error.
135+
ValueError: In case if an invalid message_id was provided.
136+
133137
Example:
134138
.. code-block:: python
135139

pyrogram/parser/markdown.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import html
2020
import re
21-
from typing import Optional
21+
from typing import Optional, Union
2222

2323
import pyrogram
2424
from pyrogram.enums import MessageEntityType
@@ -74,7 +74,7 @@ def __init__(self, client: Optional["pyrogram.Client"]):
7474

7575
@staticmethod
7676
def escape_and_create_quotes(text: str, strict: bool):
77-
text_lines: list[str | None] = text.splitlines()
77+
text_lines: list[Union[str, None]] = text.splitlines()
7878

7979
# Indexes of Already escaped lines
8080
html_escaped_list: list[int] = []

pyrogram/types/input_message_content/external_reply_info.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ class ExternalReplyInfo(Object):
9999
100100
venue (:obj:`~pyrogram.types.Venue`, *optional*):
101101
Message is a venue, information about the venue.
102+
103+
media (:obj:`~pyrogram.enums.MessageMediaType`, *optional*):
104+
The external reply is a media message.
105+
This field will contain the enumeration type of the media message.
106+
You can use ``media = getattr(external_reply, external_reply.media.value)`` to access the media message.
107+
102108
"""
103109

104110
def __init__(
@@ -129,6 +135,7 @@ def __init__(
129135
location: "types.Location" = None,
130136
poll: "types.Poll" = None,
131137
venue: "types.Venue" = None,
138+
media: "enums.MessageMediaType" = None,
132139
):
133140
super().__init__(client)
134141

@@ -156,6 +163,7 @@ def __init__(
156163
self.location = location
157164
self.poll = poll
158165
self.venue = venue
166+
self.media = media
159167

160168
@staticmethod
161169
async def _parse(
@@ -336,7 +344,8 @@ async def _parse(
336344
invoice=invoice,
337345
location=location,
338346
poll=poll,
339-
venue=venue
347+
venue=venue,
348+
media=media_type
340349
)
341350

342351

pyrogram/types/message_origin/message_import_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .message_origin import MessageOrigin
2222

2323
import pyrogram
24-
from pyrogram import types
24+
from pyrogram import types, enums
2525

2626

2727
class MessageImportInfo(MessageOrigin):
@@ -43,7 +43,7 @@ def __init__(
4343
sender_user_name: str = None
4444
):
4545
super().__init__(
46-
type="import_info",
46+
type=enums.MessageOriginType.IMPORT_INFO,
4747
date=date
4848
)
4949

0 commit comments

Comments
 (0)