Skip to content

Commit 6e78935

Browse files
committed
Accommodate the new types
1 parent 59bca1c commit 6e78935

13 files changed

Lines changed: 139 additions & 122 deletions

File tree

compiler/api/compiler.py

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool
6767
n = len(t) - 1
6868

6969
t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join(
70-
":obj:`{1} <pyrogram.api.types.{0}{1}>`".format(
71-
"pyrogram." if is_pyrogram_type else "",
70+
":obj:`{1} <{0}.{1}>`".format(
71+
"pyrogram.types" if is_pyrogram_type else "pyrogram.api.types",
7272
i.replace("pyrogram.", "")
7373
)
7474
for i in t
@@ -274,32 +274,31 @@ def start():
274274
) if c.args else "pass"
275275

276276
docstring_args = []
277-
# docs = c.docs.split("|")[1:] if c.docs else None
277+
docs = c.docs.split("|")[1:] if c.docs else None
278278

279279
for i, arg in enumerate(sorted_args):
280280
arg_name, arg_type = arg
281281
is_optional = FLAGS_RE.match(arg_type)
282282
flag_number = is_optional.group(1) if is_optional else -1
283283
arg_type = arg_type.split("?")[-1]
284284

285-
# if c.namespace == "pyrogram":
286-
# docstring_args.append(
287-
# "{} ({}{}):\n {}\n".format(
288-
# arg_name,
289-
# get_docstring_arg_type(arg_type, is_pyrogram_type=True),
290-
# ", optional" if "Optional" in docs[i] else "",
291-
# re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".")
292-
# )
293-
# )
294-
# else:
295-
296-
docstring_args.append(
297-
"{}{}: {}".format(
298-
arg_name,
299-
" (optional)".format(flag_number) if is_optional else "",
300-
get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
285+
if docs:
286+
docstring_args.append(
287+
"{} ({}{}):\n {}\n".format(
288+
arg_name,
289+
get_docstring_arg_type(arg_type, is_pyrogram_type=True),
290+
", optional" if "Optional" in docs[i] else "",
291+
re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".")
292+
)
293+
)
294+
else:
295+
docstring_args.append(
296+
"{}{}: {}".format(
297+
arg_name,
298+
" (optional)".format(flag_number) if is_optional else "",
299+
get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
300+
)
301301
)
302-
)
303302

304303
if docstring_args:
305304
docstring_args = "Args:\n " + "\n ".join(docstring_args)
@@ -442,17 +441,36 @@ def start():
442441

443442
for c in combinators:
444443
path = ".".join(filter(None, [c.section, c.namespace, capit(c.name)]))
445-
f.write("\n {}: \"{}\",".format(c.id, path))
446-
447-
f.write("\n 0xbc799737: \"core.BoolFalse\",")
448-
f.write("\n 0x997275b5: \"core.BoolTrue\",")
449-
f.write("\n 0x56730bcc: \"core.Null\",")
450-
f.write("\n 0x1cb5c415: \"core.Vector\",")
451-
f.write("\n 0x73f1f8dc: \"core.MsgContainer\",")
452-
f.write("\n 0xae500895: \"core.FutureSalts\",")
453-
f.write("\n 0x0949d9dc: \"core.FutureSalt\",")
454-
f.write("\n 0x3072cfa1: \"core.GzipPacked\",")
455-
f.write("\n 0x5bb8e511: \"core.Message\"")
444+
f.write("\n {}: \"pyrogram.api.{}\",".format(c.id, path))
445+
446+
f.write("\n 0xbc799737: \"pyrogram.api.core.BoolFalse\",")
447+
f.write("\n 0x997275b5: \"pyrogram.api.core.BoolTrue\",")
448+
f.write("\n 0x56730bcc: \"pyrogram.api.core.Null\",")
449+
f.write("\n 0x1cb5c415: \"pyrogram.api.core.Vector\",")
450+
f.write("\n 0x73f1f8dc: \"pyrogram.api.core.MsgContainer\",")
451+
f.write("\n 0xae500895: \"pyrogram.api.core.FutureSalts\",")
452+
f.write("\n 0x0949d9dc: \"pyrogram.api.core.FutureSalt\",")
453+
f.write("\n 0x3072cfa1: \"pyrogram.api.core.GzipPacked\",")
454+
f.write("\n 0x5bb8e511: \"pyrogram.api.core.Message\",")
455+
456+
f.write("\n 0xb0700000: \"pyrogram.client.types.Update\",")
457+
f.write("\n 0xb0700001: \"pyrogram.client.types.User\",")
458+
f.write("\n 0xb0700002: \"pyrogram.client.types.Chat\",")
459+
f.write("\n 0xb0700003: \"pyrogram.client.types.Message\",")
460+
f.write("\n 0xb0700004: \"pyrogram.client.types.MessageEntity\",")
461+
f.write("\n 0xb0700005: \"pyrogram.client.types.PhotoSize\",")
462+
f.write("\n 0xb0700006: \"pyrogram.client.types.Audio\",")
463+
f.write("\n 0xb0700007: \"pyrogram.client.types.Document\",")
464+
f.write("\n 0xb0700008: \"pyrogram.client.types.Video\",")
465+
f.write("\n 0xb0700009: \"pyrogram.client.types.Voice\",")
466+
f.write("\n 0xb0700010: \"pyrogram.client.types.VideoNote\",")
467+
f.write("\n 0xb0700011: \"pyrogram.client.types.Contact\",")
468+
f.write("\n 0xb0700012: \"pyrogram.client.types.Location\",")
469+
f.write("\n 0xb0700013: \"pyrogram.client.types.Venue\",")
470+
f.write("\n 0xb0700014: \"pyrogram.client.types.UserProfilePhotos\",")
471+
f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",")
472+
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
473+
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\"")
456474

457475
f.write("\n}\n")
458476

compiler/api/source/pyrogram.tl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
---types---
44

5-
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;
6-
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;
7-
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;
8-
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<MessageEntity> caption_entities:flags.12?Vector<MessageEntity> audio:flags.13?Audio document:flags.14?Document game:flags.15?Game photo:flags.16?Vector<PhotoSize> 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<User> left_chat_member:flags.26?User new_chat_title:flags.27?string new_chat_photo:flags.28?Vector<PhotoSize> 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;
9-
pyrogram.messageEntity#b0700004 flags:# type:string offset:int length:int url:flags.0?string user:flags.1?User = pyrogram.MessageEntity;
10-
pyrogram.photoSize#b0700005 flags:# file_id:string file_size:flags.0?int date:flags.1?int width:int height:int = pyrogram.PhotoSize;
11-
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;
12-
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;
13-
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;
14-
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;
15-
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;
16-
pyrogram.contact#b0700011 flags:# phone_number:string first_name:string last_name:flags.0?string user_id:flags.1?int = pyrogram.Contact;
17-
pyrogram.location#b0700012 longitude:double latitude:double = pyrogram.Location;
18-
pyrogram.venue#b0700013 flags:# location:Location title:string address:string foursquare_id:flags.0?string = pyrogram.Venue;
19-
pyrogram.userProfilePhotos#b0700014 total_count:int photos:Vector<Vector<PhotoSize>> = pyrogram.UserProfilePhotos;
20-
pyrogram.chatPhoto#b0700015 small_file_id:string big_file_id:string = pyrogram.ChatPhoto;
21-
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;
22-
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;
5+
//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;
6+
//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;
7+
//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;
8+
//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<MessageEntity> caption_entities:flags.12?Vector<MessageEntity> audio:flags.13?Audio document:flags.14?Document game:flags.15?Game photo:flags.16?Vector<PhotoSize> 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<User> left_chat_member:flags.26?User new_chat_title:flags.27?string new_chat_photo:flags.28?Vector<PhotoSize> 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;
9+
//pyrogram.messageEntity#b0700004 flags:# type:string offset:int length:int url:flags.0?string user:flags.1?User = pyrogram.MessageEntity;
10+
//pyrogram.photoSize#b0700005 flags:# file_id:string file_size:flags.0?int date:flags.1?int width:int height:int = pyrogram.PhotoSize;
11+
//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;
12+
//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;
13+
//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;
14+
//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;
15+
//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;
16+
//pyrogram.contact#b0700011 flags:# phone_number:string first_name:string last_name:flags.0?string user_id:flags.1?int = pyrogram.Contact;
17+
//pyrogram.location#b0700012 longitude:double latitude:double = pyrogram.Location;
18+
//pyrogram.venue#b0700013 flags:# location:Location title:string address:string foursquare_id:flags.0?string = pyrogram.Venue;
19+
//pyrogram.userProfilePhotos#b0700014 total_count:int photos:Vector<Vector<PhotoSize>> = pyrogram.UserProfilePhotos;
20+
//pyrogram.chatPhoto#b0700015 small_file_id:string big_file_id:string = pyrogram.ChatPhoto;
21+
//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;
22+
//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;

compiler/api/template/pyrogram.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pyrogram.api.core import Object
44

5+
56
class {class_name}(Object):
67
"""{docstring_args}
78
"""

pyrogram/__init__.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@
2626
__version__ = "0.7.1"
2727

2828
from .api.errors import Error
29-
from .api.types.pyrogram import *
30-
from .client import ChatAction
31-
from .client import Client
32-
from .client import ParseMode
33-
from .client.input_media_photo import InputMediaPhoto
34-
from .client.input_media_video import InputMediaVideo
35-
from .client.input_phone_contact import InputPhoneContact
36-
from .client import Emoji
37-
from .client.handlers import MessageHandler, RawUpdateHandler
38-
from .client.filters import Filters
29+
from .client.types import *
30+
from .client import (
31+
Client, ChatAction, ParseMode, Emoji,
32+
MessageHandler, RawUpdateHandler, Filters
33+
)

pyrogram/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323

2424
for k, v in objects.items():
2525
path, name = v.rsplit(".", 1)
26-
Object.all[k] = getattr(import_module("pyrogram.api." + path), name)
26+
Object.all[k] = getattr(import_module(path), name)

pyrogram/client/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
from .chat_action import ChatAction
2020
from .client import Client
2121
from .emoji import Emoji
22+
from .filters import Filters
23+
from .handlers import MessageHandler, RawUpdateHandler
2224
from .parse_mode import ParseMode

pyrogram/client/client.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@
5151
from pyrogram.session import Auth, Session
5252
from pyrogram.session.internals import MsgId
5353
from . import message_parser
54+
from . import types as pyrogram_types
5455
from . import utils
5556
from .dispatcher import Dispatcher
56-
from .input_media_photo import InputMediaPhoto
57-
from .input_media_video import InputMediaVideo
5857
from .style import Markdown, HTML
5958
from .syncer import Syncer
6059

@@ -2076,7 +2075,7 @@ def send_media_group(self,
20762075
for i in media:
20772076
style = self.html if i.parse_mode.lower() == "html" else self.markdown
20782077

2079-
if isinstance(i, InputMediaPhoto):
2078+
if isinstance(i, pyrogram_types.InputMediaPhoto):
20802079
if os.path.exists(i.media):
20812080
media = self.send(
20822081
functions.messages.UploadMedia(
@@ -2115,7 +2114,7 @@ def send_media_group(self,
21152114
access_hash=unpacked[3]
21162115
)
21172116
)
2118-
elif isinstance(i, InputMediaVideo):
2117+
elif isinstance(i, pyrogram_types.InputMediaVideo):
21192118
if os.path.exists(i.media):
21202119
media = self.send(
21212120
functions.messages.UploadMedia(
@@ -3108,7 +3107,7 @@ def remove_cloud_password(self, password: str):
31083107
return False
31093108

31103109
def download_media(self,
3111-
message: pyrogram.Message,
3110+
message: pyrogram_types.Message,
31123111
file_name: str = "",
31133112
block: bool = True,
31143113
progress: callable = None):
@@ -3147,7 +3146,7 @@ def download_media(self,
31473146
Raises:
31483147
:class:`Error <pyrogram.Error>`
31493148
"""
3150-
if isinstance(message, pyrogram.Message):
3149+
if isinstance(message, pyrogram_types.Message):
31513150
if message.photo:
31523151
media = message.photo[-1]
31533152
elif message.audio:
@@ -3165,17 +3164,17 @@ def download_media(self,
31653164
else:
31663165
return
31673166
elif isinstance(message, (
3168-
pyrogram.PhotoSize,
3169-
pyrogram.Audio,
3170-
pyrogram.Document,
3171-
pyrogram.Video,
3172-
pyrogram.Voice,
3173-
pyrogram.VideoNote,
3174-
pyrogram.Sticker
3167+
pyrogram_types.PhotoSize,
3168+
pyrogram_types.Audio,
3169+
pyrogram_types.Document,
3170+
pyrogram_types.Video,
3171+
pyrogram_types.Voice,
3172+
pyrogram_types.VideoNote,
3173+
pyrogram_types.Sticker
31753174
)):
31763175
media = message
31773176
elif isinstance(message, str):
3178-
media = pyrogram.Document(
3177+
media = pyrogram_types.Document(
31793178
file_id=message,
31803179
file_size=0,
31813180
mime_type=""

pyrogram/client/dispatcher/dispatcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def update_worker(self):
138138

139139
self.dispatch(
140140
pyrogram.Update(
141-
update_id=0,
142141
message=((message if message.chat.type != "channel"
143142
else None) if not is_edited_message
144143
else None),

0 commit comments

Comments
 (0)