From 6e78935857b3960a4b13a3016d6594717a07ce7d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 24 Apr 2018 16:08:33 +0200 Subject: [PATCH] Accommodate the new types --- compiler/api/compiler.py | 78 ++++++++++++------- compiler/api/source/pyrogram.tl | 36 ++++----- compiler/api/template/pyrogram.txt | 1 + pyrogram/__init__.py | 15 ++-- pyrogram/api/__init__.py | 2 +- pyrogram/client/__init__.py | 2 + pyrogram/client/client.py | 27 ++++--- pyrogram/client/dispatcher/dispatcher.py | 1 - pyrogram/client/message_parser.py | 70 ++++++++--------- pyrogram/client/types/__init__.py | 29 +++---- .../client/{ => types}/input_media_photo.py | 0 .../client/{ => types}/input_media_video.py | 0 .../client/{ => types}/input_phone_contact.py | 0 13 files changed, 139 insertions(+), 122 deletions(-) rename pyrogram/client/{ => types}/input_media_photo.py (100%) rename pyrogram/client/{ => types}/input_media_video.py (100%) rename pyrogram/client/{ => types}/input_phone_contact.py (100%) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 676692ba..90592358 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -67,8 +67,8 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool n = len(t) - 1 t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join( - ":obj:`{1} `".format( - "pyrogram." if is_pyrogram_type else "", + ":obj:`{1} <{0}.{1}>`".format( + "pyrogram.types" if is_pyrogram_type else "pyrogram.api.types", i.replace("pyrogram.", "") ) for i in t @@ -274,7 +274,7 @@ def start(): ) if c.args else "pass" docstring_args = [] - # docs = c.docs.split("|")[1:] if c.docs else None + docs = c.docs.split("|")[1:] if c.docs else None for i, arg in enumerate(sorted_args): arg_name, arg_type = arg @@ -282,24 +282,23 @@ def start(): flag_number = is_optional.group(1) if is_optional else -1 arg_type = arg_type.split("?")[-1] - # if c.namespace == "pyrogram": - # docstring_args.append( - # "{} ({}{}):\n {}\n".format( - # arg_name, - # get_docstring_arg_type(arg_type, is_pyrogram_type=True), - # ", optional" if "Optional" in docs[i] else "", - # re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".") - # ) - # ) - # else: - - docstring_args.append( - "{}{}: {}".format( - arg_name, - " (optional)".format(flag_number) if is_optional else "", - get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram") + if docs: + docstring_args.append( + "{} ({}{}):\n {}\n".format( + arg_name, + get_docstring_arg_type(arg_type, is_pyrogram_type=True), + ", optional" if "Optional" in docs[i] else "", + re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".") + ) + ) + else: + docstring_args.append( + "{}{}: {}".format( + arg_name, + " (optional)".format(flag_number) if is_optional else "", + get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram") + ) ) - ) if docstring_args: docstring_args = "Args:\n " + "\n ".join(docstring_args) @@ -442,17 +441,36 @@ def start(): for c in combinators: path = ".".join(filter(None, [c.section, c.namespace, capit(c.name)])) - f.write("\n {}: \"{}\",".format(c.id, path)) + f.write("\n {}: \"pyrogram.api.{}\",".format(c.id, path)) - f.write("\n 0xbc799737: \"core.BoolFalse\",") - f.write("\n 0x997275b5: \"core.BoolTrue\",") - f.write("\n 0x56730bcc: \"core.Null\",") - f.write("\n 0x1cb5c415: \"core.Vector\",") - f.write("\n 0x73f1f8dc: \"core.MsgContainer\",") - f.write("\n 0xae500895: \"core.FutureSalts\",") - f.write("\n 0x0949d9dc: \"core.FutureSalt\",") - f.write("\n 0x3072cfa1: \"core.GzipPacked\",") - f.write("\n 0x5bb8e511: \"core.Message\"") + f.write("\n 0xbc799737: \"pyrogram.api.core.BoolFalse\",") + f.write("\n 0x997275b5: \"pyrogram.api.core.BoolTrue\",") + f.write("\n 0x56730bcc: \"pyrogram.api.core.Null\",") + f.write("\n 0x1cb5c415: \"pyrogram.api.core.Vector\",") + f.write("\n 0x73f1f8dc: \"pyrogram.api.core.MsgContainer\",") + f.write("\n 0xae500895: \"pyrogram.api.core.FutureSalts\",") + f.write("\n 0x0949d9dc: \"pyrogram.api.core.FutureSalt\",") + f.write("\n 0x3072cfa1: \"pyrogram.api.core.GzipPacked\",") + f.write("\n 0x5bb8e511: \"pyrogram.api.core.Message\",") + + f.write("\n 0xb0700000: \"pyrogram.client.types.Update\",") + f.write("\n 0xb0700001: \"pyrogram.client.types.User\",") + f.write("\n 0xb0700002: \"pyrogram.client.types.Chat\",") + f.write("\n 0xb0700003: \"pyrogram.client.types.Message\",") + f.write("\n 0xb0700004: \"pyrogram.client.types.MessageEntity\",") + f.write("\n 0xb0700005: \"pyrogram.client.types.PhotoSize\",") + f.write("\n 0xb0700006: \"pyrogram.client.types.Audio\",") + f.write("\n 0xb0700007: \"pyrogram.client.types.Document\",") + f.write("\n 0xb0700008: \"pyrogram.client.types.Video\",") + f.write("\n 0xb0700009: \"pyrogram.client.types.Voice\",") + f.write("\n 0xb0700010: \"pyrogram.client.types.VideoNote\",") + f.write("\n 0xb0700011: \"pyrogram.client.types.Contact\",") + f.write("\n 0xb0700012: \"pyrogram.client.types.Location\",") + f.write("\n 0xb0700013: \"pyrogram.client.types.Venue\",") + f.write("\n 0xb0700014: \"pyrogram.client.types.UserProfilePhotos\",") + f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",") + f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") + f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\"") f.write("\n}\n") diff --git a/compiler/api/source/pyrogram.tl b/compiler/api/source/pyrogram.tl index 4a6fb182..a8232bd6 100644 --- a/compiler/api/source/pyrogram.tl +++ b/compiler/api/source/pyrogram.tl @@ -2,21 +2,21 @@ ---types--- -pyrogram.update#b0700000 flags:# update_id:int message:flags.0?Message edited_message:flags.1?Message channel_post:flags.2?Message edited_channel_post:flags.3?Message inline_query:flags.4?InlineQuery chosen_inline_result:flags.5?ChosenInlineResult callback_query:flags.6?CallbackQuery shipping_query:flags.7?ShippingQuery pre_checkout_query:flags.8?PreCheckoutQuery = pyrogram.Update; -pyrogram.user#b0700001 flags:# id:int is_bot:Bool first_name:string last_name:flags.0?string username:flags.1?string language_code:flags.2?string phone_number:flags.3?string photo:flags.4?ChatPhoto = pyrogram.User; -pyrogram.chat#b0700002 flags:# id:int type:string title:flags.0?string username:flags.1?string first_name:flags.2?string last_name:flags.3?string all_members_are_administrators:flags.4?Bool photo:flags.5?ChatPhoto description:flags.6?string invite_link:flags.7?string pinned_message:flags.8?Message sticker_set_name:flags.9?string can_set_sticker_set:flags.10?Bool = pyrogram.Chat; -pyrogram.message#b0700003 flags:# message_id:int from_user:flags.0?User date:int chat:Chat forward_from:flags.1?User forward_from_chat:flags.2?Chat forward_from_message_id:flags.3?int forward_signature:flags.4?string forward_date:flags.5?int reply_to_message:flags.6?Message edit_date:flags.7?int media_group_id:flags.8?string author_signature:flags.9?string text:flags.10?string entities:flags.11?Vector caption_entities:flags.12?Vector audio:flags.13?Audio document:flags.14?Document game:flags.15?Game photo:flags.16?Vector sticker:flags.17?Sticker video:flags.18?Video voice:flags.19?Voice video_note:flags.20?VideoNote caption:flags.21?string contact:flags.22?Contact location:flags.23?Location venue:flags.24?Venue new_chat_members:flags.25?Vector left_chat_member:flags.26?User new_chat_title:flags.27?string new_chat_photo:flags.28?Vector delete_chat_photo:flags.29?true group_chat_created:flags.30?true supergroup_chat_created:flags.31?true channel_chat_created:flags.32?true migrate_to_chat_id:flags.33?int migrate_from_chat_id:flags.34?int pinned_message:flags.35?Message invoice:flags.36?Invoice successful_payment:flags.37?SuccessfulPayment connected_website:flags.38?string views:flags.39?int via_bot:flags.40?User = pyrogram.Message; -pyrogram.messageEntity#b0700004 flags:# type:string offset:int length:int url:flags.0?string user:flags.1?User = pyrogram.MessageEntity; -pyrogram.photoSize#b0700005 flags:# file_id:string file_size:flags.0?int date:flags.1?int width:int height:int = pyrogram.PhotoSize; -pyrogram.audio#b0700006 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int duration:int performer:flags.5?string title:flags.6?string = pyrogram.Audio; -pyrogram.document#b0700007 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int = pyrogram.Document; -pyrogram.video#b0700008 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int width:int height:int duration:int = pyrogram.Video; -pyrogram.voice#b0700009 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int duration:int = pyrogram.Voice; -pyrogram.videoNote#b0700010 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int length:int duration:int = pyrogram.VideoNote; -pyrogram.contact#b0700011 flags:# phone_number:string first_name:string last_name:flags.0?string user_id:flags.1?int = pyrogram.Contact; -pyrogram.location#b0700012 longitude:double latitude:double = pyrogram.Location; -pyrogram.venue#b0700013 flags:# location:Location title:string address:string foursquare_id:flags.0?string = pyrogram.Venue; -pyrogram.userProfilePhotos#b0700014 total_count:int photos:Vector> = pyrogram.UserProfilePhotos; -pyrogram.chatPhoto#b0700015 small_file_id:string big_file_id:string = pyrogram.ChatPhoto; -pyrogram.chatMember#b0700016 flags:# user:User status:string until_date:flags.0?int can_be_edited:flags.1?Bool can_change_info:flags.2?Bool can_post_messages:flags.3?Bool can_edit_messages:flags.4?Bool can_delete_messages:flags.5?Bool can_invite_users:flags.6?Bool can_restrict_members:flags.7?Bool can_pin_messages:flags.8?Bool can_promote_members:flags.9?Bool can_send_messages:flags.10?Bool can_send_media_messages:flags.11?Bool can_send_other_messages:flags.12?Bool can_add_web_page_previews:flags.13?Bool = pyrogram.ChatMember; -pyrogram.sticker#b0700017 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int width:int height:int emoji:flags.5?string set_name:flags.6?string mask_position:flags.7?MaskPosition = pyrogram.Sticker; +//pyrogram.update#b0700000 flags:# update_id:int message:flags.0?Message edited_message:flags.1?Message channel_post:flags.2?Message edited_channel_post:flags.3?Message inline_query:flags.4?InlineQuery chosen_inline_result:flags.5?ChosenInlineResult callback_query:flags.6?CallbackQuery shipping_query:flags.7?ShippingQuery pre_checkout_query:flags.8?PreCheckoutQuery = pyrogram.Update; +//pyrogram.user#b0700001 flags:# id:int is_bot:Bool first_name:string last_name:flags.0?string username:flags.1?string language_code:flags.2?string phone_number:flags.3?string photo:flags.4?ChatPhoto = pyrogram.User; +//pyrogram.chat#b0700002 flags:# id:int type:string title:flags.0?string username:flags.1?string first_name:flags.2?string last_name:flags.3?string all_members_are_administrators:flags.4?Bool photo:flags.5?ChatPhoto description:flags.6?string invite_link:flags.7?string pinned_message:flags.8?Message sticker_set_name:flags.9?string can_set_sticker_set:flags.10?Bool = pyrogram.Chat; +//pyrogram.message#b0700003 flags:# message_id:int from_user:flags.0?User date:int chat:Chat forward_from:flags.1?User forward_from_chat:flags.2?Chat forward_from_message_id:flags.3?int forward_signature:flags.4?string forward_date:flags.5?int reply_to_message:flags.6?Message edit_date:flags.7?int media_group_id:flags.8?string author_signature:flags.9?string text:flags.10?string entities:flags.11?Vector caption_entities:flags.12?Vector audio:flags.13?Audio document:flags.14?Document game:flags.15?Game photo:flags.16?Vector sticker:flags.17?Sticker video:flags.18?Video voice:flags.19?Voice video_note:flags.20?VideoNote caption:flags.21?string contact:flags.22?Contact location:flags.23?Location venue:flags.24?Venue new_chat_members:flags.25?Vector left_chat_member:flags.26?User new_chat_title:flags.27?string new_chat_photo:flags.28?Vector delete_chat_photo:flags.29?true group_chat_created:flags.30?true supergroup_chat_created:flags.31?true channel_chat_created:flags.32?true migrate_to_chat_id:flags.33?int migrate_from_chat_id:flags.34?int pinned_message:flags.35?Message invoice:flags.36?Invoice successful_payment:flags.37?SuccessfulPayment connected_website:flags.38?string views:flags.39?int via_bot:flags.40?User = pyrogram.Message; +//pyrogram.messageEntity#b0700004 flags:# type:string offset:int length:int url:flags.0?string user:flags.1?User = pyrogram.MessageEntity; +//pyrogram.photoSize#b0700005 flags:# file_id:string file_size:flags.0?int date:flags.1?int width:int height:int = pyrogram.PhotoSize; +//pyrogram.audio#b0700006 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int duration:int performer:flags.5?string title:flags.6?string = pyrogram.Audio; +//pyrogram.document#b0700007 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int = pyrogram.Document; +//pyrogram.video#b0700008 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int width:int height:int duration:int = pyrogram.Video; +//pyrogram.voice#b0700009 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int duration:int = pyrogram.Voice; +//pyrogram.videoNote#b0700010 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int length:int duration:int = pyrogram.VideoNote; +//pyrogram.contact#b0700011 flags:# phone_number:string first_name:string last_name:flags.0?string user_id:flags.1?int = pyrogram.Contact; +//pyrogram.location#b0700012 longitude:double latitude:double = pyrogram.Location; +//pyrogram.venue#b0700013 flags:# location:Location title:string address:string foursquare_id:flags.0?string = pyrogram.Venue; +//pyrogram.userProfilePhotos#b0700014 total_count:int photos:Vector> = pyrogram.UserProfilePhotos; +//pyrogram.chatPhoto#b0700015 small_file_id:string big_file_id:string = pyrogram.ChatPhoto; +//pyrogram.chatMember#b0700016 flags:# user:User status:string until_date:flags.0?int can_be_edited:flags.1?Bool can_change_info:flags.2?Bool can_post_messages:flags.3?Bool can_edit_messages:flags.4?Bool can_delete_messages:flags.5?Bool can_invite_users:flags.6?Bool can_restrict_members:flags.7?Bool can_pin_messages:flags.8?Bool can_promote_members:flags.9?Bool can_send_messages:flags.10?Bool can_send_media_messages:flags.11?Bool can_send_other_messages:flags.12?Bool can_add_web_page_previews:flags.13?Bool = pyrogram.ChatMember; +//pyrogram.sticker#b0700017 flags:# file_id:string thumb:flags.0?PhotoSize file_name:flags.1?string mime_type:flags.2?string file_size:flags.3?int date:flags.4?int width:int height:int emoji:flags.5?string set_name:flags.6?string mask_position:flags.7?MaskPosition = pyrogram.Sticker; diff --git a/compiler/api/template/pyrogram.txt b/compiler/api/template/pyrogram.txt index adbe4151..00ad8e33 100644 --- a/compiler/api/template/pyrogram.txt +++ b/compiler/api/template/pyrogram.txt @@ -2,6 +2,7 @@ from pyrogram.api.core import Object + class {class_name}(Object): """{docstring_args} """ diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index f483127b..e71fc0dd 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -26,13 +26,8 @@ __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)" __version__ = "0.7.1" from .api.errors import Error -from .api.types.pyrogram import * -from .client import ChatAction -from .client import Client -from .client import ParseMode -from .client.input_media_photo import InputMediaPhoto -from .client.input_media_video import InputMediaVideo -from .client.input_phone_contact import InputPhoneContact -from .client import Emoji -from .client.handlers import MessageHandler, RawUpdateHandler -from .client.filters import Filters +from .client.types import * +from .client import ( + Client, ChatAction, ParseMode, Emoji, + MessageHandler, RawUpdateHandler, Filters +) diff --git a/pyrogram/api/__init__.py b/pyrogram/api/__init__.py index 7f9f3c59..71e28d6b 100644 --- a/pyrogram/api/__init__.py +++ b/pyrogram/api/__init__.py @@ -23,4 +23,4 @@ from .core.object import Object for k, v in objects.items(): path, name = v.rsplit(".", 1) - Object.all[k] = getattr(import_module("pyrogram.api." + path), name) + Object.all[k] = getattr(import_module(path), name) diff --git a/pyrogram/client/__init__.py b/pyrogram/client/__init__.py index b2935dad..435276d3 100644 --- a/pyrogram/client/__init__.py +++ b/pyrogram/client/__init__.py @@ -19,4 +19,6 @@ from .chat_action import ChatAction from .client import Client from .emoji import Emoji +from .filters import Filters +from .handlers import MessageHandler, RawUpdateHandler from .parse_mode import ParseMode diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 1d0ef686..2756f59b 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -51,10 +51,9 @@ from pyrogram.crypto import AES from pyrogram.session import Auth, Session from pyrogram.session.internals import MsgId from . import message_parser +from . import types as pyrogram_types from . import utils from .dispatcher import Dispatcher -from .input_media_photo import InputMediaPhoto -from .input_media_video import InputMediaVideo from .style import Markdown, HTML from .syncer import Syncer @@ -2076,7 +2075,7 @@ class Client: for i in media: style = self.html if i.parse_mode.lower() == "html" else self.markdown - if isinstance(i, InputMediaPhoto): + if isinstance(i, pyrogram_types.InputMediaPhoto): if os.path.exists(i.media): media = self.send( functions.messages.UploadMedia( @@ -2115,7 +2114,7 @@ class Client: access_hash=unpacked[3] ) ) - elif isinstance(i, InputMediaVideo): + elif isinstance(i, pyrogram_types.InputMediaVideo): if os.path.exists(i.media): media = self.send( functions.messages.UploadMedia( @@ -3108,7 +3107,7 @@ class Client: return False def download_media(self, - message: pyrogram.Message, + message: pyrogram_types.Message, file_name: str = "", block: bool = True, progress: callable = None): @@ -3147,7 +3146,7 @@ class Client: Raises: :class:`Error ` """ - if isinstance(message, pyrogram.Message): + if isinstance(message, pyrogram_types.Message): if message.photo: media = message.photo[-1] elif message.audio: @@ -3165,17 +3164,17 @@ class Client: else: return elif isinstance(message, ( - pyrogram.PhotoSize, - pyrogram.Audio, - pyrogram.Document, - pyrogram.Video, - pyrogram.Voice, - pyrogram.VideoNote, - pyrogram.Sticker + pyrogram_types.PhotoSize, + pyrogram_types.Audio, + pyrogram_types.Document, + pyrogram_types.Video, + pyrogram_types.Voice, + pyrogram_types.VideoNote, + pyrogram_types.Sticker )): media = message elif isinstance(message, str): - media = pyrogram.Document( + media = pyrogram_types.Document( file_id=message, file_size=0, mime_type="" diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index 72bcbfc9..6f96876c 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -138,7 +138,6 @@ class Dispatcher: self.dispatch( pyrogram.Update( - update_id=0, message=((message if message.chat.type != "channel" else None) if not is_edited_message else None), diff --git a/pyrogram/client/message_parser.py b/pyrogram/client/message_parser.py index 9748b263..b9c38837 100644 --- a/pyrogram/client/message_parser.py +++ b/pyrogram/client/message_parser.py @@ -18,10 +18,10 @@ from struct import pack -import pyrogram -from pyrogram.api import types, functions -from pyrogram.api.errors import StickersetInvalid +from . import types as pyrogram_types from .utils import encode +from ..api import types, functions +from ..api.errors import StickersetInvalid # TODO: Organize the code better? @@ -47,7 +47,7 @@ def parse_entities(entities: list, users: dict) -> list: entity_type = ENTITIES.get(entity.ID, None) if entity_type: - output_entities.append(pyrogram.MessageEntity( + output_entities.append(pyrogram_types.MessageEntity( type=entity_type, offset=entity.offset, length=entity.length, @@ -76,7 +76,7 @@ def parse_chat_photo(photo): loc_small = photo.photo_small loc_big = photo.photo_big - return pyrogram.ChatPhoto( + return pyrogram_types.ChatPhoto( small_file_id=encode( pack( " pyrogram.User or None: - return pyrogram.User( +def parse_user(user: types.User) -> pyrogram_types.User or None: + return pyrogram_types.User( id=user.id, is_bot=user.bot, first_name=user.first_name, @@ -105,7 +105,7 @@ def parse_user(user: types.User) -> pyrogram.User or None: ) if user else None -def parse_chat(message: types.Message, users: dict, chats: dict) -> pyrogram.Chat: +def parse_chat(message: types.Message, users: dict, chats: dict) -> pyrogram_types.Chat: if isinstance(message.to_id, types.PeerUser): return parse_user_chat(users[message.to_id.user_id if message.out else message.from_id]) elif isinstance(message.to_id, types.PeerChat): @@ -114,8 +114,8 @@ def parse_chat(message: types.Message, users: dict, chats: dict) -> pyrogram.Cha return parse_channel_chat(chats[message.to_id.channel_id]) -def parse_user_chat(user: types.User) -> pyrogram.Chat: - return pyrogram.Chat( +def parse_user_chat(user: types.User) -> pyrogram_types.Chat: + return pyrogram_types.Chat( id=user.id, type="private", username=user.username, @@ -125,8 +125,8 @@ def parse_user_chat(user: types.User) -> pyrogram.Chat: ) -def parse_chat_chat(chat: types.Chat) -> pyrogram.Chat: - return pyrogram.Chat( +def parse_chat_chat(chat: types.Chat) -> pyrogram_types.Chat: + return pyrogram_types.Chat( id=-chat.id, type="group", title=chat.title, @@ -135,8 +135,8 @@ def parse_chat_chat(chat: types.Chat) -> pyrogram.Chat: ) -def parse_channel_chat(channel: types.Channel) -> pyrogram.Chat: - return pyrogram.Chat( +def parse_channel_chat(channel: types.Channel) -> pyrogram_types.Chat: + return pyrogram_types.Chat( id=int("-100" + str(channel.id)), type="supergroup" if channel.megagroup else "channel", title=channel.title, @@ -145,7 +145,7 @@ def parse_channel_chat(channel: types.Channel) -> pyrogram.Chat: ) -def parse_thumb(thumb: types.PhotoSize or types.PhotoCachedSize) -> pyrogram.PhotoSize or None: +def parse_thumb(thumb: types.PhotoSize or types.PhotoCachedSize) -> pyrogram_types.PhotoSize or None: if isinstance(thumb, (types.PhotoSize, types.PhotoCachedSize)): loc = thumb.location @@ -155,7 +155,7 @@ def parse_thumb(thumb: types.PhotoSize or types.PhotoCachedSize) -> pyrogram.Pho file_size = len(thumb.bytes) if isinstance(loc, types.FileLocation): - return pyrogram.PhotoSize( + return pyrogram_types.PhotoSize( file_id=encode( pack( " pyrogram.Message: +) -> pyrogram_types.Message: entities = parse_entities(message.entities, users) forward_from = None @@ -233,7 +233,7 @@ def parse_message( file_size = len(size.bytes) if isinstance(loc, types.FileLocation): - photo_size = pyrogram.PhotoSize( + photo_size = pyrogram_types.PhotoSize( file_id=encode( pack( " pyrogram.Message: +) -> pyrogram_types.Message: action = message.action new_chat_members = None @@ -538,7 +538,7 @@ def parse_message_service( file_size = len(size.bytes) if isinstance(loc, types.FileLocation): - photo_size = pyrogram.PhotoSize( + photo_size = pyrogram_types.PhotoSize( file_id=encode( pack( " pyrogram.Message: - return pyrogram.Message( +) -> pyrogram_types.Message: + return pyrogram_types.Message( message_id=message.id, date=None, chat=None diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 31defbdb..7b864fd4 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,21 +16,24 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .update import Update -from .user import User +from .audio import Audio from .chat import Chat +from .chat_member import ChatMember +from .chat_photo import ChatPhoto +from .contact import Contact +from .document import Document +from .input_media_photo import InputMediaPhoto +from .input_media_video import InputMediaVideo +from .input_phone_contact import InputPhoneContact +from .location import Location from .message import Message from .message_entity import MessageEntity from .photo_size import PhotoSize -from .audio import Audio -from .document import Document -from .video import Video -from .voice import Voice -from .video_note import VideoNote -from .contact import Contact -from .location import Location -from .venue import Venue -from .user_profile_photos import UserProfilePhotos -from .chat_photo import ChatPhoto -from .chat_member import ChatMember from .sticker import Sticker +from .update import Update +from .user import User +from .user_profile_photos import UserProfilePhotos +from .venue import Venue +from .video import Video +from .video_note import VideoNote +from .voice import Voice diff --git a/pyrogram/client/input_media_photo.py b/pyrogram/client/types/input_media_photo.py similarity index 100% rename from pyrogram/client/input_media_photo.py rename to pyrogram/client/types/input_media_photo.py diff --git a/pyrogram/client/input_media_video.py b/pyrogram/client/types/input_media_video.py similarity index 100% rename from pyrogram/client/input_media_video.py rename to pyrogram/client/types/input_media_video.py diff --git a/pyrogram/client/input_phone_contact.py b/pyrogram/client/types/input_phone_contact.py similarity index 100% rename from pyrogram/client/input_phone_contact.py rename to pyrogram/client/types/input_phone_contact.py