Skip to content

Commit 72eebfa

Browse files
author
Pyrogram-Mod - Dev
committed
fix: restore missing types, fix Python 3.14 event loop, and update exports
- Restored missing implementation files for PeerColor, StickerSet, PremiumGiftCodeOption, StarRefProgram, GroupCallMessage, and GroupCallStreamChannel. - Updated pyrogram/sync.py with event loop handling for Python 3.14. - Fixed missing exports in pyrogram/types/ package and subpackages. - Updated compiler templates and filters documentation.
1 parent b073b04 commit 72eebfa

18 files changed

Lines changed: 720 additions & 10 deletions

File tree

compiler/api/template/type.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ from typing import Union
66
from pyrogram import raw
77

88
{name} = Union[{types}]
9-
{name}.__doc__ = """
10-
{docstring}
11-
"""
9+
"""{docstring}"""

compiler/docs/template/bound-methods.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,55 @@ ChatJoinRequest
101101

102102
{chat_join_request_toctree}
103103

104+
StoryItem
105+
---------
106+
107+
.. hlist::
108+
:columns: 3
109+
110+
{story_item_hlist}
111+
112+
.. toctree::
113+
:hidden:
114+
115+
{story_item_toctree}
116+
117+
QuickReply
118+
----------
119+
120+
.. hlist::
121+
:columns: 2
122+
123+
{quick_reply_hlist}
124+
125+
.. toctree::
126+
:hidden:
127+
128+
{quick_reply_toctree}
129+
130+
BusinessChatLink
131+
----------------
132+
133+
.. hlist::
134+
:columns: 2
135+
136+
{business_chat_link_hlist}
137+
138+
.. toctree::
139+
:hidden:
140+
141+
{business_chat_link_toctree}
142+
143+
SavedDialog
144+
-----------
145+
146+
.. hlist::
147+
:columns: 2
148+
149+
{saved_dialog_hlist}
150+
151+
.. toctree::
152+
:hidden:
153+
154+
{saved_dialog_toctree}
155+

compiler/docs/template/types.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,84 @@ Authorization
120120

121121
{authorization}
122122

123+
Stories
124+
-------
125+
126+
.. autosummary::
127+
:nosignatures:
128+
129+
{stories}
130+
131+
.. toctree::
132+
:hidden:
133+
134+
{stories}
135+
136+
Payments
137+
--------
138+
139+
.. autosummary::
140+
:nosignatures:
141+
142+
{payments}
143+
144+
.. toctree::
145+
:hidden:
146+
147+
{payments}
148+
149+
Star Gifts
150+
----------
151+
152+
.. autosummary::
153+
:nosignatures:
154+
155+
{star_gifts}
156+
157+
.. toctree::
158+
:hidden:
159+
160+
{star_gifts}
161+
162+
Business
163+
--------
164+
165+
.. autosummary::
166+
:nosignatures:
167+
168+
{business}
169+
170+
.. toctree::
171+
:hidden:
172+
173+
{business}
174+
175+
Boosts
176+
------
177+
178+
.. autosummary::
179+
:nosignatures:
180+
181+
{boosts}
182+
183+
.. toctree::
184+
:hidden:
185+
186+
{boosts}
187+
188+
Saved Messages
189+
--------------
190+
191+
.. autosummary::
192+
:nosignatures:
193+
194+
{saved_messages}
195+
196+
.. toctree::
197+
:hidden:
198+
199+
{saved_messages}
200+
123201
.. toctree::
124202
:hidden:
125203

docs/source/topics/use-filters.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ Here are some examples:
6969
async def my_handler(client, message):
7070
print(message)
7171
72+
- Message is a **story** **or** contains **paid media**.
73+
74+
.. code-block:: python
75+
76+
@app.on_message(filters.story | filters.paid_media)
77+
async def my_handler(client, message):
78+
print(message)
79+
7280
Advanced Filters
7381
----------------
7482

pyrogram/filters.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,19 @@ async def business_filter(_, __, m: Message):
382382
"""Filter messages related to Telegram Business (sent via business bot or quick reply)."""
383383

384384

385+
# endregion
386+
387+
388+
# region boost_filter
389+
async def boost_filter(_, __, update: Update):
390+
from pyrogram.types import ChatBoostUpdated
391+
return isinstance(update, ChatBoostUpdated)
392+
393+
394+
boost = create(boost_filter)
395+
"""Filter chat boost updates."""
396+
397+
385398
# endregion
386399

387400
# region video_filter

pyrogram/raw/core/tl_object.py

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

1919
from io import BytesIO
2020
from json import dumps
21-
from typing import cast, List, Any, Union, Dict
21+
from typing import cast, List, Any, Union, Dict, Generic, TypeVar
2222

2323
from ..all import objects
2424

25+
T = TypeVar("T")
2526

26-
class TLObject:
27+
28+
class TLObject(Generic[T]):
2729
__slots__: List[str] = []
2830

2931
QUALNAME = "Base"

pyrogram/sync.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,27 @@
2626
from pyrogram.methods.utilities import idle as idle_module, compose as compose_module
2727

2828

29+
def _ensure_event_loop():
30+
"""
31+
Python 3.14 no longer creates an implicit event loop for the main thread.
32+
Reproduce the old behaviour by instantiating and setting one on-demand.
33+
"""
34+
try:
35+
return asyncio.get_running_loop()
36+
except RuntimeError:
37+
pass
38+
39+
try:
40+
return asyncio.get_event_loop()
41+
except RuntimeError:
42+
loop = asyncio.new_event_loop()
43+
asyncio.set_event_loop(loop)
44+
return loop
45+
46+
2947
def async_to_sync(obj, name):
3048
function = getattr(obj, name)
31-
main_loop = asyncio.get_event_loop()
49+
main_loop = _ensure_event_loop()
3250

3351
def async_to_sync_gen(agen, loop, is_main_thread):
3452
async def anext(agen):
@@ -52,7 +70,11 @@ async def anext(agen):
5270
def async_to_sync_wrap(*args, **kwargs):
5371
coroutine = function(*args, **kwargs)
5472

55-
loop = _ensure_event_loop()
73+
try:
74+
loop = asyncio.get_event_loop()
75+
except RuntimeError:
76+
loop = asyncio.new_event_loop()
77+
asyncio.set_event_loop(loop)
5678

5779
if threading.current_thread() is threading.main_thread() or not main_loop.is_running():
5880
if loop.is_running():

pyrogram/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .messages_and_media import *
2929
from .object import Object
3030
from .payments import *
31+
from .saved_messages import *
3132
from .stats import *
3233
from .stories import *
3334
from .todo import *

pyrogram/types/calls/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
from .group_call import GroupCall
2020
from .group_call_participant import GroupCallParticipant
2121
from .conference_call import ConferenceCall
22+
from .group_call_message import GroupCallMessage
23+
from .group_call_stream_channel import GroupCallStreamChannel
24+
2225

2326
__all__ = [
2427
"GroupCall",
2528
"GroupCallParticipant",
26-
"ConferenceCall"
29+
"ConferenceCall",
30+
"GroupCallMessage",
31+
"GroupCallStreamChannel"
2732
]
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
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 datetime import datetime
20+
21+
import pyrogram
22+
from pyrogram import raw, types, utils
23+
from ..object import Object
24+
25+
26+
class GroupCallMessage(Object):
27+
"""A message in a group call.
28+
29+
Parameters:
30+
id (``int``):
31+
Message identifier.
32+
33+
from_id (:obj:`~pyrogram.types.Chat` | :obj:`~pyrogram.types.User`):
34+
Sender of the message.
35+
36+
date (``datetime``):
37+
Date the message was sent.
38+
39+
text (``str``):
40+
Message text.
41+
42+
is_from_admin (``bool``, *optional*):
43+
True, if the message was sent by an admin.
44+
45+
paid_message_stars (``int``, *optional*):
46+
Price of the message in Telegram Stars.
47+
"""
48+
49+
def __init__(
50+
self,
51+
*,
52+
client: "pyrogram.Client" = None,
53+
id: int,
54+
from_id: "types.Chat" = None,
55+
date: datetime,
56+
text: str,
57+
is_from_admin: bool = None,
58+
paid_message_stars: int = None
59+
):
60+
super().__init__(client)
61+
62+
self.id = id
63+
self.from_id = from_id
64+
self.date = date
65+
self.text = text
66+
self.is_from_admin = is_from_admin
67+
self.paid_message_stars = paid_message_stars
68+
69+
@staticmethod
70+
def _parse(
71+
client: "pyrogram.Client",
72+
message: "raw.types.GroupCallMessage",
73+
users: dict = None,
74+
chats: dict = None
75+
) -> "GroupCallMessage":
76+
if not message:
77+
return None
78+
79+
return GroupCallMessage(
80+
client=client,
81+
id=message.id,
82+
from_id=types.Chat._parse(client, message.from_id, users, chats),
83+
date=utils.timestamp_to_datetime(message.date),
84+
text=message.message.text if hasattr(message.message, "text") else message.message,
85+
is_from_admin=getattr(message, "from_admin", None),
86+
paid_message_stars=getattr(message, "paid_message_stars", None)
87+
)

0 commit comments

Comments
 (0)