From 2db2ca3283ed433e4e8be5512eca1b0fc571a987 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 13:49:01 +0200 Subject: [PATCH 1/9] Remove ChatMembers type --- docs/source/api/types.rst | 2 - .../client/methods/chats/get_chat_member.py | 9 ++- .../client/methods/chats/get_chat_members.py | 48 +++++++------ .../client/methods/chats/iter_chat_members.py | 2 +- pyrogram/client/types/__init__.py | 2 + .../client/types/user_and_chats/__init__.py | 4 +- .../types/user_and_chats/chat_members.py | 71 ------------------- 7 files changed, 38 insertions(+), 100 deletions(-) delete mode 100644 pyrogram/client/types/user_and_chats/chat_members.py diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 4eef9638..0aab7b5e 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -30,7 +30,6 @@ Users & Chats - :class:`ChatPreview` - :class:`ChatPhoto` - :class:`ChatMember` - - :class:`ChatMembers` - :class:`ChatPermissions` - :class:`Dialog` - :class:`Dialogs` @@ -123,7 +122,6 @@ Details .. autoclass:: ChatPreview() .. autoclass:: ChatPhoto() .. autoclass:: ChatMember() -.. autoclass:: ChatMembers() .. autoclass:: ChatPermissions() .. autoclass:: Dialog() .. autoclass:: Dialogs() diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index b84836c6..b0d0641a 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -51,13 +51,18 @@ class GetChatMember(BaseClient): user = self.resolve_peer(user_id) if isinstance(chat, types.InputPeerChat): - full_chat = self.send( + r = self.send( functions.messages.GetFullChat( chat_id=chat.chat_id ) ) - for member in pyrogram.ChatMembers._parse(self, full_chat).chat_members: + members = r.full_chat.participants.participants + users = {i.id: i for i in r.users} + + for member in members: + member = pyrogram.ChatMember._parse(self, member, users) + if isinstance(user, types.InputPeerSelf): if member.user.is_self: return member diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 1c966f36..0b4613d8 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -18,7 +18,7 @@ import logging import time -from typing import Union +from typing import Union, List import pyrogram from pyrogram.api import functions, types @@ -45,7 +45,7 @@ class GetChatMembers(BaseClient): limit: int = 200, query: str = "", filter: str = Filters.ALL - ) -> "pyrogram.ChatMembers": + ) -> List["pyrogram.ChatMember"]: """Get a chunk of the members list of a chat. You can get up to 200 chat members at once. @@ -59,15 +59,16 @@ class GetChatMembers(BaseClient): offset (``int``, *optional*): Sequential number of the first member to be returned. - Defaults to 0 [1]_. + Only applicable to supergroups and channels. Defaults to 0 [1]_. limit (``int``, *optional*): Limits the number of members to be retrieved. + Only applicable to supergroups and channels. Defaults to 200, which is also the maximum server limit allowed per method call. query (``str``, *optional*): Query string to filter members based on their display names and usernames. - Defaults to "" (empty string) [2]_. + Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_. filter (``str``, *optional*): Filter used to select the kind of members you want to retrieve. Only applicable for supergroups @@ -78,6 +79,7 @@ class GetChatMembers(BaseClient): *"bots"* - bots only, *"recent"* - recent members only, *"administrators"* - chat administrators only. + Only applicable to supergroups and channels. Defaults to *"all"*. .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members @@ -86,7 +88,7 @@ class GetChatMembers(BaseClient): .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. Returns: - :obj:`ChatMembers`: On success, an object containing a list of chat members is returned. + List of :obj:`ChatMember`: On success, a list of chat members is returned. Raises: RPCError: In case of a Telegram RPC error. @@ -95,14 +97,16 @@ class GetChatMembers(BaseClient): peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): - return pyrogram.ChatMembers._parse( - self, - self.send( - functions.messages.GetFullChat( - chat_id=peer.chat_id - ) + r = self.send( + functions.messages.GetFullChat( + chat_id=peer.chat_id ) ) + + members = r.full_chat.participants.participants + users = {i.id: i for i in r.users} + + return pyrogram.List(pyrogram.ChatMember._parse(self, member, users) for member in members) elif isinstance(peer, types.InputPeerChannel): filter = filter.lower() @@ -123,18 +127,20 @@ class GetChatMembers(BaseClient): while True: try: - return pyrogram.ChatMembers._parse( - self, - self.send( - functions.channels.GetParticipants( - channel=peer, - filter=filter, - offset=offset, - limit=limit, - hash=0 - ) + r = self.send( + functions.channels.GetParticipants( + channel=peer, + filter=filter, + offset=offset, + limit=limit, + hash=0 ) ) + + members = r.participants + users = {i.id: i for i in r.users} + + return pyrogram.List(pyrogram.ChatMember._parse(self, member, users) for member in members) except FloodWait as e: log.warning("Sleeping for {}s".format(e.x)) time.sleep(e.x) diff --git a/pyrogram/client/methods/chats/iter_chat_members.py b/pyrogram/client/methods/chats/iter_chat_members.py index 961f6d98..fe117694 100644 --- a/pyrogram/client/methods/chats/iter_chat_members.py +++ b/pyrogram/client/methods/chats/iter_chat_members.py @@ -106,7 +106,7 @@ class IterChatMembers(BaseClient): limit=limit, query=q, filter=filter - ).chat_members + ) if not chat_members: break diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 3d430c44..8a725a9e 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -20,6 +20,8 @@ from .keyboards import * from .inline_mode import * from .input_media import * from .input_message_content import * +from .list import List from .messages_and_media import * +from .object import Object from .update import * from .user_and_chats import * diff --git a/pyrogram/client/types/user_and_chats/__init__.py b/pyrogram/client/types/user_and_chats/__init__.py index 2059589a..cf032850 100644 --- a/pyrogram/client/types/user_and_chats/__init__.py +++ b/pyrogram/client/types/user_and_chats/__init__.py @@ -18,7 +18,6 @@ from .chat import Chat from .chat_member import ChatMember -from .chat_members import ChatMembers from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .chat_preview import ChatPreview @@ -28,6 +27,5 @@ from .user import User from .user_status import UserStatus __all__ = [ - "Chat", "ChatMember", "ChatMembers", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", - "UserStatus" + "Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", "UserStatus" ] diff --git a/pyrogram/client/types/user_and_chats/chat_members.py b/pyrogram/client/types/user_and_chats/chat_members.py deleted file mode 100644 index 6abdd719..00000000 --- a/pyrogram/client/types/user_and_chats/chat_members.py +++ /dev/null @@ -1,71 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2019 Dan Tès -# -# 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 . - -from typing import List - -import pyrogram -from pyrogram.api import types -from .chat_member import ChatMember -from ..object import Object - - -class ChatMembers(Object): - """Contains information about the members list of a chat. - - Parameters: - total_count (``int``): - Total number of members the chat has. - - chat_members (List of :obj:`ChatMember `): - Requested chat members. - """ - - __slots__ = ["total_count", "chat_members"] - - def __init__( - self, - *, - client: "pyrogram.BaseClient" = None, - total_count: int, - chat_members: List[ChatMember] - ): - super().__init__(client) - - self.total_count = total_count - self.chat_members = chat_members - - @staticmethod - def _parse(client, members): - users = {i.id: i for i in members.users} - chat_members = [] - - if isinstance(members, types.channels.ChannelParticipants): - total_count = members.count - members = members.participants - else: - members = members.full_chat.participants.participants - total_count = len(members) - - for member in members: - chat_members.append(ChatMember._parse(client, member, users)) - - return ChatMembers( - total_count=total_count, - chat_members=chat_members, - client=client - ) From c8fd446cb6185b52d9da9090a2c4b9811dd9162a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 14:00:00 +0200 Subject: [PATCH 2/9] Remove Dialogs type --- docs/source/api/types.rst | 2 - pyrogram/client/methods/chats/get_dialogs.py | 35 +++++++- pyrogram/client/methods/chats/iter_dialogs.py | 4 +- .../client/types/user_and_chats/__init__.py | 3 +- .../client/types/user_and_chats/dialogs.py | 87 ------------------- 5 files changed, 35 insertions(+), 96 deletions(-) delete mode 100644 pyrogram/client/types/user_and_chats/dialogs.py diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 0aab7b5e..957cfa52 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -32,7 +32,6 @@ Users & Chats - :class:`ChatMember` - :class:`ChatPermissions` - :class:`Dialog` - - :class:`Dialogs` Messages & Media ^^^^^^^^^^^^^^^^ @@ -124,7 +123,6 @@ Details .. autoclass:: ChatMember() .. autoclass:: ChatPermissions() .. autoclass:: Dialog() -.. autoclass:: Dialogs() .. Messages & Media .. autoclass:: Message() diff --git a/pyrogram/client/methods/chats/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py index 8d5baa15..8c374a44 100644 --- a/pyrogram/client/methods/chats/get_dialogs.py +++ b/pyrogram/client/methods/chats/get_dialogs.py @@ -18,6 +18,7 @@ import logging import time +from typing import List import pyrogram from pyrogram.api import functions, types @@ -33,7 +34,7 @@ class GetDialogs(BaseClient): offset_date: int = 0, limit: int = 100, pinned_only: bool = False - ) -> "pyrogram.Dialogs": + ) -> List["pyrogram.Dialog"]: """Get a chunk of the user's dialogs. You can get up to 100 dialogs at once. @@ -53,7 +54,7 @@ class GetDialogs(BaseClient): Defaults to False. Returns: - :obj:`Dialogs`: On success, an object containing a list of dialogs is returned. + List of :obj:`Dialog`: On success, a list of dialogs is returned. Raises: RPCError: In case of a Telegram RPC error. @@ -80,4 +81,32 @@ class GetDialogs(BaseClient): else: break - return pyrogram.Dialogs._parse(self, r) + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + + messages = {} + + for message in r.messages: + to_id = message.to_id + + if isinstance(to_id, types.PeerUser): + if message.out: + chat_id = to_id.user_id + else: + chat_id = message.from_id + elif isinstance(to_id, types.PeerChat): + chat_id = -to_id.chat_id + else: + chat_id = int("-100" + str(to_id.channel_id)) + + messages[chat_id] = pyrogram.Message._parse(self, message, users, chats) + + parsed_dialogs = [] + + for dialog in r.dialogs: + if not isinstance(dialog, types.Dialog): + continue + + parsed_dialogs.append(pyrogram.Dialog._parse(self, dialog, messages, users, chats)) + + return pyrogram.List(parsed_dialogs) diff --git a/pyrogram/client/methods/chats/iter_dialogs.py b/pyrogram/client/methods/chats/iter_dialogs.py index e7fb7330..fce9fb99 100644 --- a/pyrogram/client/methods/chats/iter_dialogs.py +++ b/pyrogram/client/methods/chats/iter_dialogs.py @@ -55,7 +55,7 @@ class IterDialogs(BaseClient): pinned_dialogs = self.get_dialogs( pinned_only=True - ).dialogs + ) for dialog in pinned_dialogs: yield dialog @@ -69,7 +69,7 @@ class IterDialogs(BaseClient): dialogs = self.get_dialogs( offset_date=offset_date, limit=limit - ).dialogs + ) if not dialogs: return diff --git a/pyrogram/client/types/user_and_chats/__init__.py b/pyrogram/client/types/user_and_chats/__init__.py index cf032850..922ac86a 100644 --- a/pyrogram/client/types/user_and_chats/__init__.py +++ b/pyrogram/client/types/user_and_chats/__init__.py @@ -22,10 +22,9 @@ from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .chat_preview import ChatPreview from .dialog import Dialog -from .dialogs import Dialogs from .user import User from .user_status import UserStatus __all__ = [ - "Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", "UserStatus" + "Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "User", "UserStatus" ] diff --git a/pyrogram/client/types/user_and_chats/dialogs.py b/pyrogram/client/types/user_and_chats/dialogs.py deleted file mode 100644 index 56cdfc72..00000000 --- a/pyrogram/client/types/user_and_chats/dialogs.py +++ /dev/null @@ -1,87 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2019 Dan Tès -# -# 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 . - -from typing import List - -import pyrogram -from pyrogram.api import types -from .dialog import Dialog -from ..messages_and_media import Message -from ..object import Object - - -class Dialogs(Object): - """Contains a user's dialogs chunk. - - Parameters: - total_count (``int``): - Total number of dialogs the user has. - - dialogs (List of :obj:`Dialog`): - Requested dialogs. - """ - - __slots__ = ["total_count", "dialogs"] - - def __init__( - self, - *, - client: "pyrogram.BaseClient" = None, - total_count: int, - dialogs: List[Dialog] - ): - super().__init__(client) - - self.total_count = total_count - self.dialogs = dialogs - - @staticmethod - def _parse(client, dialogs: types.messages.Dialogs) -> "Dialogs": - users = {i.id: i for i in dialogs.users} - chats = {i.id: i for i in dialogs.chats} - - messages = {} - - for message in dialogs.messages: - to_id = message.to_id - - if isinstance(to_id, types.PeerUser): - if message.out: - chat_id = to_id.user_id - else: - chat_id = message.from_id - elif isinstance(to_id, types.PeerChat): - chat_id = -to_id.chat_id - else: - chat_id = int("-100" + str(to_id.channel_id)) - - messages[chat_id] = Message._parse(client, message, users, chats) - - parsed_dialogs = [] - - for dialog in dialogs.dialogs: - if not isinstance(dialog, types.Dialog): - continue - - parsed_dialogs.append(Dialog._parse(client, dialog, messages, users, chats)) - - return Dialogs( - total_count=getattr(dialogs, "count", len(dialogs.dialogs)), - dialogs=parsed_dialogs, - client=client - ) From 797de058e8cbaa0128d6879f390c658f550f2872 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 14:08:39 +0200 Subject: [PATCH 3/9] Remove ProfilePhotos type --- docs/source/api/types.rst | 2 - .../methods/users/get_profile_photos.py | 28 ++++----- .../methods/users/iter_profile_photos.py | 2 +- .../types/messages_and_media/__init__.py | 4 +- .../messages_and_media/profile_photos.py | 57 ------------------- 5 files changed, 14 insertions(+), 79 deletions(-) delete mode 100644 pyrogram/client/types/messages_and_media/profile_photos.py diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 957cfa52..a18e01a6 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -43,7 +43,6 @@ Messages & Media - :class:`Messages` - :class:`MessageEntity` - :class:`Photo` - - :class:`ProfilePhotos` - :class:`Thumbnail` - :class:`Audio` - :class:`Document` @@ -129,7 +128,6 @@ Details .. autoclass:: Messages() .. autoclass:: MessageEntity() .. autoclass:: Photo() -.. autoclass:: ProfilePhotos() .. autoclass:: Thumbnail() .. autoclass:: Audio() .. autoclass:: Document() diff --git a/pyrogram/client/methods/users/get_profile_photos.py b/pyrogram/client/methods/users/get_profile_photos.py index e4e202e0..32e7e513 100644 --- a/pyrogram/client/methods/users/get_profile_photos.py +++ b/pyrogram/client/methods/users/get_profile_photos.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union +from typing import Union, List import pyrogram from pyrogram.api import functions, types @@ -29,7 +29,7 @@ class GetProfilePhotos(BaseClient): chat_id: Union[int, str], offset: int = 0, limit: int = 100 - ) -> "pyrogram.ProfilePhotos": + ) -> List["pyrogram.Photo"]: """Get a list of profile pictures for a user or a chat. Parameters: @@ -47,7 +47,7 @@ class GetProfilePhotos(BaseClient): Values between 1—100 are accepted. Defaults to 100. Returns: - :obj:`ProfilePhotos`: On success, an object containing a list of the profile photos is returned. + List of :obj:`Photo`: On success, a list of profile photos is returned. Raises: RPCError: In case of a Telegram RPC error. @@ -55,17 +55,16 @@ class GetProfilePhotos(BaseClient): peer_id = self.resolve_peer(chat_id) if isinstance(peer_id, types.InputPeerUser): - return pyrogram.ProfilePhotos._parse( - self, - self.send( - functions.photos.GetUserPhotos( - user_id=peer_id, - offset=offset, - max_id=0, - limit=limit - ) + r = self.send( + functions.photos.GetUserPhotos( + user_id=peer_id, + offset=offset, + max_id=0, + limit=limit ) ) + + return pyrogram.List(pyrogram.Photo._parse(self, photo) for photo in r.photos) else: new_chat_photos = pyrogram.Messages._parse( self, @@ -86,7 +85,4 @@ class GetProfilePhotos(BaseClient): ) ) - return pyrogram.ProfilePhotos( - total_count=new_chat_photos.total_count, - profile_photos=[m.new_chat_photo for m in new_chat_photos.messages][:limit] - ) + return pyrogram.List([m.new_chat_photo for m in new_chat_photos.messages][:limit]) diff --git a/pyrogram/client/methods/users/iter_profile_photos.py b/pyrogram/client/methods/users/iter_profile_photos.py index 1773634e..49317f87 100644 --- a/pyrogram/client/methods/users/iter_profile_photos.py +++ b/pyrogram/client/methods/users/iter_profile_photos.py @@ -63,7 +63,7 @@ class IterProfilePhotos(BaseClient): chat_id=chat_id, offset=offset, limit=limit - ).photos + ) if not photos: return diff --git a/pyrogram/client/types/messages_and_media/__init__.py b/pyrogram/client/types/messages_and_media/__init__.py index 17a6e36a..2de2c6a3 100644 --- a/pyrogram/client/types/messages_and_media/__init__.py +++ b/pyrogram/client/types/messages_and_media/__init__.py @@ -28,7 +28,6 @@ from .messages import Messages from .photo import Photo from .poll import Poll from .poll_option import PollOption -from .profile_photos import ProfilePhotos from .sticker import Sticker from .stripped_thumbnail import StrippedThumbnail from .thumbnail import Thumbnail @@ -39,6 +38,5 @@ from .voice import Voice __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Messages", "Photo", - "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "ProfilePhotos", "Venue", "Video", "VideoNote", - "Voice" + "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice" ] diff --git a/pyrogram/client/types/messages_and_media/profile_photos.py b/pyrogram/client/types/messages_and_media/profile_photos.py deleted file mode 100644 index 11b8e4dd..00000000 --- a/pyrogram/client/types/messages_and_media/profile_photos.py +++ /dev/null @@ -1,57 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2019 Dan Tès -# -# 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 . - -from typing import List - -import pyrogram -from .photo import Photo -from ..object import Object - - -class ProfilePhotos(Object): - """Contains a user's profile pictures. - - Parameters: - total_count (``int``): - Total number of profile pictures the target user has. - - profile_photos (List of :obj:`Photo`): - Requested profile pictures. - """ - - __slots__ = ["total_count", "profile_photos"] - - def __init__( - self, - *, - client: "pyrogram.BaseClient" = None, - total_count: int, - profile_photos: List[Photo] - ): - super().__init__(client) - - self.total_count = total_count - self.profile_photos = profile_photos - - @staticmethod - def _parse(client, photos) -> "ProfilePhotos": - return ProfilePhotos( - total_count=getattr(photos, "count", len(photos.photos)), - profile_photos=[Photo._parse(client, photo) for photo in photos.photos], - client=client - ) From cfbc5298dfaad33fa537839f909fef1b81200980 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:13:52 +0200 Subject: [PATCH 4/9] Remove Messages type --- docs/source/api/types.rst | 2 - pyrogram/client/ext/dispatcher.py | 3 +- pyrogram/client/ext/utils.py | 58 +++++- .../handlers/deleted_messages_handler.py | 13 +- .../methods/messages/forward_messages.py | 26 +-- .../client/methods/messages/get_history.py | 13 +- .../client/methods/messages/get_messages.py | 16 +- .../client/methods/messages/iter_history.py | 2 +- .../methods/messages/send_media_group.py | 6 +- .../methods/users/get_profile_photos.py | 5 +- .../types/messages_and_media/__init__.py | 5 +- .../types/messages_and_media/message.py | 2 +- .../types/messages_and_media/messages.py | 170 ------------------ 13 files changed, 100 insertions(+), 221 deletions(-) delete mode 100644 pyrogram/client/types/messages_and_media/messages.py diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index a18e01a6..66d409c4 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -40,7 +40,6 @@ Messages & Media :columns: 5 - :class:`Message` - - :class:`Messages` - :class:`MessageEntity` - :class:`Photo` - :class:`Thumbnail` @@ -125,7 +124,6 @@ Details .. Messages & Media .. autoclass:: Message() -.. autoclass:: Messages() .. autoclass:: MessageEntity() .. autoclass:: Photo() .. autoclass:: Thumbnail() diff --git a/pyrogram/client/ext/dispatcher.py b/pyrogram/client/ext/dispatcher.py index 2f1ec2b9..12d5a5de 100644 --- a/pyrogram/client/ext/dispatcher.py +++ b/pyrogram/client/ext/dispatcher.py @@ -21,6 +21,7 @@ import threading from collections import OrderedDict from queue import Queue from threading import Thread +from . import utils import pyrogram from pyrogram.api import types @@ -68,7 +69,7 @@ class Dispatcher: lambda upd, usr, cht: (pyrogram.Message._parse(self.client, upd.message, usr, cht), MessageHandler), Dispatcher.DELETE_MESSAGES_UPDATES: - lambda upd, usr, cht: (pyrogram.Messages._parse_deleted(self.client, upd), DeletedMessagesHandler), + lambda upd, usr, cht: (utils.parse_deleted_messages(self.client, upd), DeletedMessagesHandler), Dispatcher.CALLBACK_QUERY_UPDATES: lambda upd, usr, cht: (pyrogram.CallbackQuery._parse(self.client, upd, usr), CallbackQueryHandler), diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index e1959309..41270d39 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -18,8 +18,9 @@ import struct from base64 import b64decode, b64encode -from typing import Union +from typing import Union, List +import pyrogram from . import BaseClient from ...api import types @@ -135,3 +136,58 @@ def get_input_media_from_file_id( ) raise ValueError("Unknown media type: {}".format(file_id_str)) + + +def parse_messages(client, messages: types.messages.Messages, replies: int = 1) -> List["pyrogram.Message"]: + users = {i.id: i for i in messages.users} + chats = {i.id: i for i in messages.chats} + + if not messages.messages: + return pyrogram.List() + + parsed_messages = [ + pyrogram.Message._parse(client, message, users, chats, replies=0) + for message in messages.messages + ] + + if replies: + messages_with_replies = {i.id: getattr(i, "reply_to_msg_id", None) for i in messages.messages} + reply_message_ids = [i[0] for i in filter(lambda x: x[1] is not None, messages_with_replies.items())] + + if reply_message_ids: + reply_messages = client.get_messages( + parsed_messages[0].chat.id, + reply_to_message_ids=reply_message_ids, + replies=replies - 1 + ) + + for message in parsed_messages: + reply_id = messages_with_replies[message.message_id] + + for reply in reply_messages: + if reply.message_id == reply_id: + message.reply_to_message = reply + + return pyrogram.List(parsed_messages) + + +def parse_deleted_messages(client, update) -> List["pyrogram.Message"]: + messages = update.messages + channel_id = getattr(update, "channel_id", None) + + parsed_messages = [] + + for message in messages: + parsed_messages.append( + pyrogram.Message( + message_id=message, + chat=pyrogram.Chat( + id=int("-100" + str(channel_id)), + type="channel", + client=client + ) if channel_id is not None else None, + client=client + ) + ) + + return pyrogram.List(parsed_messages) diff --git a/pyrogram/client/handlers/deleted_messages_handler.py b/pyrogram/client/handlers/deleted_messages_handler.py index b6651fba..3230b9bd 100644 --- a/pyrogram/client/handlers/deleted_messages_handler.py +++ b/pyrogram/client/handlers/deleted_messages_handler.py @@ -20,16 +20,15 @@ from .handler import Handler class DeletedMessagesHandler(Handler): - """The deleted Messages handler class. Used to handle deleted messages coming from any chat - (private, group, channel). It is intended to be used with - :meth:`~Client.add_handler` + """The deleted messages handler class. Used to handle deleted messages coming from any chat + (private, group, channel). It is intended to be used with :meth:`~Client.add_handler` For a nicer way to register this handler, have a look at the :meth:`~Client.on_deleted_messages` decorator. Parameters: callback (``callable``): - Pass a function that will be called when one or more Messages have been deleted. + Pass a function that will be called when one or more messages have been deleted. It takes *(client, messages)* as positional arguments (look at the section below for a detailed description). filters (:obj:`Filters`): @@ -40,12 +39,12 @@ class DeletedMessagesHandler(Handler): client (:obj:`Client`): The Client itself, useful when you want to call other API methods inside the message handler. - messages (:obj:`Messages`): - The deleted messages. + messages (List of :obj:`Message`): + The deleted messages, as list. """ def __init__(self, callback: callable, filters=None): super().__init__(callback, filters) def check(self, messages): - return super().check(messages.messages[0]) + return super().check(messages[0]) diff --git a/pyrogram/client/methods/messages/forward_messages.py b/pyrogram/client/methods/messages/forward_messages.py index bc9ad331..c69df608 100644 --- a/pyrogram/client/methods/messages/forward_messages.py +++ b/pyrogram/client/methods/messages/forward_messages.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union, Iterable +from typing import Union, Iterable, List import pyrogram from pyrogram.api import functions, types @@ -32,7 +32,7 @@ class ForwardMessages(BaseClient): disable_notification: bool = None, as_copy: bool = False, remove_caption: bool = False - ) -> "pyrogram.Messages": + ) -> List["pyrogram.Message"]: """Forward messages of any kind. Parameters: @@ -64,9 +64,9 @@ class ForwardMessages(BaseClient): Defaults to False. Returns: - :obj:`Message` | :obj:`Messages`: In case *message_ids* was an integer, the single forwarded message is - returned, otherwise, in case *message_ids* was an iterable, the returned value will be an object containing - a list of messages, even if such iterable contained just a single element. + :obj:`Message` | List of :obj:`Message`: In case *message_ids* was an integer, the single forwarded message + is returned, otherwise, in case *message_ids* was an iterable, the returned value will be a list of + messages, even if such iterable contained just a single element. Raises: RPCError: In case of a Telegram RPC error. @@ -79,9 +79,9 @@ class ForwardMessages(BaseClient): forwarded_messages = [] for chunk in [message_ids[i:i + 200] for i in range(0, len(message_ids), 200)]: - messages = self.get_messages(chat_id=from_chat_id, message_ids=chunk) # type: pyrogram.Messages + messages = self.get_messages(chat_id=from_chat_id, message_ids=chunk) - for message in messages.messages: + for message in messages: forwarded_messages.append( message.forward( chat_id, @@ -91,11 +91,7 @@ class ForwardMessages(BaseClient): ) ) - return pyrogram.Messages( - client=self, - total_count=len(forwarded_messages), - messages=forwarded_messages - ) if is_iterable else forwarded_messages[0] + return pyrogram.List(forwarded_messages) if is_iterable else forwarded_messages[0] else: r = self.send( functions.messages.ForwardMessages( @@ -121,8 +117,4 @@ class ForwardMessages(BaseClient): ) ) - return pyrogram.Messages( - client=self, - total_count=len(forwarded_messages), - messages=forwarded_messages - ) if is_iterable else forwarded_messages[0] + return pyrogram.List(forwarded_messages) if is_iterable else forwarded_messages[0] diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py index c0810474..8adafe22 100644 --- a/pyrogram/client/methods/messages/get_history.py +++ b/pyrogram/client/methods/messages/get_history.py @@ -18,10 +18,11 @@ import logging import time -from typing import Union +from typing import Union, List import pyrogram from pyrogram.api import functions +from pyrogram.client.ext import utils from pyrogram.errors import FloodWait from ...ext import BaseClient @@ -37,7 +38,7 @@ class GetHistory(BaseClient): offset_id: int = 0, offset_date: int = 0, reverse: bool = False - ) -> "pyrogram.Messages": + ) -> List["pyrogram.Message"]: """Retrieve a chunk of the history of a chat. You can get up to 100 messages at once. @@ -67,15 +68,17 @@ class GetHistory(BaseClient): Pass True to retrieve the messages in reversed order (from older to most recent). Returns: - :obj:`Messages` - On success, an object containing a list of the retrieved messages. + List of :obj:`Message` - On success, a list of the retrieved messages is returned. Raises: RPCError: In case of a Telegram RPC error. """ + offset_id = offset_id or (1 if reverse else 0) + while True: try: - messages = pyrogram.Messages._parse( + messages = utils.parse_messages( self, self.send( functions.messages.GetHistory( @@ -97,6 +100,6 @@ class GetHistory(BaseClient): break if reverse: - messages.messages.reverse() + messages.reverse() return messages diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 7a60f276..0f901174 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -18,12 +18,12 @@ import logging import time -from typing import Union, Iterable +from typing import Union, Iterable, List import pyrogram from pyrogram.api import functions, types from pyrogram.errors import FloodWait -from ...ext import BaseClient +from ...ext import BaseClient, utils log = logging.getLogger(__name__) @@ -35,7 +35,7 @@ class GetMessages(BaseClient): message_ids: Union[int, Iterable[int]] = None, reply_to_message_ids: Union[int, Iterable[int]] = None, replies: int = 1 - ) -> Union["pyrogram.Message", "pyrogram.Messages"]: + ) -> Union["pyrogram.Message", List["pyrogram.Message"]]: """Get one or more messages that belong to a specific chat. You can retrieve up to 200 messages at once. @@ -60,9 +60,9 @@ class GetMessages(BaseClient): Defaults to 1. Returns: - :obj:`Message` | :obj:`Messages`: In case *message_ids* was an integer, the single requested message is - returned, otherwise, in case *message_ids* was an iterable, the returned value will be an object containing - a list of messages, even if such iterable contained just a single element. + :obj:`Message` | List of :obj:`Message`: In case *message_ids* was an integer, the single requested message is + returned, otherwise, in case *message_ids* was an iterable, the returned value will be a list of messages, + even if such iterable contained just a single element. Raises: RPCError: In case of a Telegram RPC error. @@ -99,6 +99,6 @@ class GetMessages(BaseClient): else: break - messages = pyrogram.Messages._parse(self, r, replies=replies) + messages = utils.parse_messages(self, r, replies=replies) - return messages if is_iterable else messages.messages[0] + return messages if is_iterable else messages[0] diff --git a/pyrogram/client/methods/messages/iter_history.py b/pyrogram/client/methods/messages/iter_history.py index 57da3da5..15c48c95 100644 --- a/pyrogram/client/methods/messages/iter_history.py +++ b/pyrogram/client/methods/messages/iter_history.py @@ -80,7 +80,7 @@ class IterHistory(BaseClient): offset_id=offset_id, offset_date=offset_date, reverse=reverse - ).messages + ) if not messages: return diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index fb029a66..194a2202 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -38,7 +38,7 @@ class SendMediaGroup(BaseClient): media: List[Union["pyrogram.InputMediaPhoto", "pyrogram.InputMediaVideo"]], disable_notification: bool = None, reply_to_message_id: int = None - ): + ) -> List["pyrogram.Message"]: """Send a group of photos or videos as an album. Parameters: @@ -58,7 +58,7 @@ class SendMediaGroup(BaseClient): If the message is a reply, ID of the original message. Returns: - :obj:`Messages`: On success, an object is returned containing all the single messages sent. + List of :obj:`Message`: On success, a list of the sent messages is returned. Raises: RPCError: In case of a Telegram RPC error. @@ -158,7 +158,7 @@ class SendMediaGroup(BaseClient): else: break - return pyrogram.Messages._parse( + return utils.parse_messages( self, types.messages.Messages( messages=[m.message for m in filter( diff --git a/pyrogram/client/methods/users/get_profile_photos.py b/pyrogram/client/methods/users/get_profile_photos.py index 32e7e513..eaf632e2 100644 --- a/pyrogram/client/methods/users/get_profile_photos.py +++ b/pyrogram/client/methods/users/get_profile_photos.py @@ -20,6 +20,7 @@ from typing import Union, List import pyrogram from pyrogram.api import functions, types +from pyrogram.client.ext import utils from ...ext import BaseClient @@ -66,7 +67,7 @@ class GetProfilePhotos(BaseClient): return pyrogram.List(pyrogram.Photo._parse(self, photo) for photo in r.photos) else: - new_chat_photos = pyrogram.Messages._parse( + r = utils.parse_messages( self, self.send( functions.messages.Search( @@ -85,4 +86,4 @@ class GetProfilePhotos(BaseClient): ) ) - return pyrogram.List([m.new_chat_photo for m in new_chat_photos.messages][:limit]) + return pyrogram.List([message.new_chat_photo for message in r][:limit]) diff --git a/pyrogram/client/types/messages_and_media/__init__.py b/pyrogram/client/types/messages_and_media/__init__.py index 2de2c6a3..b9bcb460 100644 --- a/pyrogram/client/types/messages_and_media/__init__.py +++ b/pyrogram/client/types/messages_and_media/__init__.py @@ -24,7 +24,6 @@ from .game import Game from .location import Location from .message import Message from .message_entity import MessageEntity -from .messages import Messages from .photo import Photo from .poll import Poll from .poll_option import PollOption @@ -37,6 +36,6 @@ from .video_note import VideoNote from .voice import Voice __all__ = [ - "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Messages", "Photo", - "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice" + "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", + "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice" ] diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index f7dff7b5..f7e99d0a 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -2617,7 +2617,7 @@ class Message(Object, Update): ) if self.photo: - file_id = self.photo.sizes[-1].file_id + file_id = self.photo.file_id elif self.audio: file_id = self.audio.file_id elif self.document: diff --git a/pyrogram/client/types/messages_and_media/messages.py b/pyrogram/client/types/messages_and_media/messages.py deleted file mode 100644 index ee516f20..00000000 --- a/pyrogram/client/types/messages_and_media/messages.py +++ /dev/null @@ -1,170 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2019 Dan Tès -# -# 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 . - -from typing import List, Union - -import pyrogram -from pyrogram.api import types -from .message import Message -from ..object import Object -from ..update import Update -from ..user_and_chats import Chat - - -class Messages(Object, Update): - """Contains a chat's messages. - - Parameters: - total_count (``int``): - Total number of messages the target chat has. - - messages (List of :obj:`Message`): - Requested messages. - """ - - __slots__ = ["total_count", "messages"] - - def __init__( - self, - *, - client: "pyrogram.BaseClient" = None, - total_count: int, - messages: List[Message] - ): - super().__init__(client) - - self.total_count = total_count - self.messages = messages - - @staticmethod - def _parse(client, messages: types.messages.Messages, replies: int = 1) -> "Messages": - users = {i.id: i for i in messages.users} - chats = {i.id: i for i in messages.chats} - - total_count = getattr(messages, "count", len(messages.messages)) - - if not messages.messages: - return Messages( - total_count=total_count, - messages=[], - client=client - ) - - parsed_messages = [Message._parse(client, message, users, chats, replies=0) for message in messages.messages] - - if replies: - messages_with_replies = {i.id: getattr(i, "reply_to_msg_id", None) for i in messages.messages} - reply_message_ids = [i[0] for i in filter(lambda x: x[1] is not None, messages_with_replies.items())] - - if reply_message_ids: - reply_messages = client.get_messages( - parsed_messages[0].chat.id, - reply_to_message_ids=reply_message_ids, - replies=replies - 1 - ).messages - - for message in parsed_messages: - reply_id = messages_with_replies[message.message_id] - - for reply in reply_messages: - if reply.message_id == reply_id: - message.reply_to_message = reply - - return Messages( - total_count=total_count, - messages=parsed_messages, - client=client - ) - - @staticmethod - def _parse_deleted(client, update) -> "Messages": - messages = update.messages - channel_id = getattr(update, "channel_id", None) - - parsed_messages = [] - - for message in messages: - parsed_messages.append( - Message( - message_id=message, - chat=Chat( - id=int("-100" + str(channel_id)), - type="channel", - client=client - ) if channel_id is not None else None, - client=client - ) - ) - - return Messages( - total_count=len(parsed_messages), - messages=parsed_messages, - client=client - ) - - def forward( - self, - chat_id: Union[int, str], - disable_notification: bool = None, - as_copy: bool = False, - remove_caption: bool = False - ): - """Bound method *forward* of :obj:`Message`. - - Parameters: - 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). - - disable_notification (``bool``, *optional*): - Sends messages silently. - Users will receive a notification with no sound. - - as_copy (``bool``, *optional*): - Pass True to forward messages without the forward header (i.e.: send a copy of the message content). - Defaults to False. - - remove_caption (``bool``, *optional*): - If set to True and *as_copy* is enabled as well, media captions are not preserved when copying the - message. Has no effect if *as_copy* is not enabled. - Defaults to False. - - Returns: - On success, a :obj:`Messages` containing forwarded messages is returned. - - Raises: - RPCError: In case of a Telegram RPC error. - """ - forwarded_messages = [] - - for message in self.messages: - forwarded_messages.append( - message.forward( - chat_id=chat_id, - as_copy=as_copy, - disable_notification=disable_notification, - remove_caption=remove_caption - ) - ) - - return Messages( - total_count=len(forwarded_messages), - messages=forwarded_messages, - client=self._client - ) From a769fdfd20ad94f54e5caee0079ffc39a15de9a3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:14:28 +0200 Subject: [PATCH 5/9] Remove GameHighScores type --- docs/source/api/types.rst | 2 - .../methods/bots/get_game_high_scores.py | 21 ++++--- pyrogram/client/types/keyboards/__init__.py | 5 +- .../types/keyboards/game_high_scores.py | 60 ------------------- 4 files changed, 12 insertions(+), 76 deletions(-) delete mode 100644 pyrogram/client/types/keyboards/game_high_scores.py diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 66d409c4..118c4261 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -71,7 +71,6 @@ Keyboards - :class:`ForceReply` - :class:`CallbackQuery` - :class:`GameHighScore` - - :class:`GameHighScores` - :class:`CallbackGame` Input Media @@ -150,7 +149,6 @@ Details .. autoclass:: ForceReply() .. autoclass:: CallbackQuery() .. autoclass:: GameHighScore() -.. autoclass:: GameHighScores() .. autoclass:: CallbackGame() .. Input Media diff --git a/pyrogram/client/methods/bots/get_game_high_scores.py b/pyrogram/client/methods/bots/get_game_high_scores.py index e1472b9e..e6459bac 100644 --- a/pyrogram/client/methods/bots/get_game_high_scores.py +++ b/pyrogram/client/methods/bots/get_game_high_scores.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union +from typing import Union, List import pyrogram from pyrogram.api import functions @@ -29,7 +29,7 @@ class GetGameHighScores(BaseClient): user_id: Union[int, str], chat_id: Union[int, str], message_id: int = None - ) -> "pyrogram.GameHighScores": + ) -> List["pyrogram.GameHighScore"]: """Get data for high score tables. Parameters: @@ -49,20 +49,19 @@ class GetGameHighScores(BaseClient): Required if inline_message_id is not specified. Returns: - :obj:`GameHighScores`: On success. + List of :obj:`GameHighScore`: On success. Raises: RPCError: In case of a Telegram RPC error. """ # TODO: inline_message_id - return pyrogram.GameHighScores._parse( - self, - self.send( - functions.messages.GetGameHighScores( - peer=self.resolve_peer(chat_id), - id=message_id, - user_id=self.resolve_peer(user_id) - ) + r = self.send( + functions.messages.GetGameHighScores( + peer=self.resolve_peer(chat_id), + id=message_id, + user_id=self.resolve_peer(user_id) ) ) + + return pyrogram.List(pyrogram.GameHighScore._parse(self, score, r.users) for score in r.scores) diff --git a/pyrogram/client/types/keyboards/__init__.py b/pyrogram/client/types/keyboards/__init__.py index dae33e10..90376504 100644 --- a/pyrogram/client/types/keyboards/__init__.py +++ b/pyrogram/client/types/keyboards/__init__.py @@ -20,7 +20,6 @@ from .callback_game import CallbackGame from .callback_query import CallbackQuery from .force_reply import ForceReply from .game_high_score import GameHighScore -from .game_high_scores import GameHighScores from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup from .keyboard_button import KeyboardButton @@ -28,6 +27,6 @@ from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove __all__ = [ - "CallbackGame", "CallbackQuery", "ForceReply", "GameHighScore", "GameHighScores", "InlineKeyboardButton", - "InlineKeyboardMarkup", "KeyboardButton", "ReplyKeyboardMarkup", "ReplyKeyboardRemove" + "CallbackGame", "CallbackQuery", "ForceReply", "GameHighScore", "InlineKeyboardButton", "InlineKeyboardMarkup", + "KeyboardButton", "ReplyKeyboardMarkup", "ReplyKeyboardRemove" ] diff --git a/pyrogram/client/types/keyboards/game_high_scores.py b/pyrogram/client/types/keyboards/game_high_scores.py deleted file mode 100644 index ea557cd5..00000000 --- a/pyrogram/client/types/keyboards/game_high_scores.py +++ /dev/null @@ -1,60 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2019 Dan Tès -# -# 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 . - -from typing import List - -import pyrogram -from pyrogram.api import types -from pyrogram.client.types.object import Object -from .game_high_score import GameHighScore - - -class GameHighScores(Object): - """The high scores table for a game. - - Parameters: - total_count (``int``): - Total number of scores the target game has. - - game_high_scores (List of :obj:`GameHighScore`): - Game scores. - """ - - __slots__ = ["total_count", "game_high_scores"] - - def __init__( - self, - *, - client: "pyrogram.BaseClient" = None, - total_count: int, - game_high_scores: List[GameHighScore] - ): - super().__init__(client) - - self.total_count = total_count - self.game_high_scores = game_high_scores - - @staticmethod - def _parse(client, game_high_scores: types.messages.HighScores) -> "GameHighScores": - return GameHighScores( - total_count=len(game_high_scores.scores), - game_high_scores=[ - GameHighScore._parse(client, score, game_high_scores.users) - for score in game_high_scores.scores], - client=client - ) From 09c5b239be029abde40c9613877ab4bc33307947 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:21:32 +0200 Subject: [PATCH 6/9] Add FOLDER_DEAC_AUTOFIX_ALL error. Weird new 500-class error --- compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv b/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv index 4dfe5994..c85fe7e0 100644 --- a/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv +++ b/compiler/error/source/500_INTERNAL_SERVER_ERROR.tsv @@ -8,4 +8,5 @@ REG_ID_GENERATE_FAILED Telegram is having internal problems. Please try again la RANDOM_ID_DUPLICATE Telegram is having internal problems. Please try again later WORKER_BUSY_TOO_LONG_RETRY Telegram is having internal problems. Please try again later INTERDC_X_CALL_ERROR Telegram is having internal problems. Please try again later -INTERDC_X_CALL_RICH_ERROR Telegram is having internal problems. Please try again later \ No newline at end of file +INTERDC_X_CALL_RICH_ERROR Telegram is having internal problems. Please try again later +FOLDER_DEAC_AUTOFIX_ALL Telegram is having internal problems. Please try again later \ No newline at end of file From 94d90efc80961a58253dcbc59f9c573ff4f12cc9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:27:09 +0200 Subject: [PATCH 7/9] Rename section from "Keyboards" to "Bots & Keyboards" --- docs/source/api/types.rst | 6 +++--- pyrogram/client/filters/filters.py | 2 +- pyrogram/client/types/__init__.py | 2 +- .../types/{keyboards => bots_and_keyboards}/__init__.py | 0 .../{keyboards => bots_and_keyboards}/callback_game.py | 0 .../{keyboards => bots_and_keyboards}/callback_query.py | 0 .../types/{keyboards => bots_and_keyboards}/force_reply.py | 0 .../{keyboards => bots_and_keyboards}/game_high_score.py | 0 .../inline_keyboard_button.py | 0 .../inline_keyboard_markup.py | 0 .../{keyboards => bots_and_keyboards}/keyboard_button.py | 0 .../reply_keyboard_markup.py | 0 .../reply_keyboard_remove.py | 0 13 files changed, 5 insertions(+), 5 deletions(-) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/__init__.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/callback_game.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/callback_query.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/force_reply.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/game_high_score.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/inline_keyboard_button.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/inline_keyboard_markup.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/keyboard_button.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/reply_keyboard_markup.py (100%) rename pyrogram/client/types/{keyboards => bots_and_keyboards}/reply_keyboard_remove.py (100%) diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 118c4261..644f8bb2 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -57,8 +57,8 @@ Messages & Media - :class:`Poll` - :class:`PollOption` -Keyboards -^^^^^^^^^ +Bots & Keyboards +^^^^^^^^^^^^^^^^ .. hlist:: :columns: 4 @@ -140,7 +140,7 @@ Details .. autoclass:: Poll() .. autoclass:: PollOption() -.. Keyboards +.. Bots & Keyboards .. autoclass:: ReplyKeyboardMarkup() .. autoclass:: KeyboardButton() .. autoclass:: ReplyKeyboardRemove() diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 1d962e85..fb0a3615 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -19,7 +19,7 @@ import re from .filter import Filter -from ..types.keyboards import InlineKeyboardMarkup, ReplyKeyboardMarkup +from ..types.bots_and_keyboards import InlineKeyboardMarkup, ReplyKeyboardMarkup def create(name: str, func: callable, **kwargs) -> type: diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 8a725a9e..8fa55482 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .keyboards import * +from .bots_and_keyboards import * from .inline_mode import * from .input_media import * from .input_message_content import * diff --git a/pyrogram/client/types/keyboards/__init__.py b/pyrogram/client/types/bots_and_keyboards/__init__.py similarity index 100% rename from pyrogram/client/types/keyboards/__init__.py rename to pyrogram/client/types/bots_and_keyboards/__init__.py diff --git a/pyrogram/client/types/keyboards/callback_game.py b/pyrogram/client/types/bots_and_keyboards/callback_game.py similarity index 100% rename from pyrogram/client/types/keyboards/callback_game.py rename to pyrogram/client/types/bots_and_keyboards/callback_game.py diff --git a/pyrogram/client/types/keyboards/callback_query.py b/pyrogram/client/types/bots_and_keyboards/callback_query.py similarity index 100% rename from pyrogram/client/types/keyboards/callback_query.py rename to pyrogram/client/types/bots_and_keyboards/callback_query.py diff --git a/pyrogram/client/types/keyboards/force_reply.py b/pyrogram/client/types/bots_and_keyboards/force_reply.py similarity index 100% rename from pyrogram/client/types/keyboards/force_reply.py rename to pyrogram/client/types/bots_and_keyboards/force_reply.py diff --git a/pyrogram/client/types/keyboards/game_high_score.py b/pyrogram/client/types/bots_and_keyboards/game_high_score.py similarity index 100% rename from pyrogram/client/types/keyboards/game_high_score.py rename to pyrogram/client/types/bots_and_keyboards/game_high_score.py diff --git a/pyrogram/client/types/keyboards/inline_keyboard_button.py b/pyrogram/client/types/bots_and_keyboards/inline_keyboard_button.py similarity index 100% rename from pyrogram/client/types/keyboards/inline_keyboard_button.py rename to pyrogram/client/types/bots_and_keyboards/inline_keyboard_button.py diff --git a/pyrogram/client/types/keyboards/inline_keyboard_markup.py b/pyrogram/client/types/bots_and_keyboards/inline_keyboard_markup.py similarity index 100% rename from pyrogram/client/types/keyboards/inline_keyboard_markup.py rename to pyrogram/client/types/bots_and_keyboards/inline_keyboard_markup.py diff --git a/pyrogram/client/types/keyboards/keyboard_button.py b/pyrogram/client/types/bots_and_keyboards/keyboard_button.py similarity index 100% rename from pyrogram/client/types/keyboards/keyboard_button.py rename to pyrogram/client/types/bots_and_keyboards/keyboard_button.py diff --git a/pyrogram/client/types/keyboards/reply_keyboard_markup.py b/pyrogram/client/types/bots_and_keyboards/reply_keyboard_markup.py similarity index 100% rename from pyrogram/client/types/keyboards/reply_keyboard_markup.py rename to pyrogram/client/types/bots_and_keyboards/reply_keyboard_markup.py diff --git a/pyrogram/client/types/keyboards/reply_keyboard_remove.py b/pyrogram/client/types/bots_and_keyboards/reply_keyboard_remove.py similarity index 100% rename from pyrogram/client/types/keyboards/reply_keyboard_remove.py rename to pyrogram/client/types/bots_and_keyboards/reply_keyboard_remove.py From 43493733c93eed960354f036f0c981baf54de360 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:28:03 +0200 Subject: [PATCH 8/9] Rearrange code --- pyrogram/client/ext/__init__.py | 3 +-- pyrogram/client/ext/dispatcher.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/ext/__init__.py b/pyrogram/client/ext/__init__.py index 58897c55..dde1952e 100644 --- a/pyrogram/client/ext/__init__.py +++ b/pyrogram/client/ext/__init__.py @@ -19,6 +19,5 @@ from .base_client import BaseClient from .dispatcher import Dispatcher from .emoji import Emoji -from .syncer import Syncer from .file_data import FileData - +from .syncer import Syncer diff --git a/pyrogram/client/ext/dispatcher.py b/pyrogram/client/ext/dispatcher.py index 12d5a5de..b6760345 100644 --- a/pyrogram/client/ext/dispatcher.py +++ b/pyrogram/client/ext/dispatcher.py @@ -21,10 +21,10 @@ import threading from collections import OrderedDict from queue import Queue from threading import Thread -from . import utils import pyrogram from pyrogram.api import types +from . import utils from ..handlers import ( CallbackQueryHandler, MessageHandler, DeletedMessagesHandler, UserStatusHandler, RawUpdateHandler, InlineQueryHandler, PollHandler From b9b50bad94afe50073e0b85677538f0bcdaf74b3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 11 Jun 2019 16:46:10 +0200 Subject: [PATCH 9/9] Fix get_users and get_contacts not returning pretty-printable lists --- pyrogram/client/methods/contacts/get_contacts.py | 2 +- pyrogram/client/methods/users/get_users.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/contacts/get_contacts.py b/pyrogram/client/methods/contacts/get_contacts.py index 0c231670..8ca321dc 100644 --- a/pyrogram/client/methods/contacts/get_contacts.py +++ b/pyrogram/client/methods/contacts/get_contacts.py @@ -47,4 +47,4 @@ class GetContacts(BaseClient): time.sleep(e.x) else: log.info("Total contacts: {}".format(len(self.peers_by_phone))) - return [pyrogram.User._parse(self, user) for user in contacts.users] + return pyrogram.List(pyrogram.User._parse(self, user) for user in contacts.users) diff --git a/pyrogram/client/methods/users/get_users.py b/pyrogram/client/methods/users/get_users.py index 4ec0e893..f76e6802 100644 --- a/pyrogram/client/methods/users/get_users.py +++ b/pyrogram/client/methods/users/get_users.py @@ -56,7 +56,7 @@ class GetUsers(BaseClient): ) ) - users = [] + users = pyrogram.List() for i in r: users.append(pyrogram.User._parse(self, i))