Skip to content

Commit a5a3a69

Browse files
committed
Merge remote-tracking branch 'KurimuzonAkuma/dev' into dev
# Conflicts: # pyproject.toml # pyrogram/client.py # pyrogram/enums/__init__.py
2 parents e459b8d + 3997a4a commit a5a3a69

74 files changed

Lines changed: 2126 additions & 589 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/api/source/main_api.tl

Lines changed: 68 additions & 46 deletions
Large diffs are not rendered by default.

compiler/docs/compiler.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def get_title_list(s: str) -> list:
243243
send_voice
244244
send_video_note
245245
send_media_group
246+
send_message_draft
246247
send_location
247248
send_venue
248249
send_contact
@@ -432,6 +433,7 @@ def get_title_list(s: str) -> list:
432433
add_contact
433434
delete_contacts
434435
import_contacts
436+
get_blocked_message_senders
435437
get_contacts
436438
get_contacts_count
437439
search_contacts
@@ -460,6 +462,8 @@ def get_title_list(s: str) -> list:
460462
set_gift_collection_name
461463
get_gift_upgrade_preview
462464
get_gift_upgrade_variants
465+
get_gifts_for_crafting
466+
craft_gift
463467
get_payment_form
464468
get_stars_balance
465469
get_ton_balance
@@ -714,6 +718,9 @@ def get_title_list(s: str) -> list:
714718
Voice
715719
VideoNote
716720
Contact
721+
CraftGiftResult
722+
CraftGiftResultSuccess
723+
CraftGiftResultFail
717724
Location
718725
MaskPosition
719726
MediaArea
@@ -749,7 +756,7 @@ def get_title_list(s: str) -> list:
749756
Invoice
750757
LinkPreviewOptions
751758
GiftCollection
752-
GiftCode
759+
PremiumGiftCode
753760
GiftPurchaseLimit
754761
GiftResaleParameters
755762
GiftResalePrice
@@ -789,6 +796,8 @@ def get_title_list(s: str) -> list:
789796
SavedCredentials
790797
PaymentResult
791798
ChatBoost
799+
ChatOwnerChanged
800+
ChatOwnerLeft
792801
ContactRegistered
793802
ScreenshotTaken
794803
StarAmount
@@ -807,6 +816,12 @@ def get_title_list(s: str) -> list:
807816
UpgradedGiftAttributeIdModel
808817
UpgradedGiftAttributeIdSymbol
809818
UpgradedGiftAttributeIdBackdrop
819+
UpgradedGiftAttributeRarity
820+
UpgradedGiftAttributeRarityPerMille
821+
UpgradedGiftAttributeRarityUncommon
822+
UpgradedGiftAttributeRarityRare
823+
UpgradedGiftAttributeRarityEpic
824+
UpgradedGiftAttributeRarityLegendary
810825
UpgradedGiftOriginalDetails
811826
InputChatPhoto
812827
InputChatPhotoPrevious
@@ -1187,7 +1202,9 @@ def get_title_list(s: str) -> list:
11871202
categories = dict(
11881203
enums="""
11891204
Enumerations
1205+
BlockList
11901206
BusinessSchedule
1207+
ButtonStyle
11911208
ChatAction
11921209
ChatEventAction
11931210
ChatJoinType
@@ -1213,6 +1230,7 @@ def get_title_list(s: str) -> list:
12131230
SentCodeType
12141231
StoriesPrivacyRules
12151232
UserStatus
1233+
UpgradedGiftOrigin
12161234
GiftAttributeType
12171235
MediaAreaType
12181236
PrivacyRuleType

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ POLL_OPTION_INVALID IA poll option used invalid data (the data may be too long).
400400
POLL_QUESTION_INVALID The poll question is invalid.
401401
POLL_UNSUPPORTED This layer does not support polls in the invoked method.
402402
POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method.
403-
PRECHECKOUT_FAILED Precheckout failed.
403+
PRECHECKOUT_FAILED Precheckout failed. Probably you don't have enough funds to complete the purchase.
404404
PREMIUM_ACCOUNT_REQUIRED A premium account is required to execute this action.
405405
PREMIUM_GIFTCODE_WAS_REFUNDED This gift code can't be redeemed because the giveaway organizer requested a refund.
406406
PRICING_CHAT_INVALID The pricing for the [subscription](https://core.telegram.org/api/subscriptions) is invalid, the maximum price is specified in the [`stars_subscription_amount_max` config key »](https://core.telegram.org/api/config#stars-subscription-amount-max).
@@ -644,4 +644,4 @@ WEBPAGE_URL_INVALID The specified webpage `url` is invalid.
644644
WEBPUSH_AUTH_INVALID The specified web push authentication secret is invalid.
645645
WEBPUSH_KEY_INVALID The specified web push elliptic curve Diffie-Hellman public key is invalid.
646646
WEBPUSH_TOKEN_INVALID The specified web push token is invalid.
647-
YOU_BLOCKED_USER You blocked this user.
647+
YOU_BLOCKED_USER You blocked this user.

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
__version__ = "2.2.17"
19+
__version__ = "2.2.19"
2020
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
2121
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"
2222

pyrogram/client.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#
66
# Pyrogram is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU Lesser General Public License as published
8-
# by the Free Software 我给他職5日4还有个63 摩羯男 Foundation, either version 3 of the License, or
8+
# by the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
1010
#
1111
# Pyrogram is distributed in the hope that it will be useful,
1212
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR5A PARTICULAR PURPOSE. See the
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
# GNU Lesser General Public License for more details.
1515
#
1616
# You should have received a copy of the GNU Lesser General Public License
@@ -119,9 +119,10 @@ class Client(Methods):
119119
after which the server address will be updated (works both ways).
120120
Defaults to False (IPv4).
121121
122-
proxy (``dict``, *optional*):
122+
proxy (``dict`` | ``str``, *optional*):
123123
The Proxy settings as dict.
124-
E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*.
124+
E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*
125+
or *"http://11.22.33.44:1234"* or *"socks5://user:pass@11.22.33.44:1234"*.
125126
The *username* and *password* can be omitted if the proxy doesn't require authorization.
126127
127128
test_mode (``bool``, *optional*):
@@ -180,6 +181,7 @@ class Client(Methods):
180181
181182
skip_updates (``bool``, *optional*):
182183
Pass True to skip pending updates that arrived while the client was offline.
184+
Doesn't work if *in_memory* is set to True.
183185
Defaults to True.
184186
185187
takeout (``bool``, *optional*):
@@ -287,7 +289,7 @@ def __init__(
287289
lang_code: str = LANG_CODE,
288290
system_lang_code: str = SYSTEM_LANG_CODE,
289291
ipv6: Optional[bool] = False,
290-
proxy: Optional[dict] = None,
292+
proxy: Optional[Union[dict, str]] = None,
291293
test_mode: Optional[bool] = False,
292294
bot_token: Optional[str] = None,
293295
session_string: Optional[str] = None,
@@ -382,10 +384,7 @@ def __init__(
382384
self.dispatcher: Dispatcher = Dispatcher(self)
383385

384386
self.rnd_id = MsgId
385-
self._last_sync_time = time.time()
386-
self._last_monotonic = time.monotonic()
387-
388-
self._is_server_time_synced = False
387+
self._server_time_offset = 0.0
389388

390389
self.parser: Parser = Parser(self)
391390

@@ -425,10 +424,20 @@ def __init__(
425424
if isinstance(loop, asyncio.AbstractEventLoop):
426425
self.loop = loop
427426
else:
428-
self.loop = utils.get_event_loop()
427+
self.loop = None
429428

430429
self.__config: "raw.types.Config" = None
431430

431+
@property
432+
def loop(self) -> asyncio.AbstractEventLoop:
433+
if not self._loop:
434+
self._loop = utils.get_event_loop()
435+
return self._loop
436+
437+
@loop.setter
438+
def loop(self, value: asyncio.AbstractEventLoop):
439+
self._loop = value
440+
432441
self.listeners = {listener_type: [] for listener_type in pyrogram.enums.ListenerTypes}
433442

434443
self.listeners = {listener_type: [] for listener_type in pyrogram.enums.ListenerTypes}
@@ -633,12 +642,12 @@ async def authorize(self) -> User:
633642
return signed_up
634643

635644
async def authorize_qr(self, except_ids: List[int] = []) -> "User":
636-
import qrcode
645+
from qrcode import QRCode
637646

638647
qr_login = QRLogin(self, except_ids)
639648
await qr_login.recreate()
640649

641-
qr = qrcode.QRCode(version=1)
650+
qr = QRCode(version=1)
642651

643652
while True:
644653
try:
@@ -822,7 +831,7 @@ async def handle_updates(self, updates):
822831
pts = getattr(update, "pts", None)
823832
pts_count = getattr(update, "pts_count", None)
824833

825-
if pts and not self.skip_updates:
834+
if pts:
826835
await self.storage.update_state(
827836
(
828837
utils.get_channel_id(channel_id) if channel_id else 0,
@@ -864,16 +873,15 @@ async def handle_updates(self, updates):
864873

865874
self.dispatcher.updates_queue.put_nowait((update, users, chats))
866875
elif isinstance(updates, (raw.types.UpdateShortMessage, raw.types.UpdateShortChatMessage)):
867-
if not self.skip_updates:
868-
await self.storage.update_state(
869-
(
870-
0,
871-
updates.pts,
872-
None,
873-
updates.date,
874-
None
875-
)
876+
await self.storage.update_state(
877+
(
878+
0,
879+
updates.pts,
880+
None,
881+
updates.date,
882+
None
876883
)
884+
)
877885

878886
diff = await self.invoke(
879887
raw.functions.updates.GetDifference(
@@ -1536,16 +1544,12 @@ async def set_dc(
15361544

15371545
@property
15381546
def server_time(self) -> float:
1539-
return self._last_sync_time + (time.monotonic() - self._last_monotonic)
1547+
return time.time() + self._server_time_offset
15401548

15411549
def _set_server_time(self, msg_id: int):
1542-
if self._is_server_time_synced:
1543-
return
1544-
1545-
self._last_sync_time = msg_id / float(2**32)
1546-
self._last_monotonic = time.monotonic()
1547-
self._is_server_time_synced = True
1548-
log.info(f"Time synced: {utils.timestamp_to_datetime(self._last_sync_time)}")
1550+
server_ts = msg_id / float(2**32)
1551+
self._server_time_offset = server_ts - time.time()
1552+
log.info(f"Time synced: offset={self._server_time_offset:.3f}s, server_time={utils.timestamp_to_datetime(server_ts)}")
15491553

15501554
def guess_mime_type(self, filename: Union[str, BytesIO]) -> Optional[str]:
15511555
if isinstance(filename, BytesIO):

pyrogram/connection/connection.py

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

1919
import asyncio
2020
import logging
21-
from typing import Optional, Type
21+
from typing import Optional, Type, Union
2222

2323
from pyrogram import utils
2424

@@ -36,7 +36,7 @@ def __init__(
3636
server_address: str,
3737
port: int,
3838
test_mode: bool,
39-
proxy: dict,
39+
proxy: Optional[Union[dict, str]] = None,
4040
media: bool = False,
4141
protocol_factory: Type[TCP] = TCPAbridged,
4242
crypto_executor_workers: int = 1,

0 commit comments

Comments
 (0)