Merge branch 'develop' into asyncio
This commit is contained in:
commit
cc7901adf8
@ -172,9 +172,8 @@ def start():
|
||||
|
||||
with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \
|
||||
open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \
|
||||
open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api, \
|
||||
open("{}/source/pyrogram.tl".format(HOME), encoding="utf-8") as pyrogram:
|
||||
schema = (auth.read() + system.read() + api.read() + pyrogram.read()).splitlines()
|
||||
open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api:
|
||||
schema = (auth.read() + system.read() + api.read()).splitlines()
|
||||
|
||||
with open("{}/template/mtproto.txt".format(HOME), encoding="utf-8") as f:
|
||||
mtproto_template = f.read()
|
||||
|
@ -1,22 +0,0 @@
|
||||
// Pyrogram
|
||||
|
||||
---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<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;
|
||||
//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<Vector<PhotoSize>> = 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;
|
@ -3,7 +3,7 @@
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = ~/PycharmProjects/pyrogram/venv3.6/bin/sphinx-build
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXPROJ = Pyrogram
|
||||
SOURCEDIR = source
|
||||
BUILDDIR = build
|
||||
|
@ -1,20 +0,0 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXPROJ = Pyrogram
|
||||
SOURCEDIR = source
|
||||
BUILDDIR = build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
@ -30,7 +30,7 @@ class BoolFalse(Object):
|
||||
return cls.value
|
||||
|
||||
def __new__(cls) -> bytes:
|
||||
return int.to_bytes(cls.ID, 4, "little")
|
||||
return cls.ID.to_bytes(4, "little")
|
||||
|
||||
|
||||
class BoolTrue(BoolFalse):
|
||||
|
@ -48,7 +48,7 @@ class Bytes(Object):
|
||||
else:
|
||||
return (
|
||||
bytes([254])
|
||||
+ int.to_bytes(length, 3, "little")
|
||||
+ length.to_bytes(3, "little")
|
||||
+ value
|
||||
+ bytes(-length % 4)
|
||||
)
|
||||
|
@ -29,15 +29,12 @@ class Int(Object):
|
||||
return int.from_bytes(b.read(cls.SIZE), "little", signed=signed)
|
||||
|
||||
def __new__(cls, value: int, signed: bool = True) -> bytes:
|
||||
return int.to_bytes(value, cls.SIZE, "little", signed=signed)
|
||||
return value.to_bytes(cls.SIZE, "little", signed=signed)
|
||||
|
||||
|
||||
class Long(Int):
|
||||
SIZE = 8
|
||||
|
||||
def __new__(cls, *args):
|
||||
return super().__new__(cls, *args)
|
||||
|
||||
|
||||
class Int128(Int):
|
||||
SIZE = 16
|
||||
|
@ -29,4 +29,4 @@ class Null(Object):
|
||||
return None
|
||||
|
||||
def __new__(cls) -> bytes:
|
||||
return int.to_bytes(cls.ID, 4, "little")
|
||||
return cls.ID.to_bytes(4, "little")
|
||||
|
@ -619,7 +619,7 @@ class Client(Methods, BaseClient):
|
||||
if phone is not None:
|
||||
self.peers_by_phone[phone] = input_peer
|
||||
|
||||
if isinstance(entity, types.Chat):
|
||||
if isinstance(entity, (types.Chat, types.ChatForbidden)):
|
||||
chat_id = entity.id
|
||||
peer_id = -chat_id
|
||||
|
||||
@ -629,7 +629,7 @@ class Client(Methods, BaseClient):
|
||||
|
||||
self.peers_by_id[peer_id] = input_peer
|
||||
|
||||
if isinstance(entity, types.Channel):
|
||||
if isinstance(entity, (types.Channel, types.ChannelForbidden)):
|
||||
channel_id = entity.id
|
||||
peer_id = int("-100" + str(channel_id))
|
||||
|
||||
@ -638,7 +638,7 @@ class Client(Methods, BaseClient):
|
||||
if access_hash is None:
|
||||
continue
|
||||
|
||||
username = entity.username
|
||||
username = getattr(entity, "username", None)
|
||||
|
||||
input_peer = types.InputPeerChannel(
|
||||
channel_id=channel_id,
|
||||
|
@ -206,12 +206,8 @@ class RSA:
|
||||
|
||||
@classmethod
|
||||
def encrypt(cls, data: bytes, fingerprint: int) -> bytes:
|
||||
return int.to_bytes(
|
||||
pow(
|
||||
int.from_bytes(data, "big"),
|
||||
cls.server_public_keys[fingerprint].e,
|
||||
cls.server_public_keys[fingerprint].m
|
||||
),
|
||||
256,
|
||||
"big"
|
||||
)
|
||||
return pow(
|
||||
int.from_bytes(data, "big"),
|
||||
cls.server_public_keys[fingerprint].e,
|
||||
cls.server_public_keys[fingerprint].m
|
||||
).to_bytes(256, "big")
|
||||
|
@ -111,8 +111,8 @@ class Auth:
|
||||
|
||||
data = types.PQInnerData(
|
||||
res_pq.pq,
|
||||
int.to_bytes(p, 4, "big"),
|
||||
int.to_bytes(q, 4, "big"),
|
||||
p.to_bytes(4, "big"),
|
||||
q.to_bytes(4, "big"),
|
||||
nonce,
|
||||
server_nonce,
|
||||
new_nonce,
|
||||
@ -131,8 +131,8 @@ class Auth:
|
||||
functions.ReqDHParams(
|
||||
nonce,
|
||||
server_nonce,
|
||||
int.to_bytes(p, 4, "big"),
|
||||
int.to_bytes(q, 4, "big"),
|
||||
p.to_bytes(4, "big"),
|
||||
q.to_bytes(4, "big"),
|
||||
public_key_fingerprint,
|
||||
encrypted_data
|
||||
)
|
||||
@ -140,8 +140,8 @@ class Auth:
|
||||
|
||||
encrypted_answer = server_dh_params.encrypted_answer
|
||||
|
||||
server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True)
|
||||
new_nonce = int.to_bytes(new_nonce, 32, "little", signed=True)
|
||||
server_nonce = server_nonce.to_bytes(16, "little", signed=True)
|
||||
new_nonce = new_nonce.to_bytes(32, "little", signed=True)
|
||||
|
||||
tmp_aes_key = (
|
||||
sha1(new_nonce + server_nonce).digest()
|
||||
@ -170,7 +170,7 @@ class Auth:
|
||||
# Step 6
|
||||
g = server_dh_inner_data.g
|
||||
b = int.from_bytes(urandom(256), "big")
|
||||
g_b = int.to_bytes(pow(g, b, dh_prime), 256, "big")
|
||||
g_b = pow(g, b, dh_prime).to_bytes(256, "big")
|
||||
|
||||
retry_id = 0
|
||||
|
||||
@ -199,8 +199,8 @@ class Auth:
|
||||
|
||||
# Step 7; Step 8
|
||||
g_a = int.from_bytes(server_dh_inner_data.g_a, "big")
|
||||
auth_key = int.to_bytes(pow(g_a, b, dh_prime), 256, "big")
|
||||
server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True)
|
||||
auth_key = pow(g_a, b, dh_prime).to_bytes(256, "big")
|
||||
server_nonce = server_nonce.to_bytes(16, "little", signed=True)
|
||||
|
||||
# TODO: Handle errors
|
||||
|
||||
@ -235,7 +235,7 @@ class Auth:
|
||||
# 3rd message
|
||||
assert nonce == set_client_dh_params_answer.nonce
|
||||
assert server_nonce == set_client_dh_params_answer.server_nonce
|
||||
server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True)
|
||||
server_nonce = server_nonce.to_bytes(16, "little", signed=True)
|
||||
log.debug("Nonce fields check: OK")
|
||||
|
||||
# Step 9
|
||||
|
Loading…
Reference in New Issue
Block a user