mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-30 17:43:32 +00:00
Remove get_user_dc method, add dc_id attribute to User
This commit is contained in:
parent
e41d21ba29
commit
d119998212
@ -214,7 +214,6 @@ def pyrogram_api():
|
||||
set_profile_photo
|
||||
delete_profile_photos
|
||||
update_username
|
||||
get_user_dc
|
||||
block_user
|
||||
unblock_user
|
||||
""",
|
||||
|
@ -21,7 +21,6 @@ from .delete_profile_photos import DeleteProfilePhotos
|
||||
from .get_me import GetMe
|
||||
from .get_profile_photos import GetProfilePhotos
|
||||
from .get_profile_photos_count import GetProfilePhotosCount
|
||||
from .get_user_dc import GetUserDC
|
||||
from .get_users import GetUsers
|
||||
from .iter_profile_photos import IterProfilePhotos
|
||||
from .set_profile_photo import SetProfilePhoto
|
||||
@ -38,7 +37,6 @@ class Users(
|
||||
GetMe,
|
||||
UpdateUsername,
|
||||
GetProfilePhotosCount,
|
||||
GetUserDC,
|
||||
IterProfilePhotos,
|
||||
UnblockUser
|
||||
):
|
||||
|
@ -1,58 +0,0 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram 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.
|
||||
#
|
||||
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Union
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from ...ext import BaseClient
|
||||
|
||||
|
||||
class GetUserDC(BaseClient):
|
||||
def get_user_dc(self, user_id: Union[int, str]) -> Union[int, None]:
|
||||
"""Get the assigned DC (data center) of a user.
|
||||
|
||||
.. note::
|
||||
|
||||
This information is approximate: it is based on where Telegram stores a user profile pictures and does not
|
||||
by any means tell you the user location (i.e. a user might travel far away, but will still connect to its
|
||||
assigned DC). More info at `FAQs <../faq#what-are-the-ip-addresses-of-telegram-data-centers>`_.
|
||||
|
||||
Parameters:
|
||||
user_id (``int`` | ``str``):
|
||||
Unique identifier (int) or username (str) of the target chat.
|
||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||
|
||||
Returns:
|
||||
``int`` | ``None``: The DC identifier as integer, or None in case it wasn't possible to get it (i.e. the
|
||||
user has no profile picture or has the privacy setting enabled).
|
||||
|
||||
Raises:
|
||||
RPCError: In case of a Telegram RPC error.
|
||||
"""
|
||||
|
||||
r = self.send(functions.users.GetUsers(id=[self.resolve_peer(user_id)]))
|
||||
|
||||
if r:
|
||||
r = r[0]
|
||||
|
||||
if r.photo:
|
||||
if isinstance(r.photo, types.UserProfilePhoto):
|
||||
return r.photo.dc_id
|
||||
|
||||
return None
|
@ -75,6 +75,12 @@ class User(Object):
|
||||
language_code (``str``, *optional*):
|
||||
IETF language tag of the user's language.
|
||||
|
||||
dc_id (``int``, *optional*):
|
||||
User's or bot's assigned DC (data center). Available only in case the user has set a public profile photo.
|
||||
Note that this information is approximate: it is based on where Telegram stores a user profile pictures and
|
||||
does not by any means tell you the user location (i.e. a user might travel far away, but will still connect
|
||||
to its assigned DC). More info at `FAQs </faq#what-are-the-ip-addresses-of-telegram-data-centers>`_.
|
||||
|
||||
phone_number (``str``, *optional*):
|
||||
User's phone number.
|
||||
|
||||
@ -88,8 +94,8 @@ class User(Object):
|
||||
|
||||
__slots__ = [
|
||||
"id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "is_verified", "is_restricted",
|
||||
"is_scam", "is_support", "first_name", "last_name", "status", "username", "language_code", "phone_number",
|
||||
"photo", "restriction_reason"
|
||||
"is_scam", "is_support", "first_name", "last_name", "status", "username", "language_code", "dc_id",
|
||||
"phone_number", "photo", "restriction_reason"
|
||||
]
|
||||
|
||||
def __init__(
|
||||
@ -111,6 +117,7 @@ class User(Object):
|
||||
status: UserStatus = None,
|
||||
username: str = None,
|
||||
language_code: str = None,
|
||||
dc_id: int = None,
|
||||
phone_number: str = None,
|
||||
photo: ChatPhoto = None,
|
||||
restriction_reason: str = None
|
||||
@ -132,6 +139,7 @@ class User(Object):
|
||||
self.status = status
|
||||
self.username = username
|
||||
self.language_code = language_code
|
||||
self.dc_id = dc_id
|
||||
self.phone_number = phone_number
|
||||
self.photo = photo
|
||||
self.restriction_reason = restriction_reason
|
||||
@ -163,6 +171,7 @@ class User(Object):
|
||||
status=UserStatus._parse(client, user.status, user.id, user.bot),
|
||||
username=user.username,
|
||||
language_code=user.lang_code,
|
||||
dc_id=getattr(user.photo, "dc_id", None),
|
||||
phone_number=user.phone,
|
||||
photo=ChatPhoto._parse(client, user.photo, user.id),
|
||||
restriction_reason=user.restriction_reason,
|
||||
@ -238,7 +247,6 @@ class User(Object):
|
||||
|
||||
return self._client.block_user(self.id)
|
||||
|
||||
|
||||
def unblock(self):
|
||||
"""Bound method *unblock* of :obj:`User`.
|
||||
|
||||
@ -261,4 +269,3 @@ class User(Object):
|
||||
"""
|
||||
|
||||
return self._client.unblock_user(self.id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user