Skip to content

Commit 917af0b

Browse files
Update types to layer 214
Also fixed some bugs
1 parent 5eb978c commit 917af0b

12 files changed

Lines changed: 229 additions & 30 deletions

File tree

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ def get_title_list(s: str) -> list:
374374
transfer_chat_ownership
375375
get_suitable_discussion_chats
376376
set_chat_discussion_group
377+
set_main_profile_tab
377378
""",
378379
users="""
379380
Users
@@ -1135,6 +1136,7 @@ def get_title_list(s: str) -> list:
11351136
PollType
11361137
PrivacyKey
11371138
ProfileColor
1139+
ProfileTab
11381140
ReplyColor
11391141
SentCodeType
11401142
StoriesPrivacyRules

pyrogram/enums/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from .privacy_key import PrivacyKey
4040
from .privacy_rule_type import PrivacyRuleType
4141
from .profile_color import ProfileColor
42+
from .profile_tab import ProfileTab
4243
from .reply_color import ReplyColor
4344
from .sent_code_type import SentCodeType
4445
from .sticker_type import StickerType
@@ -75,6 +76,7 @@
7576
'PrivacyKey',
7677
'PrivacyRuleType',
7778
'ProfileColor',
79+
'ProfileTab',
7880
'ReplyColor',
7981
'SentCodeType',
8082
'StickerType',

pyrogram/enums/profile_tab.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 pyrogram import raw
20+
from .auto_name import AutoName
21+
22+
23+
class ProfileTab(AutoName):
24+
"""Profile tab enumeration used in :obj:`~pyrogram.types.Chat`."""
25+
26+
POSTS = raw.types.ProfileTabPosts
27+
"A tab with stories posted by the user or the channel chat and saved to profile."
28+
29+
GIFTS = raw.types.ProfileTabGifts
30+
"A tab with gifts received by the user or the channel chat."
31+
32+
MEDIA = raw.types.ProfileTabMedia
33+
"A tab with photos and videos posted by the channel."
34+
35+
FILES = raw.types.ProfileTabFiles
36+
"A tab with documents posted by the channel."
37+
38+
LINKS = raw.types.ProfileTabLinks
39+
"A tab with messages posted by the channel and containing links."
40+
41+
MUSIC = raw.types.ProfileTabMusic
42+
"A tab with audio messages posted by the channel."
43+
44+
VOICE = raw.types.ProfileTabVoice
45+
"A tab with voice notes posted by the channel."
46+
47+
GIFS = raw.types.ProfileTabGifs
48+
"A tab with animations posted by the channel."

pyrogram/methods/advanced/resolve_peer.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ async def resolve_peer(
116116
)
117117
)
118118

119-
try:
120-
return await self.storage.get_peer_by_id(utils.get_peer_id(r.peer))
121-
except KeyError:
122-
return await self.storage.get_peer_by_phone_number(phone)
119+
return await self.storage.get_peer_by_id(utils.get_peer_id(r.peer))
123120
else:
124121
username = None
125122
channel_id = None
@@ -136,23 +133,20 @@ async def resolve_peer(
136133

137134
if channel_id:
138135
try:
139-
return await self.storage.get_peer_by_id(peer_id)
136+
return await self.storage.get_peer_by_id(channel_id)
140137
except KeyError as e:
141138
raise PeerIdInvalid from e
142139
elif username:
143140
try:
144-
return await self.storage.get_peer_by_username(peer_id)
141+
return await self.storage.get_peer_by_username(username)
145142
except KeyError:
146143
r = await self.invoke(
147144
raw.functions.contacts.ResolveUsername(
148-
username=peer_id
145+
username=username
149146
)
150147
)
151148

152-
try:
153-
return await self.storage.get_peer_by_id(utils.get_peer_id(r.peer))
154-
except KeyError:
155-
return await self.storage.get_peer_by_username(peer_id)
149+
return await self.storage.get_peer_by_id(utils.get_peer_id(r.peer))
156150
else:
157151
raise PeerIdInvalid
158152
else:

pyrogram/methods/auth/send_code.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,18 @@ async def send_code(
103103
except (PhoneMigrate, NetworkMigrate) as e:
104104
dc_option = await self.get_dc_option(e.value, ipv6=self.ipv6)
105105
await self.session.stop()
106-
self.session = None
106+
107+
self.session = await self.get_session(
108+
dc_id=e.value,
109+
server_address=dc_option.ip_address,
110+
port=dc_option.port,
111+
export_authorization=False,
112+
temporary=True
113+
)
107114

108115
await self.storage.dc_id(e.value)
109116
await self.storage.server_address(dc_option.ip_address)
110117
await self.storage.port(dc_option.port)
111-
112-
self.session = await self.get_session(
113-
server_address=await self.storage.server_address(),
114-
port=await self.storage.port(),
115-
export_authorization=False,
116-
temporary=True
117-
)
118+
await self.storage.auth_key(self.session.auth_key)
118119
else:
119120
return types.SentCode._parse(r)

pyrogram/methods/auth/sign_in_bot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ async def sign_in_bot(
5858
except UserMigrate as e:
5959
dc_option = await self.get_dc_option(e.value, ipv6=self.ipv6)
6060
await self.session.stop()
61-
self.session = None
62-
63-
await self.storage.dc_id(e.value)
64-
await self.storage.server_address(dc_option.ip_address)
65-
await self.storage.port(dc_option.port)
6661

6762
self.session = await self.get_session(
68-
server_address=await self.storage.server_address(),
69-
port=await self.storage.port(),
70-
export_authorization=False,
71-
temporary=True
63+
dc_id=e.value,
64+
server_address=dc_option.ip_address,
65+
port=dc_option.port,
66+
export_authorization=False,
67+
temporary=True
7268
)
7369

70+
await self.storage.dc_id(e.value)
71+
await self.storage.server_address(dc_option.ip_address)
72+
await self.storage.port(dc_option.port)
73+
await self.storage.auth_key(self.session.auth_key)
7474
else:
7575
await self.storage.user_id(r.user.id)
7676
await self.storage.is_bot(True)

pyrogram/methods/chats/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
from .set_chat_direct_messages_group import SetChatDirectMessagesGroup
6969
from .set_chat_permissions import SetChatPermissions
7070
from .set_chat_discussion_group import SetChatDiscussionGroup
71+
from .set_main_profile_tab import SetMainProfileTab
7172
from .set_chat_photo import SetChatPhoto
7273
from .set_chat_protected_content import SetChatProtectedContent
7374
from .set_chat_title import SetChatTitle
@@ -124,6 +125,7 @@ class Chats(
124125
SetChatUsername,
125126
SetChatPermissions,
126127
SetChatDiscussionGroup,
128+
SetMainProfileTab,
127129
GetDialogsCount,
128130
GetFolders,
129131
GetForumTopics,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 typing import Union
20+
21+
import pyrogram
22+
from pyrogram import enums, raw
23+
24+
25+
class SetMainProfileTab:
26+
async def set_main_profile_tab(
27+
self: "pyrogram.Client",
28+
chat_id: Union[int, str],
29+
main_profile_tab: "enums.ProfileTab"
30+
) -> bool:
31+
"""Changes the main profile tab of the user or channel.
32+
33+
.. include:: /_includes/usable-by/users.rst
34+
35+
Parameters:
36+
chat_id (``int`` | ``str``):
37+
Unique identifier (int) or username (str) of the target chat.
38+
For your personal cloud (Saved Messages) you can simply use "me" or "self".
39+
40+
main_profile_tab (:obj:`~pyrogram.enums.ProfileTab`):
41+
The new value of the main profile tab.
42+
43+
Returns:
44+
``bool``: On success, True is returned.
45+
46+
Example:
47+
.. code-block:: python
48+
49+
# Set user main profile tab to "Posts"
50+
await app.set_main_profile_tab("me", main_profile_tab=enums.ProfileTab.POSTS)
51+
52+
# Set channel main profile tab to "Gifts"
53+
await app.set_main_profile_tab("kurigram_news", main_profile_tab=enums.ProfileTab.GIFTS)
54+
"""
55+
peer = await self.resolve_peer(chat_id)
56+
57+
if isinstance(peer, raw.types.InputPeerSelf):
58+
r = await self.invoke(
59+
raw.functions.account.SetMainProfileTab(
60+
tab=main_profile_tab.value(),
61+
)
62+
)
63+
else:
64+
r = await self.invoke(
65+
raw.functions.channels.SetMainProfileTab(
66+
channel=peer,
67+
tab=main_profile_tab.value()
68+
)
69+
)
70+
71+
return r

pyrogram/types/messages_and_media/gift.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ class Gift(Object):
184184
is_pinned (``bool``, *optional*):
185185
True, if the gift is pinned.
186186
187+
is_upgrade_separate (``bool``, *optional*):
188+
True, if the upgrade was bought after the gift was sent.
189+
In this case, prepaid upgrade cost must not be added to the gift cost.
190+
191+
is_theme_available (``bool``, *optional*):
192+
True, if the gift can be used to set a theme in a chat.
193+
194+
used_theme_chat_id (``int``, *optional*):
195+
Identifier of the chat for which the gift is used to set a theme.
196+
187197
raw (:obj:`~pyrogram.raw.base.StarGift`, *optional*):
188198
The raw object as received from the server.
189199
@@ -246,6 +256,9 @@ def __init__(
246256
is_for_birthday: Optional[bool] = None,
247257
is_premium: Optional[bool] = None,
248258
is_pinned: Optional[bool] = None,
259+
is_upgrade_separate: Optional[bool] = None,
260+
is_theme_available: Optional[bool] = None,
261+
used_theme_chat_id: Optional[int] = None,
249262
raw: Optional["raw.base.StarGift"] = None
250263
):
251264
super().__init__(client)
@@ -300,6 +313,9 @@ def __init__(
300313
self.is_for_birthday = is_for_birthday
301314
self.is_premium = is_premium
302315
self.is_pinned = is_pinned
316+
self.is_upgrade_separate = is_upgrade_separate
317+
self.is_theme_available = is_theme_available
318+
self.used_theme_chat_id = used_theme_chat_id
303319
self.raw = raw
304320

305321
@staticmethod
@@ -372,6 +388,8 @@ async def _parse_unique(
372388
total_upgraded_count=star_gift.availability_total,
373389
max_upgraded_count=star_gift.availability_issued,
374390
is_premium=star_gift.require_premium,
391+
is_theme_available=star_gift.theme_available,
392+
used_theme_chat_id=utils.get_peer_id(star_gift.theme_peer) if star_gift.theme_peer else None,
375393
owner=types.Chat._parse_chat(client, users.get(owner_id) or chats.get(owner_id)),
376394
owner_name=star_gift.owner_name,
377395
owner_address=star_gift.owner_address,
@@ -411,6 +429,7 @@ async def _parse_saved(
411429
parsed_gift.is_saved = not saved_gift.unsaved
412430
parsed_gift.is_refunded = saved_gift.refunded
413431
parsed_gift.is_pinned = saved_gift.pinned_to_top
432+
parsed_gift.is_upgrade_separate = saved_gift.upgrade_separate
414433
parsed_gift.can_upgrade = saved_gift.can_upgrade
415434
parsed_gift.from_user = types.User._parse(client, users.get(utils.get_raw_peer_id(saved_gift.from_id)))
416435
parsed_gift.caption = caption
@@ -447,6 +466,7 @@ async def _parse_action(
447466
parsed_gift.is_converted = action.converted
448467
parsed_gift.is_upgraded = action.upgraded
449468
parsed_gift.is_refunded = action.refunded
469+
parsed_gift.is_upgrade_separate = action.upgrade_separate
450470
parsed_gift.can_upgrade = action.can_upgrade
451471
parsed_gift.caption = caption
452472
parsed_gift.caption_entities = caption_entities

pyrogram/types/messages_and_media/gift_resale_price.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def write(self) -> "raw.base.StarsAmount":
3838
raise NotImplementedError
3939

4040

41-
class GiftResalePriceStar(Object):
41+
class GiftResalePriceStar(GiftResalePrice):
4242
"""Describes price of a resold gift in Telegram Stars.
4343
4444
Parameters:
@@ -61,7 +61,7 @@ def write(self) -> "raw.types.StarsAmount":
6161
)
6262

6363

64-
class GiftResalePriceTon(Object):
64+
class GiftResalePriceTon(GiftResalePrice):
6565
"""Describes price of a resold gift in Toncoins.
6666
6767
Parameters:

0 commit comments

Comments
 (0)