Rename methods dealing with profile pictures
This commit is contained in:
parent
06ad65e3a0
commit
a984558860
@ -111,10 +111,11 @@ Users
|
|||||||
|
|
||||||
- :meth:`~Client.get_me`
|
- :meth:`~Client.get_me`
|
||||||
- :meth:`~Client.get_users`
|
- :meth:`~Client.get_users`
|
||||||
- :meth:`~Client.get_user_photos`
|
- :meth:`~Client.get_profile_photos`
|
||||||
- :meth:`~Client.get_user_photos_count`
|
- :meth:`~Client.get_profile_photos_count`
|
||||||
- :meth:`~Client.set_photo`
|
- :meth:`~Client.iter_profile_photos`
|
||||||
- :meth:`~Client.delete_photos`
|
- :meth:`~Client.set_profile_photo`
|
||||||
|
- :meth:`~Client.delete_profile_photos`
|
||||||
- :meth:`~Client.update_username`
|
- :meth:`~Client.update_username`
|
||||||
- :meth:`~Client.get_user_dc`
|
- :meth:`~Client.get_user_dc`
|
||||||
|
|
||||||
@ -232,10 +233,11 @@ Details
|
|||||||
.. Users
|
.. Users
|
||||||
.. automethod:: Client.get_me()
|
.. automethod:: Client.get_me()
|
||||||
.. automethod:: Client.get_users()
|
.. automethod:: Client.get_users()
|
||||||
.. automethod:: Client.get_user_photos()
|
.. automethod:: Client.get_profile_photos()
|
||||||
.. automethod:: Client.get_user_photos_count()
|
.. automethod:: Client.get_profile_photos_count()
|
||||||
.. automethod:: Client.set_photo()
|
.. automethod:: Client.iter_profile_photos()
|
||||||
.. automethod:: Client.delete_photos()
|
.. automethod:: Client.set_profile_photo()
|
||||||
|
.. automethod:: Client.delete_profile_photos()
|
||||||
.. automethod:: Client.update_username()
|
.. automethod:: Client.update_username()
|
||||||
.. automethod:: Client.get_user_dc()
|
.. automethod:: Client.get_user_dc()
|
||||||
|
|
||||||
|
@ -159,3 +159,6 @@ class BaseClient:
|
|||||||
|
|
||||||
def guess_extension(self, *args, **kwargs):
|
def guess_extension(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_profile_photos(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
@ -16,24 +16,26 @@
|
|||||||
# 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 .delete_photos import DeletePhotos
|
from .delete_profile_photos import DeleteProfilePhotos
|
||||||
from .get_me import GetMe
|
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_user_dc import GetUserDC
|
||||||
from .get_user_photos import GetUserPhotos
|
|
||||||
from .get_user_photos_count import GetUserPhotosCount
|
|
||||||
from .get_users import GetUsers
|
from .get_users import GetUsers
|
||||||
from .set_photo import SetPhoto
|
from .iter_profile_photos import IterProfilePhotos
|
||||||
|
from .set_profile_photo import SetProfilePhoto
|
||||||
from .update_username import UpdateUsername
|
from .update_username import UpdateUsername
|
||||||
|
|
||||||
|
|
||||||
class Users(
|
class Users(
|
||||||
GetUserPhotos,
|
GetProfilePhotos,
|
||||||
SetPhoto,
|
SetProfilePhoto,
|
||||||
DeletePhotos,
|
DeleteProfilePhotos,
|
||||||
GetUsers,
|
GetUsers,
|
||||||
GetMe,
|
GetMe,
|
||||||
UpdateUsername,
|
UpdateUsername,
|
||||||
GetUserPhotosCount,
|
GetProfilePhotosCount,
|
||||||
GetUserDC
|
GetUserDC,
|
||||||
|
IterProfilePhotos
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
@ -24,8 +24,8 @@ from pyrogram.api import functions, types
|
|||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class DeletePhotos(BaseClient):
|
class DeleteProfilePhotos(BaseClient):
|
||||||
def delete_photos(
|
def delete_profile_photos(
|
||||||
self,
|
self,
|
||||||
id: Union[str, List[str]]
|
id: Union[str, List[str]]
|
||||||
) -> bool:
|
) -> bool:
|
@ -19,21 +19,21 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions
|
from pyrogram.api import functions, types
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class GetUserPhotos(BaseClient):
|
class GetProfilePhotos(BaseClient):
|
||||||
def get_user_photos(
|
def get_profile_photos(
|
||||||
self,
|
self,
|
||||||
user_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
limit: int = 100
|
limit: int = 100
|
||||||
) -> "pyrogram.Photos":
|
) -> "pyrogram.Photos":
|
||||||
"""Get a list of profile pictures for a user.
|
"""Get a list of profile pictures for a user or a chat.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
user_id (``int`` | ``str``):
|
chat_id (``int`` | ``str``):
|
||||||
Unique identifier (int) or username (str) of the target chat.
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
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).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
@ -52,14 +52,41 @@ class GetUserPhotos(BaseClient):
|
|||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
return pyrogram.Photos._parse(
|
peer_id = self.resolve_peer(chat_id)
|
||||||
self,
|
|
||||||
self.send(
|
if isinstance(peer_id, types.InputPeerUser):
|
||||||
functions.photos.GetUserPhotos(
|
return pyrogram.Photos._parse(
|
||||||
user_id=self.resolve_peer(user_id),
|
self,
|
||||||
offset=offset,
|
self.send(
|
||||||
max_id=0,
|
functions.photos.GetUserPhotos(
|
||||||
limit=limit
|
user_id=peer_id,
|
||||||
|
offset=offset,
|
||||||
|
max_id=0,
|
||||||
|
limit=limit
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
else:
|
||||||
|
new_chat_photos = pyrogram.Messages._parse(
|
||||||
|
self,
|
||||||
|
self.send(
|
||||||
|
functions.messages.Search(
|
||||||
|
peer=peer_id,
|
||||||
|
q="",
|
||||||
|
filter=types.InputMessagesFilterChatPhotos(),
|
||||||
|
min_date=0,
|
||||||
|
max_date=0,
|
||||||
|
offset_id=0,
|
||||||
|
add_offset=offset,
|
||||||
|
limit=limit,
|
||||||
|
max_id=0,
|
||||||
|
min_id=0,
|
||||||
|
hash=0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return pyrogram.Photos(
|
||||||
|
total_count=new_chat_photos.total_count,
|
||||||
|
photos=[m.new_chat_photo for m in new_chat_photos.messages][:limit]
|
||||||
|
)
|
@ -18,16 +18,15 @@
|
|||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from pyrogram.api import functions, types
|
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class GetUserPhotosCount(BaseClient):
|
class GetProfilePhotosCount(BaseClient):
|
||||||
def get_user_photos_count(self, user_id: Union[int, str]) -> int:
|
def get_profile_photos_count(self, chat_id: Union[int, str]) -> int:
|
||||||
"""Get the total count of profile pictures for a user.
|
"""Get the total count of profile pictures for a user.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
user_id (``int`` | ``str``):
|
chat_id (``int`` | ``str``):
|
||||||
Unique identifier (int) or username (str) of the target chat.
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
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).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
@ -39,16 +38,4 @@ class GetUserPhotosCount(BaseClient):
|
|||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
r = self.send(
|
return self.get_profile_photos(chat_id, limit=1).total_count
|
||||||
functions.photos.GetUserPhotos(
|
|
||||||
user_id=self.resolve_peer(user_id),
|
|
||||||
offset=0,
|
|
||||||
max_id=0,
|
|
||||||
limit=1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if isinstance(r, types.photos.Photos):
|
|
||||||
return len(r.photos)
|
|
||||||
else:
|
|
||||||
return r.count
|
|
@ -20,8 +20,8 @@ from pyrogram.api import functions
|
|||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class SetPhoto(BaseClient):
|
class SetProfilePhoto(BaseClient):
|
||||||
def set_photo(
|
def set_profile_photo(
|
||||||
self,
|
self,
|
||||||
photo: str
|
photo: str
|
||||||
) -> bool:
|
) -> bool:
|
Loading…
Reference in New Issue
Block a user