Skip to content

Commit 0d049c2

Browse files
committed
Merge remote-tracking branch 'KurimuzonAkuma/dev' into dev
# Conflicts: # pyproject.toml # pyrogram/methods/auth/send_code.py # pyrogram/parser/markdown.py # pyrogram/types/messages_and_media/paid_media_info.py
2 parents 13b63bc + 290daeb commit 0d049c2

30 files changed

+587
-228
lines changed

compiler/docs/compiler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,14 @@ def get_title_list(s: str) -> list:
544544
disconnect
545545
initialize
546546
terminate
547-
send_code
548-
resend_code
547+
send_phone_number_code
548+
resend_phone_number_code
549549
sign_in
550550
sign_in_bot
551551
sign_up
552552
get_password_hint
553553
check_password
554+
change_phone_number
554555
send_recovery_code
555556
recover_password
556557
accept_terms_of_service
@@ -949,6 +950,10 @@ def get_title_list(s: str) -> list:
949950
Authorization
950951
ActiveSession
951952
ActiveSessions
953+
FirebaseAuthenticationSettings
954+
FirebaseAuthenticationSettingsAndroid
955+
FirebaseAuthenticationSettingsIos
956+
PhoneNumberAuthenticationSettings
952957
SentCode
953958
TermsOfService
954959
"""
@@ -1226,6 +1231,7 @@ def get_title_list(s: str) -> list:
12261231
PaidReactionPrivacy
12271232
ParseMode
12281233
PhoneCallDiscardReason
1234+
PhoneNumberCodeType
12291235
PollType
12301236
PrivacyKey
12311237
ProfileColor

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,11 @@ SMS_CODE_CREATE_FAILED An error occurred while creating the SMS code.
482482
SRP_A_INVALID The specified inputCheckPasswordSRP.A value is invalid.
483483
SRP_ID_INVALID Invalid SRP ID provided.
484484
SRP_PASSWORD_CHANGED The password has changed.
485+
STARGIFT_ALREADY_BURNED The provided gift is already burned.
485486
STARGIFT_ALREADY_CONVERTED The provided star gift already converted to stars.
486487
STARGIFT_ALREADY_TRANSFERRED The provided star gift is already transferred.
487488
STARGIFT_ALREADY_UPGRADED This star gift was already upgraded before.
489+
STARGIFT_ATTRIBUTE_INVALID The provided gift attribute is invalid.
488490
STARGIFT_CONVERT_TOO_OLD This gift can no longer be converted into stars.
489491
STARGIFT_EXPORT_UNAVAILABLE This gift is not available for export yet.
490492
STARGIFT_INVALID The passed [inputInvoiceStarGift](https://core.telegram.org/constructor/inputInvoiceStarGift) is invalid.
@@ -610,6 +612,7 @@ USER_BOT_REQUIRED This method can only be called by a bot.
610612
USER_CHANNELS_TOO_MUCH One of the users you tried to add is already in too many channels/supergroups.
611613
USER_CREATOR The user id being used is invalid or not known yet. Make sure you meet the user before interacting with it.
612614
USER_GIFT_UNAVAILABLE Gifts are not available in the current region ([stars_gifts_enabled](https://core.telegram.org/api/config#stars-gifts-enabled) is equal to false).
615+
USER_HANDLE_MISMATCH The user handle mismatch.
613616
USER_ID_INVALID The provided user id is invalid.
614617
USER_INVALID The provided user is invalid.
615618
USER_IS_BLOCKED You were blocked by this user.

pyrogram/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ async def authorize(self) -> User:
501501
else:
502502
self.phone_number = value
503503

504-
sent_code = await self.send_code(self.phone_number)
504+
sent_code = await self.send_phone_number_code(self.phone_number)
505505
except BadRequest as e:
506506
print(e.MESSAGE)
507507
self.phone_number = None

pyrogram/enums/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .parse_mode import ParseMode
3838
from .payment_form_type import PaymentFormType
3939
from .phone_call_discard_reason import PhoneCallDiscardReason
40+
from .phone_number_code_type import PhoneNumberCodeType
4041
from .poll_type import PollType
4142
from .privacy_key import PrivacyKey
4243
from .privacy_rule_type import PrivacyRuleType
@@ -80,6 +81,7 @@
8081
'ParseMode',
8182
'PaymentFormType',
8283
'PhoneCallDiscardReason',
84+
'PhoneNumberCodeType',
8385
'PollType',
8486
'PrivacyKey',
8587
'PrivacyRuleType',
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 enum import auto
20+
21+
from .auto_name import AutoName
22+
23+
24+
class PhoneNumberCodeType(AutoName):
25+
"""Describes type of the request for which a code is sent to a phone number"""
26+
27+
AUTHENTICATION = auto()
28+
"Default authentication process."
29+
30+
CHANGE = auto()
31+
"Checks ownership of a new phone number to change the user's authentication phone number. For official Android and iOS applications only."
32+
33+
VERIFY = auto()
34+
"Verifies ownership of a phone number to be added to the user's Telegram Passport."

pyrogram/methods/auth/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from .accept_terms_of_service import AcceptTermsOfService
20+
from .change_phone_number import ChangePhoneNumber
2021
from .check_password import CheckPassword
2122
from .connect import Connect
2223
from .disconnect import Disconnect
@@ -25,10 +26,10 @@
2526
from .initialize import Initialize
2627
from .log_out import LogOut
2728
from .recover_password import RecoverPassword
28-
from .resend_code import ResendCode
29+
from .resend_phone_number_code import ResendPhoneNumberCode
2930
from .reset_session import ResetSession
3031
from .reset_sessions import ResetSessions
31-
from .send_code import SendCode
32+
from .send_phone_number_code import SendPhoneNumberCode
3233
from .send_recovery_code import SendRecoveryCode
3334
from .sign_in import SignIn
3435
from .sign_in_bot import SignInBot
@@ -38,6 +39,7 @@
3839

3940
class Auth(
4041
AcceptTermsOfService,
42+
ChangePhoneNumber,
4143
CheckPassword,
4244
Connect,
4345
Disconnect,
@@ -46,10 +48,10 @@ class Auth(
4648
Initialize,
4749
LogOut,
4850
RecoverPassword,
49-
ResendCode,
51+
ResendPhoneNumberCode,
5052
ResetSession,
5153
ResetSessions,
52-
SendCode,
54+
SendPhoneNumberCode,
5355
SendRecoveryCode,
5456
SignIn,
5557
SignInBot,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
import logging
20+
import re
21+
22+
import pyrogram
23+
from pyrogram import raw, types
24+
25+
log = logging.getLogger(__name__)
26+
27+
28+
class ChangePhoneNumber:
29+
async def change_phone_number(
30+
self: "pyrogram.Client", phone_number: str, phone_code_hash: str, phone_code: str
31+
) -> "types.User":
32+
"""Change a user phone number in Telegram with a valid confirmation code.
33+
34+
.. include:: /_includes/usable-by/users.rst
35+
36+
Parameters:
37+
phone_number (``str``):
38+
Phone number in international format (includes the country prefix).
39+
40+
phone_code_hash (``str``):
41+
Code identifier taken from the result of :meth:`~pyrogram.Client.send_phone_number_code`.
42+
43+
phone_code (``str``):
44+
The valid confirmation code you received from SMS in your phone number.
45+
46+
Returns:
47+
:obj:`~pyrogram.types.User`: On success, in case the change completed, the user is returned.
48+
"""
49+
phone_number = re.sub(r"\D", "", phone_number)
50+
51+
r = await self.invoke(
52+
raw.functions.account.ChangePhone(
53+
phone_number=phone_number,
54+
phone_code_hash=phone_code_hash,
55+
phone_code=phone_code
56+
)
57+
)
58+
59+
return types.User._parse(self, r)

pyrogram/methods/auth/resend_code.py renamed to pyrogram/methods/auth/resend_phone_number_code.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,22 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import re
2021

2122
import pyrogram
22-
from pyrogram import raw
23-
from pyrogram import types
23+
from pyrogram import raw, types
2424

2525
log = logging.getLogger(__name__)
2626

2727

28-
class ResendCode:
29-
async def resend_code(
30-
self: "pyrogram.Client",
31-
phone_number: str,
32-
phone_code_hash: str
28+
class ResendPhoneNumberCode:
29+
async def resend_phone_number_code(
30+
self: "pyrogram.Client", phone_number: str, phone_code_hash: str
3331
) -> "types.SentCode":
3432
"""Re-send the confirmation code using a different type.
3533
3634
The type of the code to be re-sent is specified in the *next_type* attribute of the
37-
:obj:`~pyrogram.types.SentCode` object returned by :meth:`send_code`.
35+
:obj:`~pyrogram.types.SentCode` object returned by :meth:`send_phone_number_code`.
3836
3937
.. include:: /_includes/usable-by/users.rst
4038
@@ -52,13 +50,14 @@ async def resend_code(
5250
Raises:
5351
BadRequest: In case the arguments are invalid.
5452
"""
55-
phone_number = phone_number.strip(" +")
53+
phone_number = re.sub(r"\D", "", phone_number)
5654

5755
r = await self.invoke(
5856
raw.functions.auth.ResendCode(
59-
phone_number=phone_number,
60-
phone_code_hash=phone_code_hash
57+
phone_number=phone_number, phone_code_hash=phone_code_hash
6158
)
6259
)
6360

6461
return types.SentCode._parse(r)
62+
63+
resend_code = resend_phone_number_code

pyrogram/methods/auth/send_code.py

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)