mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 20:14:51 +00:00
pyrofork: Drop accept_terms_of_service and sign_up method
Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
7d85848bef
commit
9401e246b6
6 changed files with 6 additions and 157 deletions
|
|
@ -423,12 +423,10 @@ def pyrogram_api():
|
|||
sign_in
|
||||
sign_in_bot
|
||||
sign_in_qrcode
|
||||
sign_up
|
||||
get_password_hint
|
||||
check_password
|
||||
send_recovery_code
|
||||
recover_password
|
||||
accept_terms_of_service
|
||||
log_out
|
||||
get_active_sessions
|
||||
""",
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ from pyrogram.handlers.handler import Handler
|
|||
from pyrogram.methods import Methods
|
||||
from pyrogram.session import Auth, Session
|
||||
from pyrogram.storage import FileStorage, MemoryStorage, Storage
|
||||
from pyrogram.types import User, TermsOfService
|
||||
from pyrogram.types import User
|
||||
from pyrogram.utils import ainput
|
||||
from .connection import Connection
|
||||
from .connection.transport import TCPAbridged
|
||||
|
|
@ -523,28 +523,6 @@ class Client(Methods):
|
|||
if isinstance(signed_in, User):
|
||||
return signed_in
|
||||
|
||||
while True:
|
||||
first_name = await ainput("Enter first name: ")
|
||||
last_name = await ainput("Enter last name (empty to skip): ")
|
||||
|
||||
try:
|
||||
signed_up = await self.sign_up(
|
||||
self.phone_number,
|
||||
sent_code.phone_code_hash,
|
||||
first_name,
|
||||
last_name
|
||||
)
|
||||
except BadRequest as e:
|
||||
print(e.MESSAGE)
|
||||
else:
|
||||
break
|
||||
|
||||
if isinstance(signed_in, TermsOfService):
|
||||
print("\n" + signed_in.text + "\n")
|
||||
await self.accept_terms_of_service(signed_in.id)
|
||||
|
||||
return signed_up
|
||||
|
||||
def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]):
|
||||
"""Set the parse mode to be used globally by the client.
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .accept_terms_of_service import AcceptTermsOfService
|
||||
from .check_password import CheckPassword
|
||||
from .connect import Connect
|
||||
from .disconnect import Disconnect
|
||||
|
|
@ -32,12 +31,10 @@ from .send_recovery_code import SendRecoveryCode
|
|||
from .sign_in import SignIn
|
||||
from .sign_in_bot import SignInBot
|
||||
from .sign_in_qrcode import SignInQrcode
|
||||
from .sign_up import SignUp
|
||||
from .terminate import Terminate
|
||||
|
||||
|
||||
class Auth(
|
||||
AcceptTermsOfService,
|
||||
CheckPassword,
|
||||
Connect,
|
||||
Disconnect,
|
||||
|
|
@ -52,7 +49,6 @@ class Auth(
|
|||
SignIn,
|
||||
SignInBot,
|
||||
SignInQrcode,
|
||||
SignUp,
|
||||
Terminate
|
||||
):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrofork.
|
||||
#
|
||||
# Pyrofork is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrofork is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
|
||||
|
||||
class AcceptTermsOfService:
|
||||
async def accept_terms_of_service(
|
||||
self: "pyrogram.Client",
|
||||
terms_of_service_id: str
|
||||
) -> bool:
|
||||
"""Accept the given terms of service.
|
||||
|
||||
.. include:: /_includes/usable-by/users.rst
|
||||
|
||||
Parameters:
|
||||
terms_of_service_id (``str``):
|
||||
The terms of service identifier.
|
||||
"""
|
||||
r = await self.invoke(
|
||||
raw.functions.help.AcceptTermsOfService(
|
||||
id=raw.types.DataJSON(
|
||||
data=terms_of_service_id
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return bool(r)
|
||||
|
|
@ -23,6 +23,7 @@ from typing import Union
|
|||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram.errors import PhoneNumberUnoccupied
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -49,15 +50,13 @@ class SignIn:
|
|||
The valid confirmation code you received (either as Telegram message or as SMS in your phone number).
|
||||
|
||||
Returns:
|
||||
:obj:`~pyrogram.types.User` | :obj:`~pyrogram.types.TermsOfService` | bool: On success, in case the
|
||||
authorization completed, the user is returned. In case the phone number needs to be registered first AND the
|
||||
terms of services accepted (with :meth:`~pyrogram.Client.accept_terms_of_service`), an object containing
|
||||
them is returned. In case the phone number needs to be registered, but the terms of services don't need to
|
||||
be accepted, False is returned instead.
|
||||
:obj:`~pyrogram.types.User` | bool: On success, in case the
|
||||
authorization completed, the user is returned.
|
||||
|
||||
Raises:
|
||||
BadRequest: In case the arguments are invalid.
|
||||
SessionPasswordNeeded: In case a password is needed to sign in.
|
||||
PhoneNumberUnoccupied: In case the phone number is not registered on Telegram.
|
||||
"""
|
||||
phone_number = phone_number.strip(" +")
|
||||
|
||||
|
|
@ -70,10 +69,7 @@ class SignIn:
|
|||
)
|
||||
|
||||
if isinstance(r, raw.types.auth.AuthorizationSignUpRequired):
|
||||
if r.terms_of_service:
|
||||
return types.TermsOfService._parse(terms_of_service=r.terms_of_service)
|
||||
|
||||
return False
|
||||
raise PhoneNumberUnoccupied("The phone number is not registered on Telegram. Please use official Telegram app to register it.")
|
||||
else:
|
||||
await self.storage.user_id(r.user.id)
|
||||
await self.storage.is_bot(False)
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrofork.
|
||||
#
|
||||
# Pyrofork is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrofork is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SignUp:
|
||||
async def sign_up(
|
||||
self: "pyrogram.Client",
|
||||
phone_number: str,
|
||||
phone_code_hash: str,
|
||||
first_name: str,
|
||||
last_name: str = ""
|
||||
) -> "types.User":
|
||||
"""Register a new user in Telegram.
|
||||
|
||||
.. include:: /_includes/usable-by/users.rst
|
||||
|
||||
Parameters:
|
||||
phone_number (``str``):
|
||||
Phone number in international format (includes the country prefix).
|
||||
|
||||
phone_code_hash (``str``):
|
||||
Code identifier taken from the result of :meth:`~pyrogram.Client.send_code`.
|
||||
|
||||
first_name (``str``):
|
||||
New user first name.
|
||||
|
||||
last_name (``str``, *optional*):
|
||||
New user last name. Defaults to "" (empty string, no last name).
|
||||
|
||||
Returns:
|
||||
:obj:`~pyrogram.types.User`: On success, the new registered user is returned.
|
||||
|
||||
Raises:
|
||||
BadRequest: In case the arguments are invalid.
|
||||
"""
|
||||
phone_number = phone_number.strip(" +")
|
||||
|
||||
r = await self.invoke(
|
||||
raw.functions.auth.SignUp(
|
||||
phone_number=phone_number,
|
||||
first_name=first_name,
|
||||
last_name=last_name,
|
||||
phone_code_hash=phone_code_hash
|
||||
)
|
||||
)
|
||||
|
||||
await self.storage.user_id(r.user.id)
|
||||
await self.storage.is_bot(False)
|
||||
|
||||
return types.User._parse(self, r.user)
|
||||
Loading…
Reference in a new issue