2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Refactor User

This commit is contained in:
Dan 2018-12-15 17:29:51 +01:00
parent 0d0fbdad27
commit bf3609ec0a

View File

@ -16,7 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.api import types
from pyrogram.api.core import Object from pyrogram.api.core import Object
from .user_status import UserStatus
from .chat_photo import ChatPhoto
class User(Object): class User(Object):
@ -68,23 +71,11 @@ class User(Object):
ID = 0xb0700001 ID = 0xb0700001
def __init__( def __init__(self, id: int, is_self: bool, is_contact: bool, is_mutual_contact: bool, is_deleted: bool,
self, is_bot: bool, first_name: str, *,
id: int, last_name: str = None, status=None, username: str = None, language_code: str = None,
is_self: bool, phone_number: str = None, photo=None, restriction_reason: str = None,
is_contact: bool, client=None, raw=None):
is_mutual_contact: bool,
is_deleted: bool,
is_bot: bool,
first_name: str,
status=None,
last_name: str = None,
username: str = None,
language_code: str = None,
phone_number: str = None,
photo=None,
restriction_reason: str = None
):
self.id = id self.id = id
self.is_self = is_self self.is_self = is_self
self.is_contact = is_contact self.is_contact = is_contact
@ -92,10 +83,37 @@ class User(Object):
self.is_deleted = is_deleted self.is_deleted = is_deleted
self.is_bot = is_bot self.is_bot = is_bot
self.first_name = first_name self.first_name = first_name
self.status = status
self.last_name = last_name self.last_name = last_name
self.status = status
self.username = username self.username = username
self.language_code = language_code self.language_code = language_code
self.phone_number = phone_number self.phone_number = phone_number
self.photo = photo self.photo = photo
self.restriction_reason = restriction_reason self.restriction_reason = restriction_reason
self._client = client
self._raw = raw
@staticmethod
def parse(client, user: types.User) -> "User" or None:
if user is None:
return None
return User(
id=user.id,
is_self=user.is_self,
is_contact=user.contact,
is_mutual_contact=user.mutual_contact,
is_deleted=user.deleted,
is_bot=user.bot,
first_name=user.first_name,
last_name=user.last_name,
status=UserStatus.parse(client, user),
username=user.username,
language_code=user.lang_code,
phone_number=user.phone,
photo=ChatPhoto.parse(client, user.photo),
restriction_reason=user.restriction_reason,
client=client, raw=user
)