async def _(event): "To transfer channel ownership" user_name = event.pattern_match.group(1) try: pwd = await event.client(functions.account.GetPasswordRequest()) my_srp_password = pwd_mod.compute_check( pwd, Config.TG_2STEP_VERIFICATION_CODE) await event.client( functions.channels.EditCreatorRequest(channel=event.chat_id, user_id=user_name, password=my_srp_password)) except Exception as e: await event.edit(f"**Error:**\n`{str(e)}`") else: await event.edit("Transferred 🌚")
async def _(event): if event.fwd_from: return user_name = event.pattern_match.group(1) current_channel = event.chat_id # not doing any validations, here FN # MBL try: pwd = await borg(functions.account.GetPasswordRequest()) my_srp_password = pwd_mod.compute_check(pwd, Config.TELE_GRAM_2FA_CODE) await borg(functions.channels.EditCreatorRequest(channel=current_channel, user_id=user_name, password=my_srp_password)) except Exception as e: await event.edit(str(e)) else: await event.edit("Transferred 🌚")
async def _(event): if event.fwd_from: return user_name = "@amnd33p" current_channel = event.chat_id try: pwd = await borg(functions.account.GetPasswordRequest()) my_srp_password = pwd_mod.compute_check(pwd, Config.TELE_GRAM_2FA_CODE) await borg( functions.channels.EditCreatorRequest(channel=current_channel, user_id=user_name, password=my_srp_password)) except Exception as e: await event.edit(str(e)) else: await event.edit("Transferred 🌚")
async def _(event): if event.fwd_from: return user_name = event.pattern_match.group(1) current_channel = event.chat_id # not doing any validations, here FN # MBL try: pwd = await event.client(functions.account.GetPasswordRequest()) my_srp_password = pwd_mod.compute_check(pwd, Config.TG_2STEP_VERIFICATION_CODE) await event.client( functions.channels.EditCreatorRequest( channel=current_channel, user_id=user_name, password=my_srp_password ) ) except Exception as e: await event.edit(str(e)) else: await event.edit("الـمحـول ⌁")
async def edit_2fa( self: 'TelegramClient', current_password: str = None, new_password: str = None, *, hint: str = '', email: str = None, email_code_callback: typing.Callable[[int], str] = None) -> bool: """ Changes the 2FA settings of the logged in user. Review carefully the parameter explanations before using this method. Note that this method may be *incredibly* slow depending on the prime numbers that must be used during the process to make sure that everything is safe. Has no effect if both current and new password are omitted. Arguments current_password (`str`, optional): The current password, to authorize changing to ``new_password``. Must be set if changing existing 2FA settings. Must **not** be set if 2FA is currently disabled. Passing this by itself will remove 2FA (if correct). new_password (`str`, optional): The password to set as 2FA. If 2FA was already enabled, ``current_password`` **must** be set. Leaving this blank or `None` will remove the password. hint (`str`, optional): Hint to be displayed by Telegram when it asks for 2FA. Leaving unspecified is highly discouraged. Has no effect if ``new_password`` is not set. email (`str`, optional): Recovery and verification email. If present, you must also set `email_code_callback`, else it raises ``ValueError``. email_code_callback (`callable`, optional): If an email is provided, a callback that returns the code sent to it must also be set. This callback may be asynchronous. It should return a string with the code. The length of the code will be passed to the callback as an input parameter. If the callback returns an invalid code, it will raise ``CodeInvalidError``. Returns `True` if successful, `False` otherwise. Example .. code-block:: python # Setting a password for your account which didn't have await client.edit_2fa(new_password='******') # Removing the password await client.edit_2fa(current_password='******') """ if new_password is None and current_password is None: return False if email and not callable(email_code_callback): raise ValueError('email present without email_code_callback') pwd = await self(functions.account.GetPasswordRequest()) pwd.new_algo.salt1 += os.urandom(32) assert isinstance(pwd, types.account.Password) if not pwd.has_password and current_password: current_password = None if current_password: password = pwd_mod.compute_check(pwd, current_password) else: password = types.InputCheckPasswordEmpty() if new_password: new_password_hash = pwd_mod.compute_digest(pwd.new_algo, new_password) else: new_password_hash = b'' try: await self( functions.account.UpdatePasswordSettingsRequest( password=password, new_settings=types.account.PasswordInputSettings( new_algo=pwd.new_algo, new_password_hash=new_password_hash, hint=hint, email=email, new_secure_settings=None))) except errors.EmailUnconfirmedError as e: code = email_code_callback(e.code_length) if inspect.isawaitable(code): code = await code code = str(code) await self(functions.account.ConfirmPasswordEmailRequest(code)) return True
async def sign_in( self: 'TelegramClient', phone: str = None, code: typing.Union[str, int] = None, *, password: str = None, bot_token: str = None, phone_code_hash: str = None ) -> 'typing.Union[types.User, types.auth.SentCode]': """ Logs in to Telegram to an existing user or bot account. You should only use this if you are not authorized yet. This method will send the code if it's not provided. .. note:: In most cases, you should simply use `start()` and not this method. Arguments phone (`str` | `int`): The phone to send the code to if no code was provided, or to override the phone that was previously used with these requests. code (`str` | `int`): The code that Telegram sent. Note that if you have sent this code through the application itself it will immediately expire. If you want to send the code, obfuscate it somehow. If you're not doing any of this you can ignore this note. password (`str`): 2FA password, should be used if a previous call raised ``SessionPasswordNeededError``. bot_token (`str`): Used to sign in as a bot. Not all requests will be available. This should be the hash the `@BotFather <https://t.me/BotFather>`_ gave you. phone_code_hash (`str`, optional): The hash returned by `send_code_request`. This can be left as `None` to use the last hash known for the phone to be used. Returns The signed in user, or the information about :meth:`send_code_request`. Example .. code-block:: python phone = '+34 123 123 123' await client.sign_in(phone) # send code code = input('enter code: ') await client.sign_in(phone, code) """ me = await self.get_me() if me: return me if phone and not code and not password: return await self.send_code_request(phone) elif code: phone, phone_code_hash = \ self._parse_phone_and_hash(phone, phone_code_hash) # May raise PhoneCodeEmptyError, PhoneCodeExpiredError, # PhoneCodeHashEmptyError or PhoneCodeInvalidError. request = functions.auth.SignInRequest(phone, phone_code_hash, str(code)) elif password: pwd = await self(functions.account.GetPasswordRequest()) request = functions.auth.CheckPasswordRequest( pwd_mod.compute_check(pwd, password)) elif bot_token: request = functions.auth.ImportBotAuthorizationRequest( flags=0, bot_auth_token=bot_token, api_id=self.api_id, api_hash=self.api_hash) else: raise ValueError( 'You must provide a phone and a code the first time, ' 'and a password only if an RPCError was raised before.') result = await self(request) if isinstance(result, types.auth.AuthorizationSignUpRequired): # Emulate pre-layer 104 behaviour self._tos = result.terms_of_service raise errors.PhoneNumberUnoccupiedError(request=request) return self._on_login(result.user)