From 604fc7af71d0f1f3d34e166eecfc0ce275e696fd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 24 Jan 2018 21:53:27 +0100 Subject: [PATCH] Handle FirstnameInvalid error --- pyrogram/client/client.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index bcf5f994..a0b4586a 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -37,7 +37,7 @@ from pyrogram.api.errors import ( PhoneNumberUnoccupied, PhoneCodeInvalid, PhoneCodeHashEmpty, PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing, - ChatAdminRequired + ChatAdminRequired, FirstnameInvalid ) from pyrogram.api.types import ( User, Chat, Channel, @@ -215,6 +215,7 @@ class Client: phone_number_invalid_raises = self.phone_number is not None phone_code_invalid_raises = self.phone_code is not None password_hash_invalid_raises = self.password is not None + first_name_invalid_raises = self.first_name is not None while True: if self.phone_number is None: @@ -298,8 +299,8 @@ class Client: except PhoneNumberUnoccupied: pass - self.first_name = self.first_name or input("First name: ") - self.last_name = self.last_name or input("Last name: ") + self.first_name = self.first_name if self.first_name is not None else input("First name: ") + self.last_name = self.last_name if self.last_name is not None else input("Last name: ") r = self.send( functions.auth.SignUp( @@ -316,6 +317,12 @@ class Client: else: print(e.MESSAGE) self.phone_code = None + except FirstnameInvalid as e: + if first_name_invalid_raises: + raise + else: + print(e.MESSAGE) + self.first_name = None except SessionPasswordNeeded as e: print(e.MESSAGE) r = self.send(functions.account.GetPassword())