Rename methods dealing with profile pictures

This commit is contained in:
Dan 2019-05-31 00:20:09 +02:00
parent 06ad65e3a0
commit a984558860
7 changed files with 74 additions and 53 deletions

View File

@ -111,10 +111,11 @@ Users
- :meth:`~Client.get_me`
- :meth:`~Client.get_users`
- :meth:`~Client.get_user_photos`
- :meth:`~Client.get_user_photos_count`
- :meth:`~Client.set_photo`
- :meth:`~Client.delete_photos`
- :meth:`~Client.get_profile_photos`
- :meth:`~Client.get_profile_photos_count`
- :meth:`~Client.iter_profile_photos`
- :meth:`~Client.set_profile_photo`
- :meth:`~Client.delete_profile_photos`
- :meth:`~Client.update_username`
- :meth:`~Client.get_user_dc`
@ -232,10 +233,11 @@ Details
.. Users
.. automethod:: Client.get_me()
.. automethod:: Client.get_users()
.. automethod:: Client.get_user_photos()
.. automethod:: Client.get_user_photos_count()
.. automethod:: Client.set_photo()
.. automethod:: Client.delete_photos()
.. automethod:: Client.get_profile_photos()
.. automethod:: Client.get_profile_photos_count()
.. automethod:: Client.iter_profile_photos()
.. automethod:: Client.set_profile_photo()
.. automethod:: Client.delete_profile_photos()
.. automethod:: Client.update_username()
.. automethod:: Client.get_user_dc()

View File

@ -159,3 +159,6 @@ class BaseClient:
def guess_extension(self, *args, **kwargs):
pass
def get_profile_photos(self, *args, **kwargs):
pass

View File

@ -16,24 +16,26 @@
# 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 .delete_photos import DeletePhotos
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_user_photos import GetUserPhotos
from .get_user_photos_count import GetUserPhotosCount
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
class Users(
GetUserPhotos,
SetPhoto,
DeletePhotos,
GetProfilePhotos,
SetProfilePhoto,
DeleteProfilePhotos,
GetUsers,
GetMe,
UpdateUsername,
GetUserPhotosCount,
GetUserDC
GetProfilePhotosCount,
GetUserDC,
IterProfilePhotos
):
pass

View File

@ -24,8 +24,8 @@ from pyrogram.api import functions, types
from ...ext import BaseClient
class DeletePhotos(BaseClient):
def delete_photos(
class DeleteProfilePhotos(BaseClient):
def delete_profile_photos(
self,
id: Union[str, List[str]]
) -> bool:

View File

@ -19,21 +19,21 @@
from typing import Union
import pyrogram
from pyrogram.api import functions
from pyrogram.api import functions, types
from ...ext import BaseClient
class GetUserPhotos(BaseClient):
def get_user_photos(
class GetProfilePhotos(BaseClient):
def get_profile_photos(
self,
user_id: Union[int, str],
chat_id: Union[int, str],
offset: int = 0,
limit: int = 100
) -> "pyrogram.Photos":
"""Get a list of profile pictures for a user.
"""Get a list of profile pictures for a user or a chat.
Parameters:
user_id (``int`` | ``str``):
chat_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).
@ -52,14 +52,41 @@ class GetUserPhotos(BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
"""
return pyrogram.Photos._parse(
self,
self.send(
functions.photos.GetUserPhotos(
user_id=self.resolve_peer(user_id),
offset=offset,
max_id=0,
limit=limit
peer_id = self.resolve_peer(chat_id)
if isinstance(peer_id, types.InputPeerUser):
return pyrogram.Photos._parse(
self,
self.send(
functions.photos.GetUserPhotos(
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]
)

View File

@ -18,16 +18,15 @@
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class GetUserPhotosCount(BaseClient):
def get_user_photos_count(self, user_id: Union[int, str]) -> int:
class GetProfilePhotosCount(BaseClient):
def get_profile_photos_count(self, chat_id: Union[int, str]) -> int:
"""Get the total count of profile pictures for a user.
Parameters:
user_id (``int`` | ``str``):
chat_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).
@ -39,16 +38,4 @@ class GetUserPhotosCount(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
r = self.send(
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
return self.get_profile_photos(chat_id, limit=1).total_count

View File

@ -20,8 +20,8 @@ from pyrogram.api import functions
from ...ext import BaseClient
class SetPhoto(BaseClient):
def set_photo(
class SetProfilePhoto(BaseClient):
def set_profile_photo(
self,
photo: str
) -> bool: